Partitions at the beginning and end of drive and migration to smaller SSD

0

I need to migrate one 256GB HDD to 240GB SSD, but EFI partition is at the very end of my HDD.

I already did backup:

sudo dd if=/dev/sda of=backup.img

but I can't put this image to my SSD drive, because this image is 256GB.

Disk has 165GB of data and 68GB of empty space and 20MB of EFI partition at the end (sorry for polish labels in that windows app), so can I use dd or any other Linux tool to say something like:

sudo dd if=/dev/sda of=/dev/sdb SKIP_SECTORS_FROM_166GB_TO_186GB

Can I use any Linux tool (parted?) to move EFI partition 20GB to the left and use dd to copy first 236GB of data to SSD drive?

(I have CloneZilla Live USB.)

marcinpl87

Posted 2018-01-18T23:31:03.317

Reputation: 1

You know you can simply recreate the EFI partition. You just need WinRE – Ramhound – 2018-01-19T01:22:18.573

Answers

0

Sure, you can use gparted to move the partition to the left on the original drive then clone it, if you have the space. You can also use dd to carefully skip a range by running it twice: once with a count=x argument to get the first part, then a second time with a skip=y and seek=x argument to take everything after y in the source and copy it to the destination starting at x. The units default to sectors unless you specify bs=. You will also need to edit the partition table to reflect the relocated position of the ESP.

psusi

Posted 2018-01-18T23:31:03.317

Reputation: 7 195

0

Thank you for answers!

I tried to move partition with parted and gparted, but both doesn't move EFI partitions. So this is what did I do:

  1. I copied files from /dev/sda3 (D:) to /dev/sda1 (C:) and I removed /dev/sda3 (D:) partition.
  2. I had only 3 primary partitions so I created new primary partition at the beginning of empty sectors [I only checked in gparted length (in sectors) of my EFI partition to create new FAT32 partition with the same length]
  3. I copied in DD all sectors from EFI partition to new partition
  4. I used parted to remove old EFI partition
  5. I had all partitions in first 116GB of HDD so I copied only these 116GB to SSD in DD command:

    `sudo dd if=/dev/sda of=/dev/sdb bs=512KB count=237568 status=progress`
    

I connected SSD drive to SATA port in my laptop and windows boot perfectly fine.

This is how my SDD looks like

marcinpl87

Posted 2018-01-18T23:31:03.317

Reputation: 1