Converting a root filesystem to LVM
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.
Upgrade Complications | |
---|---|
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. |
Recovery Complications | |
---|---|
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 |
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:
13.8.1. Boot single user
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.
13.8.2. Run Parted
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 |
Now resize the partition:
(parted) resize 3 145 999 |
Create a new partition
(parted) mkpart primary ext2 1000 1999 |
Quit parted
(parted) q |
13.8.4. Verify kernel config options
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.
13.8.5. Adjust partition type
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 |
13.8.6. Set up LVM 1 for the new scheme
Initialize LVM 1 (vgscan)
# 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
13.8.7. Create the Filesystem
Make a filesystem in the logical volume and copy the root files onto it.
# mke2fs /dev/vg/root |
13.8.8. Update /etc/fstab
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 |
13.8.9. Create an LVM 1 initial RAM disk
# lvmcreate_initrd |
Make sure you note the name that lvmcreate_initrd calls the initrd image. It should be in /boot.
13.8.10. Update /etc/lilo.conf
Add an entry in /etc/lilo.conf for LVM 1. This should look similar to the following:
image = /boot/KERNEL_IMAGE_NAME |
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/ |
13.8.12. Reboot to lvm
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
default=lvm |
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.
13.8.13. Add remainder of disk
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 |
# pvcreate /dev/hda3
# vgextend vg /dev/hda3
No comments:
Post a Comment