How to migrate to a larger hard disk in Linux

Last updated 23 February 2010

There are a few guides out there on how to migrate from one disk to another with Linux, but most are out-of-date or incomplete - they don't include details on grub, or they don't mention /etc/fstab or the kernel boot options.

This is the complete list of steps you need to follow in order to migrate from one hard disk to another with a single reboot and no messing with the console or boot loader. I've made the following assumptions:

So here's what you need to do (all commands run as the root user, of course):

  1. Create a partition on /dev/sdb: fdisk /dev/sdb and follow the instructions (probably as simple as n p 1 return return w)
  2. Format the partition on /dev/sdb1: mkfs -t ext3 /dev/sdb1
  3. Run tune2fs -l /dev/sdb1 and note down the "Filesystem UUID" - for reference mine is 3222fc62-295e-4665-a3dc-e4960a337316
  4. mount /dev/sdb1 /mnt
  5. cd / && find . -xdev -print0 | cpio -pa0V /mnt
  6. mount --bind /dev /mnt/dev
  7. chroot /mnt
  8. Edit /etc/fstab and find the device for the mountpoint "/". If the device begins with UUID=xxx change it to the new UUID. If the device is LABEL=nnn change it to use the UUID. If the device is /dev/sda1 then there's no need to change it. For reference the line in my setup is
    UUID=3222fc62-295e-4665-a3dc-e4960a337316  / ext3 relatime,errors=remount-ro 0 1
  9. Edit /boot/grub/menu.1st and change the UUID in the same way on the kernel line for each boot option. If the "root" option to the kernel reads root=/dev/sda1 there's no need to change it. For reference the line in my setup is
    kernel /boot/vmlinuz-2.6.24-26-virtual root=UUID=3222fc62-295e-4665-a3dc-e4960a337316 quiet
  10. Run /usr/sbin/grub-install --recheck /dev/sdb
  11. Shutdown. Remove the old hard drive, move the new hard drive so it shows up in the same position in the BIOS.
  12. Reboot as normal.

mike at bfo dot co dot uk, 23 Feb 2010