Many linux users install the root filesystem on a standard partition. If this is
the case with you, it may be possible to copy the root filesystem onto an LVM
Logical-Volume by hand, and to modify the boot loader configuration file (eg:
/boot/grub.conf
for Grub) so that it now boots from the LVM volume. This
procedure has been tested with Debian Lenny, and it’s likely to work for other
distributions.
You will need enough space on your disk to have both the old root partition and the new LVM volume at the same time. If you don’t have enough space, it’s also possible to backup and restore your root filesystem instead of doing a copy. It should work if you know what you are doing. This is a dangerous operation, so please check that you have a recent backup first and don’t do this if you don’t fully understand this procedure. It is recommended that you read the previous pages about LVM before reading this one.
Before you migrate your root filesystem to an LVM volume, you should check that
the initramfs provided by your distribution supports LVM. On some distributions,
the initramfs is configuration specific. For instance, on Fedora/Redhat, the
initramfs is created automatically by a program called mkinitrd
each time
you install or update the kernel image. The problem is that this program only
includes the disk drivers for the hardware on which it runs, and it only includes
the LVM programs if you are using it. In that case you will have problems if you
try to reuse this linux kernel image and this initramfs on hardware which needs
different disk drivers and if you use LVM. The solution is to recreate the
initramfs with LVM support before you reboot the new root filesystem.
With Other distributions such as Debian-Lenny, the initramfs includes all the disk drivers and it always includes the LVM programs so it should work. In that case you can just reuse the linux -kernel-image and the initramfs as they have already been installed in /boot.
As of version 09.10 the default installer in Ubuntu does not support LVM. You have to install Ubuntu on a normal partition first, run commands on this system either by booting on it or through chroot, install the lvm2 tools, update the initramfs and then copy the filesystem to an LVM volume:
/dev/sda1
)apt-get install lvm2
update-initramfs -u -k all
Then the initramfs will have LVM support and it will work when you try to use it to boot Ubuntu from an LVM Logical-Volume.
/dev/vgmain
/dev/mapper/vgmain-debian
mke2fs -j -L debian /dev/mapper/vgmain-debian
mkdir -p /oldrootfs /newrootfs
mount -r /dev/sda2 /oldrootfs
mount /dev/mapper/vgmain-debian /newrootfs
rsync -axHAX /oldrootfs/ /newrootfs/
/newrootfs/etc/fstab
and change the entry related to
the root filesystem so that the name of the device and the filesystem are
correct.cd / ; umount /oldrootfs /newrootfs
Now you have to mount your boot partition and edit the boot loader configuration
so that it will know from where to boot. It’s recommended to preserve the
existing boot entry, just in case there is a problem with the new root
filesystem. Here is an example of a grub configuration file for Debian with
these two entries. The important thing is the the root=xxx
boot parameter.
default 0
timeout 10
title Debian-Linux-2.6.26-2-amd64 [new-lvm-rootfs]
root (hd0,0)
kernel /vmlinuz-2.6.26-2-amd64 root=/dev/mapper/vgmain-debian ro
initrd /initrd.img-2.6.26-2-amd64
title Debian-Linux-2.6.26-2-amd64 [old-std-rootfs]
root (hd0,0)
kernel /vmlinuz-2.6.26-2-amd64 root=/dev/sda2 ro
initrd /initrd.img-2.6.26-2-amd64
Now you should be able to reboot on the new root filesystem.