Root on LVM
From RockWiki
The following explains how to use the Logical Volume Manager (LVM) to great extent. Following these instructions enables you to keep as much of your harddisk in a lvm as possible. It mainly consists of a small bootstrapping system outside the LVM, which after loading the kernel and activating the volume group mounts your root. After this it changes the userspace and kernelspace root to this root directory (chroot, pivot-root).
Please note that creating the LVM itself is not discussed here. If you want to be introduced to the concepts and usage of LVM, please refer to the excellent LVM-HOWTO.
Contents |
Before you begin
Partition Layout
The partition layout in the example will be the following:
- Partition 1: 100 MB ext2 - will contain the pre-system and marked bootable.
- Partition 2: rest of the disk, LVM Physical volume.
In the LVM, Only two logical volumes are defined for the example. You can define them as you like, just adopt the procedures we run through later on.
The LVM Physical volume will be partitioned like this:
- Partition 1: swap, type swap, size 512M
- Partition 2: root, type ext3, size (what remained free)
Kernel Requirements
The kernel you use must have builtin support for LVM, device-mapper and the filesystems you use.
Installation
First you should boot into your system using the ROCK Linux cd set you want to install. Create the partitions similar to the example above. It is important to keep a partition outside the lvm for the bootstrapping system. This special partition is also not mounted during the installation process. On your target root, create the directories /mnt/boot and /mnt/oldroot, these are used to move the pre-system to this backup position. (During the ROCKLinux Installation procedure your target root is usually mounted as /mnt/target.)
Booting the ROCK Linux installation system
Please refer to chapter Installation using CD for this. Stop at the point where stone should be run. If stone is started automatically, exit it. The next steps are not yet automated. We will start it again later on.
Partitioning the harddisk
Start a partition manager (fdisk, cfdisk) and create two partitions on your harddisk as described above.
Creating the LVM volumes
Important: Do not just copy and paste the following instructions to your system. They can be correct for your setup, but are likely to vary.
root@stage2:~@ pvcreate /dev/hda2 # create a physical volume root@stage2:~@ vgcreate rockvg /dev/hda2 # create a volume group root@stage2:~@ vgchange -a y rockvg # activate the volume group root@stage2:~@ lvcreate -L512M -nswap rockvg # create logical volume for swap root@stage2:~@ lvcreate -l $(vgdisplay rockvg | grep "Total PE" | awk '{print $3}') -nroot rockvg # fill the rest with another lv named root root@stage2:~@ mkswap /dev/rockvg/swap # initialize swap space root@stage2:~@ swapon /dev/rockvg/swap # activate the swap space root@stage2:~@ mkfs.ext3 /dev/rockvg/root # create filesystem on root lv root@stage2:~@ mount /dev/rockvg/root /mnt/target # mount the root lv to the target directory root@stage2:~@ stone # run stone to continue installation
Installation of ROCK Linux
Install the system using the standard ROCKLinux installation tools as explained in Installation using CD. At the end - before you reboot, read on.
Pre-Boot system setup
For the next steps, you'll need a ROCK Linux rescue CD. It already contains all the neccessary tools we need to boot into the system in the LVM.
Prepare the boot disk
Create an empty directory where the pre-boot disk will be mounted. Create a filesystem on that disk if not already done and mount it to that directory. In our example, we will now create an ext2 filesystem and mount it to /mnt/new_boot.
root@stage2:~@ mkfs.ext2 /dev/discs/disc0/part1 root@stage2:~@ mkdir /mnt/new_boot root@stage2:~@ mount /dev/discs/disc0/part1 /mnt/new_boot
Next task is to prepare the directory structure and copy some things as the kernel, initrd, the pre-system and grub.
root@stage2:~@ cp -a /boot/grub /mnt/new_boot root@stage2:~@ cp /mnt/boot/isolinux/krescue /mnt/new_boot/vmlinuz-rescue root@stage2:~@ cp /mnt/boot/isolinux/rdrescue.gz /mnt/new_boot/initrd-rescue.img root@stage2:~@ mkdir /mnt/new_boot/rescue root@stage2:~@ cp /mnt/boot/rescue/system.tb2 /mnt/new_boot/rescue/system.tar.bz2
Configure GRUB
What we need now is a configuration for the bootloader GRUB. You can use another bootloader if you like, but then please report your success story to the ROCK Linux developers, they'll be happy :) A sample entry for grub's menu.lst is the following, which depends on the configuration described above. You probably have to alter the volume group and logical volume names.
title ROCK Linux productive LVM boot cycle kernel (hd0,0)/vmlinuz-rescue root=/dev/ram0 \ overlay_failure=ignore boot=ext2:/dev/discs/disc0/part1 \ stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg/root panic=10 initrd (hd0,0)/initrd-rescue.img
Now you have to install grub into the MBR of your special partition.
echo "install (hd0,0)/grub/stage1 (hd0,0) (hd0,0)/grub/stage2 (hd0,0)/grub/menu.lst" | grub
If everything up to here went fine, you can now try a reboot.