Michael Cordell's Blog

Cloning a larger linux OS hard drive to a smaller one

06 Jul 2013

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:

  1. Linux live CD (anything with Gparted on it should do it)
  2. Clonezilla

Process

  1. Attach the source drive (the one you will be migrating from) and the destination drive.
  2. Boot the live CD and open Gparted
  3. 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.
  4. 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.
  5. 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.
  6. Reboot into the Live CD to repair the the grub on the new drive.
  7. 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

The new drive should be functional.

comments powered by Disqus