- 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.
Code: Select all
[device] /usr ext3 noatime,comment=early 1 0
[device] /var ext3 noatime,comment=early 1 0
Code: Select all
# 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
Code: Select all
#!/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
Code: Select all
rc-update add earlymounts sysinit





