20 Feb 2012 yeupou   » (Master)

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
# (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.

Syndicated 2012-02-20 15:35:24 from # cd /scratch

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!