Root on LVM on RAID 1

Again I want to refer to George Kraolides' Root-on-LVM-on-RAID HOWTO.

The kernel supports LVM and with the lvm10 Debian package I have the needed tools to work on the LVM setup.

pvscan does not show any physical volumes yet
pvcreate /dev/md/1
pvscan now shows the new physical volume. Essentially, this writes the signature on the RAID array /dev/md/1 so that kernel knows how to deal with it. It doesn't belong to any volume group yet.

create the volume group
vgcreate vg1 /dev/md/1
A volume group can consist of more than one physical volume. In this case we just have our RAID array /dev/md/1 which has just been initialized as a physical volume above as the only component. The name of the volume group is vg1 and with devfs the kernel creates a directory /dev/vg1 to contain the volumes. There are now volumes in it now (only group for the whole group). We need to create them first.

lvcreate -L 10G -n root vg1
lvcreate -L 3G -n home vg1
lvcreate -L 5G -n local vg1
lvcreate -L 1G -n opt vg1
lvcreate -L 30G -n audio vg1
lvcreate -L 1G -n swap vg1
Now these volumes appear as devices in /dev/vg1. They are still unformatted. Let's format them as follows (-j is for ext3):
mke2fs -j /dev/vg1/root
mke2fs -j /dev/vg1/home
mke2fs -j /dev/vg1/local
mke2fs -j /dev/vg1/opt
mke2fs -j /dev/vg1/audio
mkswap /dev/vg1/swap

Copying the installed system

Next we want to copy the existing installation over to the new volumes. First we arrange the target filesystem structure and make it available by mounting it under /mnt.

mount -t ext3 /dev/vg1/root /mnt
mkdir /mnt/boot
mount -t ext3 /dev/md/0 /mnt/boot
mkdir -p /mnt/usr/local
mount -t ext3 /dev/vg1/local /mnt/usr/local
mkdir -p /mnt/opt
mount -t ext3 /dev/vg1/opt /mnt/opt
mkdir -p /mnt/export/home1
mount -t ext3 /dev/vg1/home /mnt/export/home1
mkdir -p /mnt/export/audio1
mount -t ext3 /dev/vg1/audio /mnt/export/audio1
There is more than one way to do the actual copying. Here's one:
cp -ax / /mnt
(And here is a variation of the theme: find / -xdev | cpio -pvmd /mnt)

Update fstab on the new filesystem, i.e., /mnt/etc/fstab. Here's mine:

/dev/vg1/root       /               ext3      errors=remount-ro  0  1
/dev/md/0           /boot           ext3      defaults           0  2
/dev/vg1/local      /usr/local      ext3      defaults           0  2
/dev/vg1/opt        /opt            ext3      defaults           0  2
/dev/vg1/home       /export/home1   ext3      defaults           0  2
/dev/vg1/audio      /export/audio1  ext3      defaults           0  2
/dev/vg1/swap       none            swap      sw                 0  0
tmpfs               /tmp            tmpfs     defaults           0  0
proc                /proc           proc      defaults           0  0
usbdev              /proc/bus/usb   usbdevfs  defaults           0  0
/dev/floppy/0       /floppy         auto      user,noauto        0  0
/dev/cdroms/cdrom0  /cdrom          iso9660   ro,user,noauto     0  0

Add an entry for the new setup to /etc/lilo.conf

# [... rest of lilo.conf ...]
image=/mnt/boot/vmlinuz-2.4.19-heebs.1.5
        label=LinuxLVM
        initrd=/mnt/boot/initrd.img-2.4.19-heebs.1.5.gz
        root=/dev/vg1/root
        read-only
lilo -v and rebooting should now activate the new setup. Once we are confident that everything worked out, we can update /etc/lilo on the new setup. (From now on, we keep the installation on /dev/hda3 only as a rescue fallback.)
# /etc/lilo.conf
#
lba32

boot=/dev/md/0
root=/dev/vg1/root

install=/boot/boot-menu.b
map=/boot/map
delay=10
# message=/boot/bootmess.txt
prompt
timeout=150
vga=normal
append="hdb=ide-scsi"

default=Linux

image=/boot/vmlinuz-2.4.19-heebs.1.5
        label=Linux
        initrd=/boot/initrd-lvm-2.4.19-heebs.1.5.gz
        read-only
Right now Linux is the only entry so there would be no need to ask for a "choice". There are a few reasons we still want to do that. One is the fact, that we might want to provide kernel parameters. Another is, that this single entry will become our backup kernel when we update to a new kernel image. And then we may want to play with other OSs and Linux distributions.

With fdisk /dev/discs/disc0/disc and fdisk /dev/discs/disc1/disc we set the boot flag on the first partition of each disc. lilo -v with the new /etc/lilo.conf file will write the new boot sector on the partition of both discs thanks to the RAID setup (see boot=/dev/md/0 in /etc/lilo.conf). While we are at it we update the both sectors on both discs with mbr too:
install-mbr -e 1 /dev/discs/disc0/disc
install-mbr -e 1 /dev/discs/disc1/disc

... to be continued ...