How to clone a disk to a different size in Linux

We have Linux-Fedora 22,
HDD-on which the system is installed, you need to move to an SDD that is half the size, but there is not enough data on the HDD, so they will fit.
Both disks are connected to the computer.
Q: How do I clone a disk? Preferably using GNU Linux.

Callouts:
1. CD/DVD-no.
2. gparted-does not work with the active system partition.
3. Where should the tar archive be placed? in /dev/null ? two disks in total.
4. Disks of various sizes size!

Author: PashaPash, 2015-10-06

2 answers

Everything can be done, the main thing is neat. You need the following things:

  • livecd disk or better flash drive. You can use another compatible distribution, for example ubuntu.
  • both disks must be connected to the computer.

The transfer procedure.

  • will boot from live
  • open gparted or any other favorite disk partitioning utility.
  • split the ssd as needed (home, root, swap, and so on according to your preferences), format
  • mounting new ones disks and old ones. I recommend making the / mount folder old (for the old disk) and new (for the new one).
  • copy the data. Since this is Linux, you can use cp, the main thing is to save the rights. For example, home cp -a /mount/old/home/ /mount/new/home.
  • the root is copied in the same way. But there is a special feature-not everything needs to be copied. for example, the tmp folder is not needed (although nothing bad will happen). If there is something inside the /mount/old/proc and /mount/old/sys folders, you do not need to copy it (the system creates the contents of these folders herself).
  • don't forget about the boot partition.
  • if the device names have changed (for example, home was /dev/sda*1*, and became /dev/sdb*4* - the number is important here, not the letter), then open the file /mount/new/etc/fstab and edit it by default.
  • the last thing left is to move the boot record. First, we copy the old dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1, and then transfer it to the new one. Since we don't want to rub the partition table, we don't need to copy everything. dd if=/path/to/mbr_file.img of=/dev/sdX bs=446 count=1.

Everything, you can turn off, put the disks in their places, fix them in the bios boot device and try.

What should I do if nothing is started?

The old disk is probably not damaged. So that they can be loaded. Plus there is a flash drive. You can restore it.

But to be honest, I endured a little differently. Everything is as above, I broke the disk, copied the home partition, then pulled out the old disk, and booted from the flash drive. And started the installation as usual. During the installation process, the main thing is not to format the home partition (although you can still do it later copy). Since there is a home section, all program settings will be saved. Then you may only need to install the missing programs.

 6
Author: KoVadim, 2015-10-06 07:20:50

I highly recommend taking a closer look at the Clonezilla project. It can copy both Linux and Windows partitions. It loads from a flash drive, dummy, network, can work in server mode and distribute the image via multicast. It runs in the wizard mode, and the vast majority of dialogs are translated into Russian.

Yes, the same gparted live may need to shrink the partitions to the size that fits on the ssd, but the other dd and cp -r are not needed there. There is a copy mode from piece of iron to piece of iron, you can first enter the image, and then out of the image.

 2
Author: don Rumata, 2015-10-06 21:37:21