# [SOLVED] dracut and bind mounts on /usr

## radio_flyer

I have a relatively new stable amd64 gentoo system with both an HDD and an SSD. The SSD is bind-mounted onto various directories like so:

```

# HDD and SSD

/dev/sda1               /boot           ext4    noatime                     1 2

/dev/sda2               /               ext4    noatime                     0 1

/dev/sda3               /home           ext4    noatime                     0 2

/dev/sdb1               /ssd            ext4    noatime,nodiratime,discard  0 2

# swap

/swapfile               swap            swap    defaults                    0 0

# shared memory

shm                     /dev/shm        tmpfs   nodev,nosuid,noexec         0 0

# SSD binds

/ssd/opt                /opt            none    bind

/ssd/usr/bin            /usr/bin        none    bind

/ssd/usr/games          /usr/games      none    bind

/ssd/usr/include        /usr/include    none    bind

/ssd/usr/lib32          /usr/lib32      none    bind

/ssd/usr/lib64          /usr/lib64      none    bind

/ssd/usr/libexec        /usr/libexec    none    bind

/ssd/usr/local          /usr/local      none    bind

/ssd/usr/sbin           /usr/sbin       none    bind

/ssd/usr/share          /usr/share      none    bind

# CD-ROM

/dev/cdrom              /mnt/cdrom      auto    noauto,ro,user              0 0

# other miscellaneous stuff

/dev/sdc1               /mnt/flash      auto    noauto,user                 0 0

```

Other than a few alsactl warnings, the system currently boots fine with this configuration. It leaves the boot-time executables on the HDD, puts most of the application executables on the SSD, and minimizes the number of writes to the SSD by keeping things like /usr/src, /usr/portage and other oft-written directories in /usr off the SSD.

Also note that I build my own kernels from gentoo-sources using the 'make oldconfig' 'make menuconfig' manual approach.

However, now comes the infamous /usr merge, as discussed here: https://forums.gentoo.org/viewtopic-p-6987422.html#6987422

Since I'd like to hop this freight train before it plows into stable, I decided to install dracut and see if I could get my system to boot off an initramfs with the /usr binds properly mounted. A side benefit would be that alsactl would finally shut up.

My first attempt running dracut succeeded in building an initramfs which booted the system fine, however, with no /usr bind mounts. In other words, no difference. Even though the dracut usrmount module is loaded, it apparently only looks for a full /usr partition mount and is oblivious to bind mounts.

So I tried creating an /etc/fstab.sys file as described on the Gentoo Wiki: http://wiki.gentoo.org/wiki/Dracut

```

# /etc/fstab.sys: initramfs file system information.

#

# this file is loaded into the initramfs in order to get the /usr

# bind mounts done before launching init.

#

# <fs>                  <mountpoint>    <type>  <opts>          <dump/pass>

# necessary boot disks (root on /dev/sda2 is already mounted)

/dev/sdb1               /ssd          ext4   noatime,nodiratime,discard     0 2

#SSD binds

/ssd/opt                /opt          none    bind

/ssd/usr/bin            /usr/bin      none    bind

/ssd/usr/games          /usr/games    none    bind

/ssd/usr/include        /usr/include  none    bind

/ssd/usr/lib32          /usr/lib32    none    bind

/ssd/usr/lib64          /usr/lib64    none    bind

/ssd/usr/libexec        /usr/libexec  none    bind

/ssd/usr/local          /usr/local    none    bind

/ssd/usr/sbin           /usr/sbin     none    bind

/ssd/usr/share          /usr/share    none    bind

```

However, this is what I get at boot:

 *Quote:*   

> 
> 
> [    1.664854] dracut: Checking ext4: /dev/sda2
> 
> [    1.665010] dracut: issuing e2fsck -a  /dev/sda2
> ...

 

And, of course, since the SSD did mount in the initramfs, after root is switched init complains later on:

'/dev/sdb1 is mounted. e2fsck: Cannot continue, aborting', followed by 'Operational error'. Init then proceeds to do the binds, and the boot continues normally from that point on.

