A Quick Dracut Module
Since the general trend on many linux distros is towards requiring /usr to be mounted at boot time, I figured I’d see what it would take to get it working using dracut.
I’ve been messing with dracut for a while, and for some reason it stubbornly refuses to detect my raid devices. The kernel autodetection works fine, but this is disabled when booting from an initramfs. Dracut would timeout and drop me to a dash shell, and if I just typed mdadm -As followed by exit it would boot just fine.
Dracut is using udev to set up raid devices, and obviously that is not working.
Beyond this, I’d like to get my /usr mounted pre-boot, and there is a module called usrmount that purports to do just this. However, it isn’t working in my case because /usr is a bind mount to a subdir on an lvm volume, and it just isn’t figuring that out (it doesn’t even run lvm in the first place despite having the module installed, let alone figuring out what to mount in what order – I suspect the lvm module only works if root is on lvm).
My solution to both problems is to build my own simple dracut module. If you want to try it out:
- cd /usr/lib/dracut/modules.d/
- mkdir 91local
- cat > 91local/module-setup.sh
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=shcheck() {
return 0
}depends() {
return 0
}install() {
inst_hook pre-trigger 91 "$moddir/mount-local.sh"
}
- cat > 91local/mount-local.sh
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=shmount_local()
{
mdadm -As
lvm pvscan
lvm vgscan
lvm lvscan
lvm vgchange -ay
}mount_local
Then run dracut to build your initramfs, and it should let mdadm and lvm auto-detect everything before it gets to mounting stuff. You can then use the fstab-sys to mount whatever you need to mount user. However, in your fstab.sys if you’re configuring a bindmount be sure to prepend /sysroot/ before the source directory.
Example fstab.sys:
/dev/vg1/data /data ext4 noatime,user_xattr,barrier=1 0 0
/sysroot/data/usr /usr none bind 0 0
/sysroot/data/var /var none bind 0 0
Hopefully this helps somebody out – the dracut documentation is pretty sparse. In fact, if somebody connected to dracut stumbles upon this I’d be open to a better way of hooking my script – pre-trigger just doesn’t seem right – I’d rather let udev try to do everything first. However, I couldn’t find any way to hook after udev runs but before it bombs out not finding my root device. Suggestions welcome.
Have you tried emerging dracut from portage with DRACUT_MODULES=”mdraid lvm” and NOT using “dracut -H” (i.e. hostonly)? For me dracut handles mdadm/mdraid and lvm like a charmwithout any trickery.
x
January 22, 2012 at 4:47 pm
Yup – numerous times. In fact the initramfs I am currently using (with my module added) is built that way. It boots fine with my module, and not otherwise.
I’m not sure why. I built a vm that is as close to my server as I can think with various 0.90 metadata raid-1s and usr bind-mounted from an lvm on a raid5. (Amusing setting up a vm with 4 2gb drives split 3 ways each – oh, and I found out mdadm tends to be fussy about multiple raid1 spares with the old metadata since it can’t tell them apart.)
I don’t use -H in any case – I’m sure it will shave a second or two off of boot time but I’d prefer that if for whatever reason I have to swap something out that it is pretty likely to work without any fuss. My next little project might be getting Gentoo running on my CR-48 with systemd and dracut and I might try it there – assuming an initramfs even makes sense not having read up on the chromebook bootloader…
rich0
January 22, 2012 at 5:23 pm