Gentoo lvm+raid root
- gentoo lvm raid
Gentoo support for lvm root is still a pain in the ass, here is a working solution.
Assuming you have 2 disks same size to be mirrored.
You want a mirrored /boot and a big lvm.
Start a normal gentoo installation with this disks layout:
fdisk -l /dev/sda
Device Boot Start End Blocks Id System
/dev/sda1 * 1 31 248976 fd Linux raid autodetect
/dev/sda2 32 242246 1945591987+ fd Linux raid autodetect
fdisk -l /dev/sdb
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 31 248976 fd Linux raid autodetect
/dev/sdb2 32 242246 1945591987+ 83 Linux raid autodetect
Set both disk the boot flags on the first partition and set all partitions to FD Linux raid autodetect.
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2
If it complains about another array by this is name is already running or disk used.
First stop them all:
cat /proc/mdstat
Identify the old arrays then stop it:
mdadm --stop /dev/md??
Clean the partition if necessaray
dd if=/dev/zero of=/dev/sda1 count=100 bs=1024
dd if=/dev/zero of=/dev/sda1 count=100 bs=1024
Create the boot:
mkfs.ext3 /dev/md0
Create the lvm root and swap:
pvcreate /dev/md1
vgcreate vg0 /dev/md1
lvcreate -L10G -nroot vg0
lvcreate -L16G -nswap vg0
# set the minfree to 0 and increase the number of inodes to 600k
mkfs.ext4 -m0 -N 600000 /dev/vg0/root
mkswap /dev/vg0/swap
Mount them all !
mount /dev/vg0/root /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/md0 /mnt/gentoo/boot
Continue with the standard install procedure, mount -t proc …
After the emerge –sync in the install procedure get back here:
emerge lvm2 dmadm genkernel
emerge gentoo-sources
mdadm --examine --scan >> /etc/mdadm.conf
Edit /etc/genkernel.conf:
Set LVM=“yes”
Set MDADM=“yes”
Edit /etc/fstab
/dev/md0 /boot ext3 noauto,noatime 1 2
/dev/vg0/root / ext4 noatime 0 1
/dev/vg0/swap none swap sw 0 0
Compile your kernel with genkernel (note that if you want to compile your own kernel without genkernel this is possible with the command genkernel initramfs).
genkernel --menuconfig all
Continue to normal procedure until grub, apply grub on both disks:
grub> root (hd0,0)
grub> setup (hd0)
grub> root (hd2,0)
grub> setup (hd1)
grub> quit
Then edit grub.conf
title Gentoo
root (hd0,0)
kernel /boot/kernel-genkernel-x86_64-2.6.36-gentoo-r5 root=/dev/ram0 real_root=/dev/vg0/root dolvm domdadm lvmraid=/dev/md1
initrd /boot/initramfs-genkernel-x86_64-2.6.36-gentoo-r5
Explanation, for lvm to find his disks, we need a ramfs with the static lvm command, but to find back our raids md we also need mdadm to save the config somewhere, that’s exactly what the genkernel initramfs is doing.
Then we invoke the kernel with ramfs and domdadm dolvm and lvmraid.
You can use the initramfs with your own kernel, you only have to be sure all needed hardware drivers to detect the disks are in the kernel, and not as modules.
Remember that when gentoo stable will update to baselayout2 you will have to add rc-update add mdraid boot.
EDIT: on recent Gentoo I have to add this to kernel boot line:
kernel /boot/kernel-genkernel-x86_64-3.1.10-gentoo-r1 root=/dev/ram0 init=/linuxrc real_root=/dev/vg0/root udev dolvm domdadm gentoo=nodevfs lvmraid=/dev/md1 rootfstype=ext4