So, can someone shed some light on how to get the dracut initramfs to do these binds? Preferably before the other light at the end of this Fedora-dug tunnel gets here. Thanks.Last edited by radio_flyer on Thu Mar 29, 2012 7:34 am; edited 1 time in total

----------

## Hu

Based on the messages you showed, Dracut is treating your fstab strangely.  It prepends /sysroot to the mount point for the actual mount, but then takes your bind lines as-is.  This may be normal behavior for Dracut, in which case you need to adjust your fstab to compensate for this silliness.

----------

## radio_flyer

Hu, you're right. Here's what the new /etc/fstab.sys looks like:

```

# /etc/fstab.sys: initramfs file system information.

#

# this file is loaded into the initramfs in order to get the /usr

# bind mounts done before launching init.

#

# <fs>                  <mountpoint>  <type>  <opts>            <dump/pass>

# necessary boot disks (root on /dev/sda2 is already mounted)

/dev/sdb1               /ssd          ext4   noatime,nodiratime,discard  0 2

# SSD binds

/sysroot/ssd/opt                /opt          none    bind

/sysroot/ssd/usr/bin            /usr/bin      none    bind

/sysroot/ssd/usr/games          /usr/games    none    bind

/sysroot/ssd/usr/include        /usr/include  none    bind

/sysroot/ssd/usr/lib32          /usr/lib32    none    bind

/sysroot/ssd/usr/lib64          /usr/lib64    none    bind

/sysroot/ssd/usr/libexec        /usr/libexec  none    bind

/sysroot/ssd/usr/local          /usr/local    none    bind

/sysroot/ssd/usr/sbin           /usr/sbin     none    bind

/sysroot/ssd/usr/share          /usr/share    none    bind

```

I also had to change the SSD drive partition pass value in /etc/fstab to disable the filesystem check, as that is now done in the initramfs. Otherwise, e2fsck errors out on /dev/sdb1 when control is passed out of the initramfs:

```

/dev/sdb1               /ssd            ext4    noatime,nodiratime,discard  0 0

```

I had actually tried the /sysroot prefix previously (having seen the same messages at startup) but was initially confused because I saw errors spew out before each bind mount, namely:

 *Quote:*   

> 
> 
> [: 1: Illegal number:
> 
> device node not found
> ...

 

After some digging around the dracut modules, it appears that is actually a udevadm message triggered by the dracut fstab.sys script "/usr/lib/dracut/modules.d/95fstab-sys/mount-sys.sh", excerpted here:

```

fstab_mount() {

    local _dev _mp _fs _opts _dump _pass _rest

    test -e "$1" || return 1

    info "Mounting from $1"

    while read _dev _mp _fs _opts _dump _pass _rest; do

        [ -z "${_dev%%#*}" ] && continue # Skip comment lines

        if [ "$_pass" -gt 0 ] && ! strstr "$_opts" _netdev; then

            fsck_single "$_dev" "$_fs"

        fi

        _fs=$(det_fs "$_dev" "$_fs")   <-- this causes problems

        info "Mounting $_dev"

        if [ -d "$NEWROOT/$_mp" ]; then

            mount -v -t $_fs -o $_opts $_dev "$NEWROOT/$_mp" 2>&1 | vinfo

        else

            mkdir -p "$_mp"

            mount -v -t $_fs -o $_opts $_dev $_mp 2>&1 | vinfo

        fi

    done < $1

    return 0

}

```

The $(det_fs ...) part is actually a function that calls "udevadm info" with $_dev as the --name parameter, which is supposed to be a device node or symlink to one. A bind mount obviously has nothing to do with device nodes, so this function errors out. Other than for the annoying error messages, however, nothing appears to break, and the system boots normally from that point forward. Guess I'll file a bug report. On the bright side, the alsactl errors are now gone.

Now I'll wait and see what happens when the 'new and improved' udev hits stable.

Thanks again Hu.

----------

