# init script to mount /usr and friends before udev

## greyspoke

OK peeps, as mentioned on the What do you think about Fedora/FreeDesktop.org UsrMove Plan? gentoo chat thread, here is my initscript which may provide an alternative way to be friendly with udev (alternative to mounting /usr in an initramfs).  This is improved thanks to comments from sphakka and steveL on that thread.  I have since then:

 - tried to make it POSIX compliant 

 - found a way of using a fake mount command to identify the devices from fstab that need checking and mounting, thus avoiding fancy stuff with sed or awk

 - not found a way to avoid checking the devices at this stage and relying on the fsck init script to do it later.  fsck will not check mounted devices even if mounted ro and I am getting conflicting messages from the internets about whether checking ro devices is safe.

You may say why not run mount all and fsck all commands with appropriate option restrictions.   That would work for mounting but not for fsck - ing as the devices will be set with the sixth bit on the line to 0 (don't check).

I can't fathom what is going on in the fsck init script, so I haven't tried to copy what it tries to do, though it appears to do some clever stuff that might be useful here.

Comments etc welcome.

modify /etc/fstab thus - add the comment=early option and put 0 in "pass" so it doesn't try to checkt an already mounted filesystem.  I have a separate /usr and /var, so probably will need to early mount them both.

```
[device]   /usr      ext3      noatime,comment=early   1 0

[device]   /var      ext3      noatime,comment=early   1 0

```

some configuration in /etc/conf.d/earlymounts - not needed if you don't use raids or lvms and want to check, this has my settings:

```
# earlymounts configuration file for early mounts init script

# set to true if raids need assembling, default is false

#mdadm=true

# set to true if logical volumes need activating, default is false, no 

# lvm will be done if false

lvm2=true

# comma separated list of names of volume groups to activate, if not set

# then all volume groups will be activated if lvm2 is set to true 

#vgs=vg

# comma separated list of lvm2 paths of volumes to activate

# if set and lvm2 is set to true the specified volumes will be activated

# as well as all volumes in any groups specified by vgs

lvs=vg/usr,vg/var

# whether to fsck the mounts or not, default is true

#check=false

```

And the script /etc/init/d/earlymounts

```
#!/sbin/runscript

# earlymounts - Gentoo Linux runscript to mount partitions early on in

# the init process.  Relies on the mounts being in /etc/fstab and will

# try to run fsck and then mount only those fstab entries that have the

# mount option comment=early set (no quotes around early)

# set defaults

depend() {

  before udev

}

doline () {

    if $check; then  

        ebegin "checking $5 filesystem on $1"

        fsck -C "$1"

        local err=$?

        if [ $err = 4 ]; then

            eerror "errors on filesystem on $1 couldn't be corrected, will not mount"

            return 1

        elif [ $err -gt 4 ]; then

            ewarn "fsck couldn't check filesystem on $1"

        elif [ $err -gt 0 ]; then

            ewarn "errors found on filelsystem on $1 and corrected"

        fi

    fi

    ebegin "mounting $1 on $3"

    mount "$1"

    err=$?

    eend $err "couldn't mount filesystem $1"

    return $err

}

start () {

    ebegin "starting early mount service"

    # build the raid arrays 

    if ${mdadm:=false}; then

        if [ -f /etc/mdadm.conf ]; then

            mdadm --assemble --scan

        else

            mdadm --assemble

        fi

    fi

    

    # now need to assemble the logical volumes 

    if ${lvm2:=false}; then

        if ! [ -z $vgs ]; then

            IFS=","

            for vg in $vgs; do

                unset IFS

                vgchange -aly --sysinit $vg

                IFS=","

            done

            unset IFS

        fi

        if ! [ -z $lvs ]; then

            IFS=","

            for lv in $lvs; do

                unset IFS

                lvchange -aly --sysinit $lv

                IFS=","

            done

            unset IFS

        fi

        if [ -z $vgs ] && [ -z $lvs ]; then

            vgchange -aly --sysinit

        fi

    fi

    

    #default check is true

    case $check in

        "true" | "false") ;;

        *) check=true;;

    esac

    

    # verbose mount fake all prints lines just for devices with the

    # specified option in /etc/fstab, with the devicename as the first word

    mntlines=$(mount -v -f -a -O comment=early)

    local err=0, retval=0

    IFS=$'\n'

    eindent

    for line in $mntlines; do

        unset IFS

        doline $line

        retval=$?

        err=$(($err + $retval))

        IFS=$'\n'

    done

    eoutdent

    eend $err "some filesystems not mounted or not checked"

    # check it worked before it scrolls by

    #read -p "press any key to continue"

    unset IFS

}

# no exit at the end of a runscript

```

Then you need to put this in the sysinit runlevel

```
rc-update add earlymounts sysinit
```

This works for me, can't promise it will work for you and I wouldn't suggest using it unless you can check it for yourself.

----------

## ExecutorElassus

ohgod, am I going to be a beta tester for this? What's the best route to test this? Right now, I have >=udev-181 hardmasked; should I install these scripts, update rc, and reboot (to see if it works) and then unmask udev? Do I need to do both at the same time? If this script does not work, is there a way to recover?

Thanks for your work on this. I'll, uh, report my findings? (Assuming my computer doesn't puke)

Cheers,

EE

UPDATE: okay, so it boots? Yay? I got a bunch of errors about fsck being unable to read/check the partitions; I'm assuming that's normal, yes? Should I unmask udev?

