Migrating a Linux (Debian Squeeze) system from one HD to another HD

Migrating a Linux (Debian Squeeze) system from one HD to another HD

Yedidyah Bar-David linux-il at didi.bardavid.org
Sun Feb 19 12:24:03 IST 2012


On Sun, Feb 19, 2012 at 04:03:05AM +0200, Omer Zak wrote:
> My PC has a 500GB hard disk, and I want to migrate it to a 2TB hard
> disk.
> The new hard disk has been formatted to have two physical partitions,
> one serves as /boot and the other is an encrypted LVM volume, which has
> its own division into logical partitions.
> 
> I rsync'ed the old hard disk's contents into the new one (excluding
> - /lib/init/rw/***
> - /dev/shm/***
> - /proc
> - /sys
> - /tmp/***
> - /var/lock/***
> - /var/tmp/***
> - /cdrom/***
> - /media/***
> - /etc/fstab
> ).
> 
> I edited /etc/fstab in the new hard disk to specify the correct
> partitions.
> 
> Then I ran grub-install on the new hard disk using:
>   chroot /tmp/new_2T grub-install /dev/sdb
> where the new hard disk's /boot and logical partitions are mounted on
> subdirectories of /tmp/new_2T, and the new hard disk itself is /dev/sdb.
> 
> However the logical volume paths in the old hard disk and the new one
> differ.
> It turns out that the kernel and initrd images in the old hard disk have
> the old logical volume paths hardwired in them.

Are you certain about that? I do not have cryptfs (and the cryptroot
script below) installed, but I think very little is hardwired into
Debian's mkinitramfs-generated initrd images.

> So when trying to reboot the PC from the new hard disk, it doesn't find
> the root filesystem.  The failing script is /scripts/local-top/cryptroot
> (/scripts/local-top template can be found in /etc/initramfs).

Can you try passing (adding or changing) "root=THENEWROOT" from your
bootloader?

If that works, you'll need to change your boot loader's configuration.
In a default squeeze install, that's in /etc/default/grub and
/etc/grub.d . Then run 'update-grub'.

> 
> So it seems that I need somehow to recreate the initrd.img's contents.
> 
> I may have missed also other things.
> 
> Questions:
> 1. How to recreate initrd.img's appropriate for the new hard disk?

Not sure how to do this from the old disk, but once you manage to boot
to the new disk (e.g. using some rescue CD or whatever), you should be
able to use mkinitramfs without special options - hopefully it will
detect the changes etc by itself.

Note that I have no experience with cryptfs and related stuff.

> 2. Is there any guide about migrating a Debian Squeeze system inside an
> encrypted LVM partition from one hard disk to another hard disk?

No idea.

> 
> In conclusion: I am dismayed at the fact that migrating Linux systems,
> which used to be a simple affair (like MS-DOS), is now complicated (like
> versions of MS-Windows after Windows 95).

That's not a fair comparison - you decided to do some non-trivial changes
to your disk layout, and that's not mere "migrating". That said, I agree
that in the process of making the boot process more robust, distributions
(Debian included) made it also more complex. One thing I noticed, which
might or might not be relevant here, is that in certain cases the boot
loader identifies filesystems with their UUID, which is not copied by
most people when copying a disk. So now if something changes your
/dev/sda2 to /dev/hda2 or vice versa, you'll still boot, unlike in the
past, but copying root elsewhere will also require updating the boot
loader unless you made sure you also copied the UUID.
-- 
Didi




More information about the Linux-il mailing list