Moving a live system from one hard disk to another
Ever found yourself in the situation where you want to move your GNU/Linux from an old hard disk to a new one? Well, it can be done quite easily :-)
First, set up new partitions with parted then mkswap, mkfs (using proper labels). Yes, I assume you’re familiar with these (RTFM).
Mount the new root partition somewhere, like /mnt/tmp in this article.
Create in this new partition all the directories that it would not make sense to copy from the original system (in my case: home being on another partition, stockage containing only NFS mounts):
cd /mnt/tmp mkdir dev home proc stockage sys tmp mnt
Shut down any daemon/service that is up (cron, etc), to avoid copying stuff in an incoherent state.
Then, actually copy the system:
for dir in /*; do if [ ! -e /mnt/tmp/$dir ]; then cp -ax $dir /mnt/tmp/; fi ; done
Edit /mnt/tmp/etc/fstab to use the newly created partitions.
Chroot in the new system to make it bootable with grub:
mount --bind /dev /mnt/tmp/dev mount --bind /sys /mnt/tmp/sys mount proc -t proc /mnt/tmp/proc chroot /mnt/tmp grub-mkdevicemap update-grub # (you can run blkid to check the root's unique id of this # new system shows up in the new system /boot/grub/grub.cfg) grub-install /dev/XX # where XX is the new disk, like /dev/sdc or whatever
Reboot on the new system (stating the obvious: change boot drive order in the BIOS). If everything is fine, then copy /home from the old disk to the new partition, without login in with any system (CTRL-ALT-F2 to quite X server and log in as root, for example).
After removing the old device, re-run update-grub so it’ll no longer show up. The end.
Update: Please take a look also at the following backup script that clone a live system to a secondary hard drive.