(I'm a bit of a wuss)

----------

## greyspoke

Well I didn't say you had to do it EE...

I am running udev-164-r2 (I think it is time to update my system) so I can't comment. (I did this to avoid some error messages from stuff that udev tried to start which needed /usr.)  I get the idea that this new udev refuses to play at all unless /usr is present.  So this ought to keep it happy.

If you are getting fsck complaining about checking partitions, did you set the last thing on the lines in fstab to "0" - which tells fsck not to try to check them?  This script checks the partitions you want mounted early (unless you have set check to false in the config file).

----------

## ExecutorElassus

Well, lemme try another tack (and this is a dumb question. Sorry!).

Is there a way to read a log of all the startup messages? The ones that come after rc is loaded, that are in the format "Checking [X]...................................[OK]" Because that's where I got all the errors: after rc had loaded, when fsck is usually run on all the lvm partitions.

Not checking the filesystems isn't such a terrible thing to me, but I would like to have it (if that's even what went wrong; it scrolled by too fast to read).

Thanks,

EE

----------

## gorkypl

 *ExecutorElassus wrote:*   

> Well, lemme try another tack (and this is a dumb question. Sorry!).
> 
> Is there a way to read a log of all the startup messages? The ones that come after rc is loaded, that are in the format "Checking [X]...................................[OK]" Because that's where I got all the errors: after rc had loaded, when fsck is usually run on all the lvm partitions.
> 
> Not checking the filesystems isn't such a terrible thing to me, but I would like to have it (if that's even what went wrong; it scrolled by too fast to read).
> ...

 

Enable rc_logger in /etc/rc.conf and check /var/log/rc.log

----------

## greyspoke

Or hit "L" key when rc starts and you will be able to walk through the boot process - here's the bit from etc/rc.conf:

```

# Set rc_interactive to "YES" and you'll be able to press the I key during

# boot so you can choose to start specific services. Set to "NO" to disable

# this feature.

rc_interactive="YES"

```

you checked your fstab and it is still happening I assume.

----------

## Hu

 *greyspoke wrote:*   

> Or hit "L" key when rc starts and you will be able to walk through the boot process - here's the bit from etc/rc.conf:
> 
> ```
> # Set rc_interactive to "YES" and you'll be able to press the I key during
> 
> ...

 Your post says L (as in Lima), but the text you quoted shows I (as in India).

----------

## greyspoke

Doh my brane... yes of course it is the "I" key, thanks.

----------

## derk

could this approach be added to the gentoo wiki   i.e.  http://wiki.gentoo.org ?

----------

## ExecutorElassus

thanks for the logging tip. But now I've checked rc.log, and it shows nothing. But watching, it looks like fsck is trying to run on the earlymounted drives, and failing (maybe because they're already mounted?). The drives all mount okay, it's just the timing of fsck seems to be wrong (and yes, the check flag is set to 0 in fstab). Unfortunately, rc.log doesn't start logging until later on in the startup process, so I can't see what's really going on. I'll try again in interactive mode, and see what the exact errors are.

Cheers,

EE

UPDATE: hrm. It went by too fast for me to hit the I key. But the errors I'm getting are what I thought: rc is failing to mount and check the earlymounted drives. Should I care about this? They're obviously mounted, so maybe this is just a needless second mount attempt that I can safely ignore?

----------

## greyspoke

Well I can't see why your system should behave differently EE, I am assuming your fsck script does the same thing as mine does - which should mean it won't try to check filesystems with the last word in fstab set to 0.  But also, it seems averse to checking mounted filesystems even if it thinks it should (which is a clearly a good thing), which would explain the errors.

Not sure how reliable things have to be to wiki them.  How many folk does this actually work for?

----------

## ExecutorElassus

Does "work" imply that I can boot newer udev without the system puking? I'll give it a shot and let you know, once I no longer have stuff to do that can't be put on hold for a few days while I rescue a broken system if it doesn't work. After Easter?

Cheers,

EE

----------

## sphakka

Hi there,

As promised, my contribution -- patches and comments.

 /etc/init.d/earlymounts (patch: '# cd /etc/init.d/ && patch < /path/to/patch-file')

```

--- earlymounts   2012-04-04 20:01:18.000000000 +0200

+++ earlymounts.new   2012-04-04 19:53:57.000000000 +0200

@@ -1,19 +1,40 @@

 #!/sbin/runscript

 # earlymounts - Gentoo Linux runscript to mount partitions early on in

 # the init process.  Relies on the mounts being in /etc/fstab and will

-# try to run fsck and then mount only those fstab entries that have the

-# mount option comment=early set (no quotes around early)

+# try to run fsck and then mount only those fstab entries that have

+# the mount option comment=early set (no quotes around early)

 # set defaults

+description="Early mount [and check] some filesystems to make udev happy ;-)"

+

+check=${check:=true}

+fsck_opts=${fsck_opts:='-C0 -T -a'}

+lvm2=${lvm2:=false}

+mdadm=${mdadm:=false}

+mount_opts=${mount_opts:=}

+pretend=${pretend:=false}

+

+# aux variables

+_IFS=','

+

+if yesno $pretend; then

+    alias runcmd='echo [fake]'

+else

+    # just a no-op

+    alias runcmd=':;'

+fi

+

+

 depend() {

-  before udev

+    before udev

 }

