Rich0's Gentoo Blog

A Quick Dracut Module

with 6 comments

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:

  1. cd /usr/lib/dracut/modules.d/
  2. mkdir 91local
  3. 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=sh

    check() {
    return 0
    }

    depends() {
    return 0
    }

    install() {
    inst_hook pre-trigger 91 "$moddir/mount-local.sh"
    }

  4. 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=sh

    mount_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.

About these ads

Written by rich0

January 21, 2012 at 4:28 pm

Posted in gentoo, linux

6 Responses

Subscribe to comments with RSS.

  1. 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

  2. Neighbourly greetings from Fedora-land, and thanks for helping me fix a problem I had following the /usr-move operation that came with the upgrade to FC17. Not identical, but looks like combination of /usr-move, having /usr on a separate partition, and using LVM are all factors. See here my posting on Fedora Forums.

    Thanks,
    Andrew

    Andrew Wasielewski

    July 25, 2012 at 6:51 pm

    • Glad I could be of help – I actually have learned most of what I know about Dracut from the Fedora docs in the first place, so happy to return the favor.

      I suspect you wouldn’t need the custom module but just the fstab-sys module. I never figured out why Dracut wasn’t assembling the raid without my custom module, but it has been hard to reproduce on VMs/etc, so it probably won’t affect many others. However, besides slowing down boot by a few seconds doing an mdadm -As shouldn’t hurt anything.

      rich0

      July 25, 2012 at 10:06 pm

  3. Incorporated into my own Gentoo/Funtoo Portage overlay, for easy installation.
    https://github.com/mirage335/BaseEbuilds-mirage335/tree/master/sys-kernel/dracutLocalMount
    Note pre-trigger was changed to initqueue/settled . Apparently necessary to wait for an out-of-kernel SATA port driver.
    Thank you for providing this example.

    mirage335

    May 18, 2014 at 7:06 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: