Cloning a larger linux OS hard drive to a smaller one
I needed to upgrade my linux server’s hard drive from a traditional HDD to a SSD. Unfortunately the old hard drive was 80 GB and the new one is 64 GB. There are commercial programs for this purpose but I figured I could do it with freeware. To that end, you will need:
- Linux live CD (anything with Gparted on it should do it)
- Clonezilla
Process
- Attach the source drive (the one you will be migrating from) and the destination drive.
- Boot the live CD and open Gparted
- Set up the partitions on the new drive. For this I just set up a similar sized swap and extended space. Then I filled the rest of the drive with and ext4.
- Now reduce the size of the ext4 partition on the source drive to match the same size as the ext4 on the destination drive. Obviously you will have to reduce the data size on the source drive if it is more than the destination partition can hold. You can mount the drive in the live CD, no need to reboot to clean it up.
- Reboot into clonezilla, select “Start clonezilla”, “device-device”, “local dev”, select the source partition, select the destination partition. You will then hit through a bunch of confirmations and the partitions will be copied.
- Reboot into the Live CD to repair the the grub on the new drive.
- Do the following where /dev/sdd is the new drive, and sdd1 is the ext4 partition.
sudo mount /dev/sdd1 /mnt && sudo mount -o bind /dev /mnt/dev && sudo mount -o /dev/pts /mnt/dev/pts && sudo mount -o bind /proc /mnt/proc && sudo mount -o bind /sys /mnt/sys
sudo chroot /mnt bash
grub-install /dev/sdd
exit
sudo poweroff