-doline () {

-    if $check; then

+_doline () {

+    # default check value taken into account here

+    if yesno $check; then

         ebegin "checking $5 filesystem on $1"

-        fsck -C "$1"

+        runcmd fsck $fsck_opts "$1"

         local err=$?

         if [ $err = 4 ]; then

             eerror "errors on filesystem on $1 couldn't be corrected, will not mount"

@@ -25,7 +46,7 @@

         fi

     fi

     ebegin "mounting $1 on $3"

-    mount "$1"

+    runcmd mount $mount_opts "$1"

     err=$?

     eend $err "couldn't mount filesystem $1"

     return $err

@@ -34,7 +55,7 @@

 start () {

     ebegin "starting early mount service"

     # build the raid arrays

-    if ${mdadm:=false}; then

+    if yesno $mdadm; then

         if [ -f /etc/mdadm.conf ]; then

             mdadm --assemble --scan

         else

@@ -43,22 +64,22 @@

     fi

     # now need to assemble the logical volumes

-    if ${lvm2:=false}; then

+    if yesno $lvm2; then

         if ! [ -z $vgs ]; then

-            IFS=","

+       local IFS="$_IFS"

             for vg in $vgs; do

                 unset IFS

                 vgchange -aly --sysinit $vg

-                IFS=","

+           IFS="$_IFS"

             done

             unset IFS

         fi

         if ! [ -z $lvs ]; then

-            IFS=","

+       IFS="$_IFS"

             for lv in $lvs; do

                 unset IFS

                 lvchange -aly --sysinit $lv

-                IFS=","

+           IFS="$_IFS"

             done

             unset IFS

         fi

@@ -67,29 +88,28 @@

         fi

     fi

-    #default check is true

-    case $check in

-        "true" | "false") ;;

-        *) check=true;;

-    esac

-

     # verbose mount fake all prints lines just for devices with the

     # specified option in /etc/fstab, with the devicename as the first word

-    mntlines=$(mount -v -f -a -O comment=early)

-    local err=0, retval=0

+    # (also don't write in /etc/mtab to avoid hassles)

+    mntlines=$(mount -vfan -O comment=early)

+    local err=0 retval=0

     IFS=$'\n'

     eindent

     for line in $mntlines; do

+        # need to filter out unexepcted output

+        echo $line| egrep -i 'already[[:blank:]]+mounted' >/dev/null && {

+            ewarn "$line: skipping..."

+            continue;

+        }

+        # only well-formatted lines should go through

         unset IFS

-        doline $line

+        _doline $line

         retval=$?

         err=$(($err + $retval))

-        IFS=$'\n'

+        local IFS=$'\n'

     done

     eoutdent

     eend $err "some filesystems not mounted or not checked"

-    # check it worked before it scrolls by

-    #read -p "press any key to continue"

     unset IFS

 }

```

Comments:

 added description and option declarations with default values at beginning. New options are:

 fsck_opts: mainly because I want minimal checks via the switch '-a'

 mount_opts: as I need '-r' (read-only) to avoid hassles with following fsck in boot runlevel

 pretend: to show fsck and mount commands without executing them. This is done by creating an alias which is prefixed to the relevant commands

 renamed 'doline()' to '_doline()' as it is an internal function, not a script command

 in '_doline()', branching on option 'check' moved here (default treated outside)

 in 'start()':

 branching on options unfied via 'yesno()'

 relevant variable localized to avoid ENV hassles

 default for 'check' removed

 fake mount with '-n' to not writing mtab (avoid hassles with double entries)

 added a filter for already mounted partition -- just cosmetic: it warns beforehand instead of letting _doline() scream; useful when debugging at system already up (I used dummy mount lines in my fstab...).

 watch out for commas in statements like 

```
local err=0, retval=0
```

 as you end up having 'err := 0,' which breaks 'eend'!

 /etc/conf.d/earlymounts (new options only)

```

# pretend executing mounts and checks; for debugging only. Default is false.

# pretend=true

# mount options. Default is empty. Use '-r' for read-only mounts (avoid hassles

# with fsck service running afterwards).

mount_opts='-r'

# fsck options. Default is '-C0 -T -a', i.e. output on STDOUT, be quiet and do

# automatic/lightweight checks

#fsck_opts='-C0 -T -a'

```

Comments: quite obvious.

It works for me with

 udev-171-r5, openrc-0.9.9.3 (though I'm downgrading it now for stability)

 /usr and /var on LVM, no raid

 read-only mounts and light fsck

The only harmless glitch, as seen already with the previous version, is LVM complaining later on about missing udev symlinks.

Other tips:

 OpenRC logging: set 'rc_log_path="/rc.log"' to also have sysinit logging (else won't work on /var as it is not mounted yet)

 I don't know why but '# rc-update add earlymounts sysinit' silently fails somewhere (with openrc-0.9.9.3): the dependency tree was not updated and earlymounts would run in default runlevel. However, forcing deps update with '# rc-update -u' fixed the problem

 possibly another udev side effect: my keyboard doesn't get up fast enough at sysinit (it lags behind for 10-20 seconds), so I can't enter interactive boot  :Sad:  An ugly workaround is temporarily adding a 'sleep 20' statements at end in '/etc/init.d/earlymounts' -- a better explanation/solution would be much appreciated!

Last but not least, I'd be keen on writing an ebuild for this... if I find some more spare time  :Wink: 

Enjoy!

  ^s

----------

## DaggyStyle

sphakka, the issue is with udev-182 and above, I fail to see how this is relevant if you didn't tested it on at least that version.

----------

## sphakka

Hi,

 *DaggyStyle wrote:*   

> sphakka, the issue is with udev-182 and above, I fail to see how this is relevant if you didn't tested it on at least that version.

 

One thing at a time, please.

1) fist step, verified that the script solves current issues with <udev-182 (alsactl and bluetooth);

2) next step, try with >=udev-182. But I'm waiting to see how this bug evolves, as I'm affected.

Cheers,

--^s

----------

## DaggyStyle

 *sphakka wrote:*   

> Hi,
> 
>  *DaggyStyle wrote:*   sphakka, the issue is with udev-182 and above, I fail to see how this is relevant if you didn't tested it on at least that version. 
> 
> One thing at a time, please.
> ...

 

thats make sense, I was under the impression that you've concluded the testing.

----------

## sphakka

Update.

Further testing with openrc-0.9.8.4 (as of today, stable in portage), earlymounts with read-only mounts breaks default runlevel, notably dbus and dependent services:

```

* Starting D-BUS system messagebus ...

Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_socket": Read-only file system

```

Since consolekit is also affected, my box *won't* boot correctly. I didn't try to early mount RW as I already know that it'll break openrc-0.9.9.3. So for the time being, I re-emerged the latest openrc (which so far behaved pretty well) and re-set earlymounts RO.

p.s. bug 408919 was fixed today, so I'll be soon testing udev-182!

----------

## The Sk

Thanks for the script. I will be trying it tomorrow. 

I'm affected by the same problem, having /usr on a seperate partition and had to create an initramfs =s with dracut.

I currently have udev 171, and heard that with 181 booting without an initramfs is deprecated. Is this true? If so I guess I'll stick with an initramfs and +5 seconds on my boot time =(

----------

## Hu

 *The Sk wrote:*   

> I currently have udev 171, and heard that with 181 booting without an initramfs is deprecated. Is this true? If so I guess I'll stick with an initramfs and +5 seconds on my boot time =(

 As I understand it, using >=sys-fs/udev-181 with separate /usr and no initramfs is unsupported and highly likely to fail in very frustrating ways.  Older versions have already not handled separate /usr particularly well, and support has degraded over time.

----------

## sphakka

 *The Sk wrote:*   

> Thanks for the script. I will be trying it tomorrow. 
> 
> I'm affected by the same problem, having /usr on a seperate partition and had to create an initramfs =s with dracut.
> 
> I currently have udev 171, and heard that with 181 booting without an initramfs is deprecated. Is this true? If so I guess I'll stick with an initramfs and +5 seconds on my boot time =(

 

IMHO, having an initramfs is just an (overkill) option. Earlymounts will hopefully spare you the extra overhead of maintaining an initramfs, though, as for boot time overhead, you might have the same penalty depending on how many partitions you'll mount and check. 

I'd appreciate if you could test the script posted by greyspoke plus my patch -- please, mind the warnings above about different openrc versions and RW vs RO mounts.

Cheers,

--^s

----------

## The Sk

I just found out that ctrl+s stops the boot up and enter starts it up.  

The original script works. I noticed it hangs a bit after "loading uevents" but is still faster than initramfs. Thanks =)

The patch doesn't run and outputs: 

```
./earlymounts: line 21: yesno: command not found

./earlymounts: line 55: syntax error near unexpected token `fi'

./earlymounts: line 55: `     fi' 
```

It seems it might be a problem on my end. I checked the code and can't tell why it's saying there's an error near "fi". I tried tabbing it and spacing it but it still fails.

----------

## sphakka

Thanks, The Sk!

 *The Sk wrote:*   

> 
> 
> I just found out that ctrl+s stops the boot up and enter starts it up. 
> 
> 

 

Interesting, I didn' know...

 *Quote:*   

> 
> 
> The patch doesn't run and outputs: 
> 
> ```
> ...

 

Possibly it wasn't clear from my previous posts, but you need at least openrc-0.9.8.4 (recommended version is 0.9.9.3, in order to use RO mounts) -- 'yesno' is a runscript's facility, you can check with $ man runscript if it's available in your setup. Those other syntax errors are possibly a consequence of the script breaking beforehand at yesno -- the shell is tricky, you know  :Wink:  BTW, you can debug it by running

```
# /etc/init.d/earlymounts -d <action>
```

Let me know!

----------

## gseba

Thanks for this quick post. But here is my `/etc/fstab':

```

/dev/mapper/linux-usr   /usr      auto   noatime,comment=udev   0 1

/dev/mapper/linux-lib64   /usr/lib64   auto   noatime,comment=udev   0 2

```

and `/etc/conf.d/earlymounts':

```

vgs=linux

lvs=linux/usr,linux/lib64

```

It looks a step further, so I patched it below (I rather use `udev' as "comment"; well, not important...)

```

--- earlymounts   2012-04-08 21:28:50.254407881 +0300

+++ earlymounts.static   2012-04-08 21:28:50.254407881 +0300

@@ -69,7 +69,7 @@

        local IFS="$_IFS"

             for vg in $vgs; do

                 unset IFS

-                vgchange -aly --sysinit $vg

+                lvm.static vgchange -aly --sysinit $vg

            IFS="$_IFS"

             done

             unset IFS

@@ -78,13 +78,13 @@

        IFS="$_IFS"

             for lv in $lvs; do

                 unset IFS

-                lvchange -aly --sysinit $lv

+                lvm.static lvchange -aly --sysinit $lv

            IFS="$_IFS"

             done

             unset IFS

         fi

         if [ -z $vgs ] && [ -z $lvs ]; then

-            vgchange -aly --sysinit

+            lvm.static vgchange -aly --sysinit

         fi

     fi

```

I wont go to far to suggest a USE flag "early" perhaps for `sys-fs/udev' to install your script? Except for this problem from `/var/log/rc.log':

 *Quote:*   

> 
> 
> /dev/mapper/linux-usr is mounted.  e2fsck: Cannot continue, aborting.
> 
> 

 

s.

----------

## sphakka

Hi gseba, 

Thanks for testing.

I'm not an LVM expert, but as far as I can see your patch prepends all lvm calls with lvm.static: I guess that's needed because your '/lib64' is on LVM, right?

As for USE flags, ebuilds & Co., I wouldn't start working on that until we can confirm that earlymounts works with udev-182. BTW, which version of udev are you using?

Also, is that error you see about e2fsck really blocking the boot process? I don't use ext* file systems, but on top of my head it looks like a RW mount problem: if so, please try RO mounts, by setting 

```
mount_opts='-r'
```

 in '/etc/conf.d/earlymounts'.

Lastly, on my box, I still see at shutdown weird warnings concerning my '/tmp' partition:

```

* Unmounting filesystems

 *   Unmounting /tmp ...

 *   in use but fuser finds nothing  [ !! ]

 * Shutting down the Logical Volume Manager

 *   Shutting Down logical volumes  ...

  LV flexzoHD2/tmp in use: not deactivating [ !! ]

 *   Shutting Down volume groups  ...

  Can't deactivate volume group "flexzoHD2" with 1 open logical volume(s) [ !! ]

```

Is anybody seeing the same message? Someone elsewhere suggests adding the failing mounts to 'RC_NO_UMOUNTS' ENV var, though I'd like to have an explanation for that...

Cheers,

  ^s

----------

## gseba

None other than those concerned: sys-fs/udev-182-r3, sys-apps/openrc-0.9.9.3.

It's the `/usr/lib64' mount, it's "libudev.so.0" that is not found because:

 *Quote:*   

> 
> 
> gseba@localhost ~ $ ldd /sbin/vgchange
> 
> 	linux-vdso.so.1 =>  (0x00007fff97572000)
> ...

 

all symlink'd against `/sbin/lvm' binary which is dynamic; try `lvm.static help' for the commands accepted.

The "mount_opts='-r'" is there; but, as you said, for now the log is harmless.

thank s.

----------

## gseba

Hi,

genkernel has another solution in `/etc/initramfs.mounts': list there "/usr" and "/usr/lib64", "/var" etc. and the initramfs created by genkernel will mount these on boot, before 'init'.

For me, it works only with patches from bug #411559, since in the case these are encrypted logical volumes, their volume group(s) must be priorly openLUKS'ed, using kernel cmdline parameter "crypt_maps".

s.Last edited by gseba on Sat Apr 21, 2012 6:44 pm; edited 2 times in total

----------

## sphakka

 *gseba wrote:*   

> 
> 
> genkernel has another solution in `/etc/initramfs.mounts': list there "/usr" and "/usr/lib64", "/var" etc. and the initramfs created by genkernel will mount these on boot, before 'init'.
> 
> 

 

Thanks for the tip, but... "initramfs" (argh!) is taboo in this thread  :Wink:  ... and, as far as I'm concerned, genkernel too.

  ^s

----------

## DaggyStyle

also genkernel  :Smile: 

----------

## gseba

 *sphakka wrote:*   

> 
> 
> "initramfs" (argh!) is taboo in this thread
> 
> 

 

I agree "initrd=", as a parameter, is optional.

Regarding "lvm.static" in the patch of my first post, this is from "pkg-setup" of =sys-fs/lvm2-2.02.95-r1 (the third "elog" line):

```

pkg_setup() {

   # 1. Genkernel no longer copies /sbin/lvm blindly.

   # 2. There are no longer any linking deps in /usr.

   if use static; then

      elog "Warning, we no longer overwrite /sbin/lvm and;/sbin/dmsetup with"

      elog "their static versions. If you need the static binaries,"

      elog "you must append .static to the filename!"

   fi

}

```

s.

----------

## ExecutorElassus

I've been away from this thread for a bit, and I'm wondering where the process stands. For example, with no initramfs, and /usr, /var/, and /opt on separate partitions (on a RAID array no less) is it possible to boot with >usev-182 and rc-0.9.9.3? Or is there still some tweaking to be done?

Thanks for the work,

EE

----------

## sphakka

 *ExecutorElassus wrote:*   

> I've been away from this thread for a bit, and I'm wondering where the process stands. For example, with no initramfs, and /usr, /var/, and /opt on separate partitions (on a RAID array no less) is it possible to boot with >usev-182 and rc-0.9.9.3? Or is there still some tweaking to be done?
> 
> Thanks for the work,
> 
> EE

 

As far as I understand, gseba is already on udev-182.

I'm still with udev-171-r5 as I see some blocking packages that might mess up my box:

```

flexzo ~ # emerge -pv udev

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild  N    ~] sys-apps/hwids-20120408  270 kB

[ebuild  N    ~] sys-apps/kmod-7  USE="tools zlib -debug -doc -lzma -static-libs" 959 kB

[uninstall     ] sys-apps/module-init-tools-3.16-r1  USE="-static" 

[blocks b      ] sys-apps/kmod ("sys-apps/kmod" is blocking sys-apps/module-init-tools-3.16-r1)

[blocks b      ] sys-apps/module-init-tools ("sys-apps/module-init-tools" is blocking sys-apps/kmod-7)

[ebuild  N    ~] sys-fs/udev-init-scripts-10  16 kB

[ebuild     U ~] sys-fs/udev-182-r3 [171-r5] USE="gudev hwdb keymap openrc%* rule_generator -build -debug -doc% -linux) -static-libs% (-acl%) (-action_modeswitch%) (-edd%) (-extras%*) (-test%)" 774 kB

[blocks b      ] <sys-fs/udev-182 ("<sys-fs/udev-182" is blocking sys-fs/udev-init-scripts-10)

[blocks B      ] <sys-apps/pciutils-3.1.9-r2 ("<sys-apps/pciutils-3.1.9-r2" is blocking sys-apps/hwids-20120408)

[blocks B      ] <sys-apps/usbutils-005-r1 ("<sys-apps/usbutils-005-r1" is blocking sys-apps/hwids-20120408)

Total: 4 packages (1 upgrade, 3 new, 1 uninstall), Size of downloads: 2,017 kB

Conflict: 5 blocks (2 unsatisfied)

 * Error: The above package list contains packages which cannot be

 * installed at the same time on the same system.

  (sys-apps/hwids-20120408::gentoo, ebuild scheduled for merge) pulled in by

    sys-apps/hwids required by (sys-fs/udev-182-r3::gentoo, ebuild scheduled for merge)

  (sys-apps/pciutils-3.1.9-r1::gentoo, installed) pulled in by

    sys-apps/pciutils required by (media-sound/alsa-utils-1.0.25-r1::gentoo, installed)

    sys-apps/pciutils required by (kde-base/kinfocenter-4.8.1::gentoo, installed)

    sys-apps/pciutils required by (sys-apps/vbetool-1.1::gentoo, installed)

    sys-apps/pciutils required by @selected

  (sys-apps/usbutils-004::gentoo, installed) pulled in by

    sys-apps/usbutils required by (kde-base/kinfocenter-4.8.1::gentoo, installed)

For more information about Blocked Packages, please refer to the following

section of the Gentoo Linux x86 Handbook (architecture is irrelevant):

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#blocked

The following keyword changes are necessary to proceed:

#required by sys-fs/udev-182-r3[hwdb], required by sys-fs/udev-init-scripts-10

=sys-apps/hwids-20120408 ~amd64

#required by sys-fs/udev-182-r3[openrc], required by udev (argument)

=sys-fs/udev-init-scripts-10 ~amd64

#required by sys-fs/udev-182-r3, required by sys-fs/udev-init-scripts-10

=sys-apps/kmod-7 ~amd64

```

Nothing really critical, though,  I'd like to know if anybody got in trouble because of that above -- so can't tinker too much on my "production" laptop...

----------

## sphakka

Pheeew! Upgraded today to udev-182-r3, my box boots fine  :Smile: 

Summary of my configuration:

- kernel 3.2.12-gentoo

- openrc-0.9.9.3

- udev-182-r3

- lvm 2.02.88: /usr, /var pre-mounted *RO*

- no RAID

Everything seems fully functional.

Someone should try with RAID...

Cheers,

  ^s

----------

## gseba

Congrats!

 *sphakka wrote:*   

> 
> 
> - no RAID 
> 
> Someone should try with RAID...
> ...

 

I tested mdadm=true for ( /home raid1) this configuration:

```

/dev/md0:

        Version : 0.90

  Creation Time : Sat Oct  2 23:00:58 2010

     Raid Level : raid1

     Array Size : 328922752 (313.69 GiB 336.82 GB)

  Used Dev Size : 328922752 (313.69 GiB 336.82 GB)

   Raid Devices : 2

  Total Devices : 2

Preferred Minor : 0

    Persistence : Superblock is persistent

    Update Time : Mon Apr 16 10:50:04 2012

          State : clean 

 Active Devices : 2

Working Devices : 2

 Failed Devices : 0

  Spare Devices : 0

           UUID : ...

         Events : 0.364

    Number   Major   Minor   RaidDevice State

       0       8       19        0      active sync   /dev/sdb3

       1       8        6        1      active sync   /dev/sda6

```

but fsck fails, and before there are about 10 messages:

 *Quote:*   

> 
> 
> mdam: sending ioctl 1261 to a partition!
> 
> 

 

afterwards '/dev/mapper/home' is not mounted (does not exist or something.)

I had to come to the console on the remote machine, so perhaps someone can fix it up before I should try again, glad to help, no thanks.

I emptied /etc/initramfs.mounts, added earlymounts to sysinit and appended comment= to /etc/fstab.

s.

----------

## sphakka

gseba,

I can't help much here. But, could you please post any other relevant mdadm/fsck error messages? In order to get sysinit properly logged, make sure RC logging is set with rc_log_path="/rc.log" AND your kernel configured with

```

CONFIG_DEVTMPFS=y

CONFIG_DEVTMPFS_MOUNT=y

```

BTW, I wonder if earlymounts should use scripts in '/lib64/rcscripts/addons/' to launch RAID and LVM, that would make it more consistent with the openrc framework...

----------

## gseba

sphakka,

I wished I can tell you it works or not. The two kernel configuration variables are there. Logging is of course enabled.

Here it  was:

```

rc sysinit logging started at Mon Apr  9 02:45:25 2012

   OpenRC 0.9.9.3 is starting up Gentoo Linux (x86_64) [XEN0]

Press I to enter interactive boot mode

 * /proc is already mounted, skipping

 * Mounting /run ... [ ok ]

 * /run/lock: creating directory

 * /run/lock: correcting owner

 * Mounting security filesystem ... [ ok ]

 * Mounting debug filesystem ... [ ok ]

 * Using /dev mounted from kernel ... [ ok ]

 * starting early mount service ...

  7 logical volume(s) in volume group "linux" now active

 *   checking auto filesystem on /dev/mapper/linux-usr ...

USR has been mounted 1 times without being checked, check forced.

USR: 100.0% USR: 41060/393216 files (2.6% non-contiguous), 389070/1571840 blocks

 *   mounting /dev/mapper/linux-usr on /usr ... [ ok ]

 *   checking auto filesystem on /dev/mapper/linux-lib64 ...

LIB has been mounted 1 times without being checked, check forced.

LIB: 100.0% LIB: 79417/393216 files (0.7% non-contiguous), 1154755/1572864 blocks

 *   mounting /dev/mapper/linux-lib64 on /usr/lib64 ... [ ok ]

 *   checking jfs filesystem on /dev/mapper/home ...

fsck.jfs version 1.1.15, 04-Mar-2011

processing started: 4/16/2012 15:06:39

Error: Cannot open device /dev/mapper/home

Usage:  fsck.jfs [-afnpvV] [-j journal_device] [--omit_journal_replay] [--replay_journal_only] device

Emergency help:

 -a                 Automatic repair.

 -f                 Force check even if file system is marked clean.

 -j journal_device  Specify external journal device.

 -n                 Check read only, make no changes to the file system.

 -p                 Automatic repair.

 -v                 Be verbose.

 -V                 Print version information only.

 --omit_journal_replay    Omit transaction log replay.

 --replay_journal_only    Only replay the transaction log.

 *   fsck couldn't check filesystem on /dev/mapper/home

 *   mounting /dev/mapper/home on /home ...

mount: special device /dev/mapper/home does not exist

 *   couldn't mount filesystem /dev/mapper/home

 [ !! ]

 * some filesystems not mounted or not checked

 [ !! ]

 * About to start the service dmesg

 *   1) Start the service      2) Skip the service

 *   3) Continue boot process      4) Exit to shell

Give root password for maintenance

(or type Control-D to continue): 

bash: no job control in this shell

localhost ~ # mdadm 

localhost ~ # mdadm --assemble --scan

localhost ~ # cat /etc/mdadm.conf 

DEVICE /dev/sdb3 /dev/sda6

ARRAY /dev/md0 devices=/dev/sdb3,/dev/sda6

...

```

The script `earlymounts' in `/etc/init.d' already has "embedded" `mdraid' script and `lvm' in it. If you go for addons, it's likely you will reach duplication. Could you not resolve this with "depend" functionality?

```

depend () {

     before udev

     after mdraid lvm

}

```

s.

----------

## sphakka

Mmh, I see nothing about mdadm running (!?). Gseba, please, modify the relevant snippet in `earlymounts' with the following one:

```

    if yesno $mdadm; then

        if [ -f /etc/mdadm.conf ]; then

            mdadm -vv --assemble --scan 2>&1

        else

            mdadm -vv --assemble 2>&1

        fi

    fi

```

... and try again. It should be safe also calling the script on the running system with `restart' action.

 *Quote:*   

> 
> 
> The script `earlymounts' in `/etc/init.d' already has "embedded" `mdraid' script and `lvm' in it. If you go for addons, it's likely you will reach duplication. Could you not resolve this with "depend" functionality?
> 
> 

 

That would be OK for mdraid; as for LVM, we want to be selective, so for now we keep it as it is.

   ^s

----------

## gseba

sphakka,

 *Quote:*   

> 
> 
> ... and try again. It should be safe also calling the script on the running system with `restart' action. 
> 
> 

 

As reaction to what you requested, I stepped a "running system" throughout sysinit and boot and have the following results.

 This became for me a probem of right steps and system administration. I managed to bootup Gentoo with the following setups.

 patch the `/lib/rcscripts/addons/lvm-start.sh'

```

--- lvm-start.sh   2012-04-17 22:24:32.000000000 +0300

+++ lvm-start.sh.static   2012-04-17 22:24:11.000000000 +0300

@@ -18,7 +18,7 @@

 

 # NOTE: Add needed modules for LVM or RAID, etc

 #       to /etc/modules.autoload if needed

-for lvm_path in /bin/lvm /sbin/lvm ; do

+for lvm_path in /{s,}bin/lvm{.static,} ; do

    [ -x "$lvm_path" ] && break

 done

 if [ -z "${CDBOOT}" -a -x "$lvm_path" ] ; then

```

UPDATE they moved `/lib/rcscripts/addons/lvm-start.sh' to plain `/etc/init.d/lvm' where now i have

```
for lvm_path in /{s,}bin/lvm{.static,} ; do
```

in `start()' and `stop()'

 this script is copied frow within portage `sys-fs/lvm2/files' directory

 note that `/etc/conf.d/lvm' contains the line: RC_AFTER="mdraid"

 make sure to have the kernel configuration variable set: CONFIG_TMPFS=Y

 edit the `/etc/lvm/lvm.conf' global settings and set variable: locking_dir = "/run/lock"

 do openrc logging there too: rc_log_path="/run/rc.log"

 For the second part, add all required services by `earlymount' to sysinit level, and delete them from their previous (boot) runlevel:

```

eselect rc delete device-mapper boot

eselect rc delete lvm boot

eselect rc delete dmcrypt boot

eselect rc delete mdraid boot

```

```

eselect rc add device-mapper sysinit

eselect rc add lvm sysinit

eselect rc add dmcrypt sysinit

eselect rc add mdraid sysinit

```

mdadm service uses /var/run/mdadm.pid, so leave it there (boot ).

 *Quote:*   

> 
> 
> That would be OK for mdraid; as for LVM, we want to be selective, so for now we keep it as it is.
> 
> 

 

But you would accept the simplification where they were both `use' dependencies?

 For the third part, keep `earlymount' to its specificity: to mount filesystems (/usr in the main) early. So have these filesystems listed in the mounts variable. The comment= is no further required in /etc/fstab.

```

# earlymounts configuration file for early mounts init script

# ...

# comma separated list of filesystems to mount

mounts=/usr,/usr/lib64,/home

```

 Next, step to a lite `earlymounts' script; start becomes:

```

...

mounts=${mounts:=/usr}

...

depend() {

    before udev

    use dmcrypt mdraid lvm

}

start () {

    ebegin "starting early mount service"

    # verbose mount fake all prints lines just for devices with the

    # specified option in /etc/fstab, with the devicename as the first word

    # (also don't write in /etc/mtab to avoid hassles)

    local err=0 retval=0 mntlines=$(mount -vfan) mount line

    eindent

    local IFS_="$IFS"

    local IFS="$_IFS"

    for mount in $mounts; do

        export IFS="$IFS_"

        line=$(echo "$mntlines" | egrep "on $mount type")

        ! [ -z "$line" ] || ewarn "$mount: skipping..."

        ! [ -z "$line" ] || continue

        _doline $line

        retval=$?

        err=$(($err + $retval))

    done

    eoutdent

    eend $err "some filesystems not mounted or not checked"

}

```

The egrep code selects the "on /xxx type yyy (zzz)" infixed lines out of "already mounted on xxx" end-suffixed ones. The _doline $line is perfect, replace with _doline "$line" makes "$1" a whole line, not the device path.

Now the boxes: with LVM (a), with both LVM and RAID (b), without any (c).

 LVM only

```

# earlymounts configuration file for early mounts init script

# comma separated list of filesystems to mount

mounts=/usr,/usr/lib64

```

```

$ eselect rc show sysinit

Status of init scripts in runlevel "sysinit"

  devfs                     [started]

  device-mapper             [started]

  dmcrypt                   [started]

  dmesg                     [started]

  earlymounts               [started]

  lvm                       [started]

  udev                      [started]

  udev-mount                [started]

```

 *Quote:*   

> 
> 
>  * Shutting down the Logical Volume Manager
> 
>  * Finished Shutting down the Logical Volume Manager
> ...

 

 LVM and RAID

```

# earlymounts configuration file for early mounts init script

# comma separated list of filesystems to mount

mounts=/usr,/usr/lib64,/home

```

```

$ eselect rc show sysinit

Status of init scripts in runlevel "sysinit"

  devfs                     [started]

  device-mapper             [started]

  dmcrypt                   [started]

  dmesg                     [started]

  earlymounts               [started]

  lvm                       [started]

  mdraid                    [started]

  udev                      [started]

```

 *Quote:*   

> 
> 
>  * Shutting down the Logical Volume Manager
> 
>  * Finished Shutting down the Logical Volume Manager
> ...

 

There is also configuration in `/etc/conf.d/dmcrpyt':

```

target=home

source='/dev/md0'

key='/homekey'

remdev='/dev/sda1'

```

 no LVM no RAID

```

# earlymounts configuration file for early mounts init script

# comma separated list of filesystems to mount

mounts=/usr,/usr/lib

```

```

$ eselect rc show sysinit

Status of init scripts in runlevel "sysinit"

  devfs                     a

  device-mapper             a

  dmesg                     a

  earlymounts               a

  lvm                       a

  udev                      a

  udev-mount                a

```

 *Quote:*   

> 
> 
>  * Shutting down the Logical Volume Manager
> 
>  * Finished Shutting down the Logical Volume Manager
> ...

 

The modules service must not be moved to sysyinit (left in boot).

The "sysinit" runlevel is the correct one where to place device-mapper, lvm, mdraid, dmcrypt; lvm needs writable path for locking: `/run/lock' (tmpfs) is suitable. From there, the line in `depend' takes care of the rest needed before early mounts.

```

    use dmcrypt mdraid lvm

```

The patch causes lvm.static to be found and used before.

The variables you had in `earlymounts` are all in order, but no LVM and no RAID workarounds are needed once the sysinit is populated with the correspondent services. The _doline is untouched, and `mount -vafn' is still what `earlymount' script is based on; the `comment=' is dropped for the `mounts' list configuration variable. But this can be reverted back: perhaps you had in mind to make the fsck service ignore "commented" lines in `/etc/fstab'.

s.Last edited by gseba on Sat Jun 16, 2012 12:02 pm; edited 1 time in total

----------

## greyspoke

blimey, it will take a while to work out what has been going on here, but to catch up on a few points, sphakka and gseba you appear to know more about this than I do.  I did look at including the raid and lvm scripts in sysinit runlevel, but it looked too complex for me.  

I did find a way round the rather alarming lvm messages on closing down, by introducing another init script 

```

#!/sbin/runscript

# dm-trigger-udev - Gentoo Linux runscript to trigger a udev event for

# any devices with system names beginning with dm- eg logical volumes

# should run after udev but before lvm

# set defaults

depend() {

  after udev

}

start () {

    ebegin "triggering logical volumes with udev"

    udevadm trigger --action=change --sysname-match=dm-*

}

# no exit at the end of a runscript

```

This partly fools lvm into thinking that the dm devices are pukka made-by-udev ones so there are no complaints on shutting down, though I still get the more innocuous message(s) on startup about names not having been created by udev when they should have been.

Anyhow, you guys seem to have taken this a way further.

----------

## steveL

This:

```
udevadm trigger --action=change --sysname-match=dm-*
```

needs quotes:

```
udevadm trigger --action=change --sysname-match='dm-*'
```

to be safe. As * is a globbing character, if the script were to run in a directory with a filename starting dm- then that name (or names) would be passed. I realise it's unlikely, but it's better to be safe once in scripts.

Also, if you're averse to moving everything to sysinit as described, you could try our patched scripts which just make udev start after localmount: it's slightly trickier to setup in that you have to patch two udev initscripts, but there's no configuration beyond setting initramfs=no in /etc/conf.d/udev (and switching udev to boot at the same time). It allows the standard sequence to run, so takes care of fsck and localmount as usual, and works if you don't need udev-created nodes to localmount (ie you have drivers for your hard-disk and motherboard, root filesystem and eg device-mapper for lvm, built-in to the kernel, not as modules, which you do when you manually configure a kernel on install.) AFAIK the same is needed for earlymounts.

I run it with lvm, but don't have mdadm so someone trying that would be good feedback for others who use it.

Not sure if the new sep-usr flag for busybox can deal with lvm or mdadm. I doubt it since it runs before init:

 *vapier wrote:*   

> [the] new applet has a hand written set of commands to automatically mount /dev /proc /sys /usr and seed /dev, and then execute 
> 
> the real init (defaulting to /sbin/init)

 

----------

## steveL

[edit: delete duplicate post, sorry about that]Last edited by steveL on Mon Jun 11, 2012 9:15 pm; edited 1 time in total

----------

## greyspoke

Well, that was all going OK until I updated my ~amd64 system (I really should update more frequently).  Now with udev-187-r3.

But that's not the problem, the problem is that the creep of basic system stuff to /usr has started.  My LVM2, built with the udev use flag, needs libudev.so.1, which lives on... /usr/lib64.  So I went back to activating and mounting my logical volumes in an initramfs for a bit, then tried putting libudev.so.1.0.3 and the symlinks to it in /usr/lib64 on my root partition and going back to earlyonunts.  It worked, except...

The only modules I have set to load via the modules init script are the ones for VirtualBox, my kernel is mainly monolithic except for the wifi ones, and they are loaded automatically by udev.  There is an error message with the vboxdrv etc modules saying modprobe command not found.  As part of the upgrade modprobe is now a symlink to /usr/sbin/kmod.  I guess the modules script (in boot runlevel) starts sufficiently soon after earlymounts (in sysinit) for the mounts not actually to be available.  Surprising, since the udev script (in sysinit) doesn't complain. If I had a very modular kernel this would be a considerable PITA.  

When the world and its dog have moved to /usr, this could get messy...

----------

