Last updated 23 November 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:
/dev/sda
and the new disk is currently blank and on /dev/sdb
. Adjust the lines below to match your setupSo here's what you need to do (all commands run as the root user, of course):
fdisk /dev/sdb
and follow the instructions (probably as simple as n p 1 return return w)
mkfs -t ext3 /dev/sdb1
tune2fs -l /dev/sdb1
and note down the "Filesystem UUID" - for reference mine is 3222fc62-295e-4665-a3dc-e4960a337316
mount /dev/sdb1 /mnt
cd / && find . -xdev -print0 | cpio -pa0V /mnt
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
chroot /mnt
/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
The next steps depend on whether you're running GRUB legacy or GRUB2. For GRUB legacy:
/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
/usr/sbin/grub-install --recheck /dev/sdb
For GRUB2
update-grub
(this is on Ubuntu 9.04 or later - for other systems you might need to run grub-mkconfig -o /boot/grub/grub.cfg
).mike at bfo dot co dot uk, 23 Nov 2010