Wednesday, April 18, 2007

Ubuntu root on LVM from the standard Live CD

These are the notes I made whilst installing Feisty Fawn from the standard Live CD, such that the root filesystem lands on LVM.

This guide does make the assumption that you know your way around Linux and is based on a rather simplified setup (for the sake of clarity) that you will probably want to amend for your specific needs.

The instructions ought to work with little or no amendment for any recent flavour of Ubuntu including Edgy Eft and Dapper Drake. If you have problems following this guide then Google is your friend!

Boot from the CD into the live desktop.

Configure networking so that we can use aptitude to obtain the necessary LVM packages.

sudo aptitude update
sudo aptitude install lvm2
modprobe dm-mod

cfdisk /dev/hda  # or /dev/hdb, /dev/sda, /dev/cciss/c0d0, etc., throughout...

Write the partitions to disk something like the following:

hda1 ; Boot ; Primary ; Linux ext2 ; 200Mb # at beginning of drive for /boot
hda2 ; ; Primary ; Linux swap ; 2048Mb # at end of drive
hda3 ; ; Primary ; Linux LVM ; 120000Mb # in remaining space for root LV and other LVs

pvcreate /dev/hda3 # This may fail, see below for fix

At the time of writing there existed a bug in the packaged version of LVM that can be fixed with: ln -s /lib/lvm-200 /lib/lvm-0

vgcreate vg00 /dev/hda3
lvcreate -n root -L 10G vg00 # If this fails make sure that you have performed modprobe dm-mod

It is necessary to create filesystems on the devices in order for the ubiquity installer to correctly identify them as possible install targets.

mkfs.ext2 /dev/hda1
mkfs.ext3 /dev/mapper/vg00-root
mkswap /dev/hda2

Proceed through the installation as normal, except choose to manually prepare the disks as follows:

/dev/hda1: use as: ext2 ; mount point: /boot ; format: yes
/dev/hda2: use as: swap
/dev/mapper/vg00-root: use as: ext3 ; mount point: / ; format: yes

Allow the install to complete and click "Continue using the live CD".

mount /dev/mapper/vg00-root /target
mount /dev/hda1 /target/boot
mount -t proc proc /target/proc
mount -t sysfs sysfs /target/sys
chroot /target

aptitude update
aptitude install lvm2
ln -s /lib/lvm-200 /lib/lvm-0

vgchange -ay # Tests that LVM works from within the target system

Add the following modules to both /etc/modules and /etc/initramfs-tools/modules:

dm-mod
dm-snapshot
dm-mirror

update-initramfs -u

Exit the chroot by pressing ctrl-d.

umount /target/proc /target/sys /target/boot /target

Reboot into your new "root on LVM" Ubuntu system.