Copy Linux to a new Harddisk

In the following howto i assume that sda is your source drive and sdb is your target drive.. please make sure not to mix this up in your setup! also i assume that your operating system disk has three partitions, sda1 as /boot, sda2 as swap and sda3 as /

  • stop any running services like apache, mysql etc. on the source system. or even better, boot from a live linux and work from there..
  • partition and format the new harddisk
    • parted /dev/sda –> print shows the current partitions of sda including their sizes.. that should help :)
  • create mountpoints for source and target
    mkdir /tmp/source
    mkdir /tmp/target
  • mount source and targed partitions:
    mount /dev/sda3 /tmp/source
    mount /dev/sda1 /tmp/source/boot
    mount /dev/sdb3 /tmp/target
    mkdir /tmp/target/boot
    mount /dev/sdb1 /tmp/target/boot
  • now copy the os:
    rsync -aHvx --numeric-ids /tmp/source /tmp/target
  • edit /tmp/target/etc/fstab and /tmp/target/boot/grub/menu.lst and update UUID according to harddisks_by_uuid_in_debian_lenny
  • chroot to the target drive and install grub:
    mount --bind /dev/ /tmp/target/dev
    mount --bind /sys/ /tmp/target/sys
    mount --bind /proc/ /tmp/target/proc
    chroot /tmp/target
    grub-install /dev/sdb
    find /boot/grub/menulst

    (if you have an own partiton for boot, you can leave boot away in the above command)

    root (hd0,0)
    setup (hd0)
  • if you are moving your installation to new hardware (other than just the harddisk) you might need to update your initrd image to contain the necessary drivers (i.e. in redhat based systems). run dracut
  • reboot your system
  • copy_linux_to_a_new_harddisk.txt
  • Last modified: 06.06.2014 10:54
  • by Pascal Suter