|Backup Your System|
It is strongly recommended that you take a full backup of your system before attempting to convert to root on LVM 1.
Having your root filesystem on LVM 1 can significantly complicate upgrade procedures (depending on your distribution) so it should not be attempted lightly. Particularly, you must consider how you will insure that the LVM 1 kernel module (if you do not have LVM 1 compiled into the kernel) as well as the vgscan/vgchange tools are available before, during, and after the upgrade.
Having your root filesystem on LVM 1 can significantly complicate recovery of damaged filesystems. If you lose your initrd, it will be very difficult to boot your system. You will need to have a recover disk that contains the kernel, LVM 1 module, and LVM 1 tools, as well as any tools necessary to recover a damaged filesystem. Be sure to make regular backups and have an up-to-date alternative boot method that allows for recovery of LVM 1.
In this example the whole system was installed in a single root partition with the exception of /boot. The system had a 2 gig disk partitioned as:
/dev/hda1 /boot /dev/hda2 swap /dev/hda3 /
The / partition covered all of the disk not used by /boot and swap. An important prerequisite of this procedure is that the root partition is less that half full (so that a copy of it can be created in a logical volume). If this is not the case then a second disk drive should be used. The procedure in that case is similar but there is no need to shrink the existing root partition and /dev/hda4 should be replaced with (eg) /dev/hdb1 in the examples.
To do this it is easiest to use GNU parted. This software allows you to grow and shrink partitions that contain filesystems. It is possible to use resize2fs and fdisk to do this but GNU parted makes it much less prone to error. It may be included in your distribution, if not you can download it from ftp://ftp.gnu.org/pub/gnu/parted.
Once you have parted on your system AND YOU HAVE BACKED THE SYSTEM UP:
Boot into single user mode (type linux S at the LILO prompt) This is important. Booting single-user ensures that the root filesystem is mounted read-only and no programs are accessing the disk.
Run parted to shrink the root partition Do this so there is room on the disk for a complete copy of it in a logical volume. In this example a 1.8 gig partition is shrunk to 1 gigabyte This displays the sizes and names of the partitions on the disk
# parted /dev/hda (parted) p . . .
Now resize the partition:
(parted) resize 3 145 999
Create a new partition
(parted) mkpart primary ext2 1000 1999
Make sure that the kernel you are currently running works with LVM 1 and has CONFIG_BLK_DEV_RAM and CONFIG_BLK_DEV_INITRD set in the config file.
Change the partition type on the newly created partition from Linux to LVM (8e). Parted doesn't understand LVM 1 partitions so this has to be done using fdisk.
# fdisk /dev/hda Command (m for help): t Partition number (1-4): 4 Hex code (type L to list codes): 8e Changed system type of partition 4 to 8e (Unknown) Command (m for help): w
Initialize LVM 1 (vgscan)
Make the new partition into a PV
# pvcreate /dev/hda4
create a new volume group
# vgcreate vg /dev/hda4
Create a logical volume to hold the new root.
# lvcreate -L250M -n root vg
Make a filesystem in the logical volume and copy the root files onto it.
# mke2fs /dev/vg/root # mount /dev/vg/root /mnt/ # find / -xdev | cpio -pvmd /mnt
Edit /mnt/etc/fstab on the new root so that / is mounted on /dev/vg/root. For example:
/dev/hda3 / ext2 defaults 1 1
/dev/vg/root / ext2 defaults 1 1
Make sure you note the name that lvmcreate_initrd calls the initrd image. It should be in /boot.
Add an entry in /etc/lilo.conf for LVM 1. This should look similar to the following:
image = /boot/KERNEL_IMAGE_NAME label = lvm root = /dev/vg/root initrd = /boot/INITRD_IMAGE_NAME ramdisk = 8192
lvmcreate_initrd -- making loopback file (6189 kB)
You should copy this new lilo.conf onto /etc in the new root fs as well.
# cp /etc/lilo.conf /mnt/etc/
Reboot - at the LILO prompt type "lvm" The system should reboot into Linux using the newly created Logical Volume.
If that worked then you should make lvm the default LILO boot destination by adding the line
If it did not work then reboot normally and try to diagnose the problem. It could be a typing error in lilo.conf or LVM 1 not being available in the initial RAM disk or its kernel. Examine the message produced at boot time carefully.
Add the rest of the disk into LVM 1. When you are happy with this setup you can then add the old root partition to LVM 1 and spread out over the disk.
First set the partition type to 8e(LVM)
# fdisk /dev/hda Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Unknown) Command (m for help): w
Convert it into a PV and add it to the volume group:
# pvcreate /dev/hda3 # vgextend vg /dev/hda3
Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:58:12