diff options
author | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2014-01-02 09:32:49 +0100 |
---|---|---|
committer | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2014-01-02 09:32:49 +0100 |
commit | d39fe99ff7e4af637c0ac1ec58c6e99d5f84cee2 (patch) | |
tree | e7983a5496e8a98b50e74f0edbbf0cbee1dff58b | |
parent | 5569908096356685152dc5194e4f3643ec05baad (diff) | |
download | embtoolkit-d39fe99ff7e4af637c0ac1ec58c6e99d5f84cee2.tar.gz embtoolkit-d39fe99ff7e4af637c0ac1ec58c6e99d5f84cee2.tar.bz2 embtoolkit-d39fe99ff7e4af637c0ac1ec58c6e99d5f84cee2.tar.xz |
Rootfs: boot runlevel: add swap and localmount init scripts
Signed-off-by: Abdoulaye Walsimou Gaye <awg@embtoolkit.org>
-rw-r--r-- | mk/rootfs/openrc/etc/init.d/localmount | 85 | ||||
-rw-r--r-- | mk/rootfs/openrc/etc/init.d/network | 3 | ||||
-rw-r--r-- | mk/rootfs/openrc/etc/init.d/procfs | 1 | ||||
-rw-r--r-- | mk/rootfs/openrc/etc/init.d/swap | 30 | ||||
-rw-r--r-- | mk/rootfs/openrc/etc/init.d/urandom | 5 | ||||
-rw-r--r-- | mk/rootfs/openrc/openrc.mk | 4 |
6 files changed, 125 insertions, 3 deletions
diff --git a/mk/rootfs/openrc/etc/init.d/localmount b/mk/rootfs/openrc/etc/init.d/localmount new file mode 100644 index 0000000..d6ef8fd --- /dev/null +++ b/mk/rootfs/openrc/etc/init.d/localmount @@ -0,0 +1,85 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mounts disks and swap according to /etc/fstab." + +depend() +{ + use modules mtab + after modules +} + +start() +{ + # Mount local filesystems in /etc/fstab. + local types="noproc" x= no_netdev= + for x in $net_fs_list $extra_net_fs_list; do + types="${types},no${x}" + done + + if [ "$RC_UNAME" = Linux ]; then + no_netdev="-O no_netdev" + if mountinfo -q /usr; then + touch "$RC_SVCDIR"/usr_premounted + fi + fi + ebegin "Mounting local filesystems" + mount -at "$types" $no_netdev + eend $? "Some local filesystem failed to mount" + + # Always return 0 - some local mounts may not be critical for boot + return 0 +} + +stop() +{ + yesno $RC_GOINGDOWN || return 0 + # We never unmount / or /dev or $RC_SVCDIR + + # Bug 381783 + local rc_svcdir=$(printf '%s\n' "$RC_SVCDIR" | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g') + + local x= no_umounts_r="/|/dev|/dev/.*|${rc_svcdir}" + no_umounts_r="${no_umounts_r}|/bin|/sbin|/lib(32|64)?|/libexec" + # RC_NO_UMOUNTS is an env var that can be set by plugins + local IFS="$IFS:" + for x in $no_umounts $RC_NO_UMOUNTS; do + no_umounts_r="$no_umounts_r|$x" + done + + if [ "$RC_UNAME" = Linux ]; then + no_umounts_r="$no_umounts_r|/proc|/proc/.*|/run|/sys|/sys/.*" + if [ -e "$rc_svcdir"/usr_premounted ]; then + no_umounts_r="$no_umounts_r|/usr" + fi + fi + no_umounts_r="^($no_umounts_r)$" + + # Flush all pending disk writes now + sync + + . "$RC_LIBEXECDIR"/sh/rc-mount.sh + + # Umount loop devices + einfo "Unmounting loop devices" + eindent + do_unmount "umount -d" --skip-point-regex "$no_umounts_r" \ + --node-regex "^/dev/loop" + eoutdent + + # Now everything else, except network filesystems as the + # network should be down by this point. + einfo "Unmounting filesystems" + eindent + local fs= + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+|}$x" + done + [ -n "$fs" ] && fs="^($fs)$" + do_unmount umount --skip-point-regex "$no_umounts_r" \ + "${fs:+--skip-fstype-regex}" $fs --nonetdev + eoutdent + + return 0 +} diff --git a/mk/rootfs/openrc/etc/init.d/network b/mk/rootfs/openrc/etc/init.d/network index 72557b8..4333500 100644 --- a/mk/rootfs/openrc/etc/init.d/network +++ b/mk/rootfs/openrc/etc/init.d/network @@ -10,6 +10,7 @@ __nl=" depend() { + need localmount if [ -n "$(interfaces)" ]; then provide net fi @@ -67,7 +68,7 @@ tentative() case "$RC_UNAME" in Linux) [ -x /sbin/ip ] || [ -x /bin/ip ] || return 1 - [ -n "$(ip -f inet6 addr show tentative)" ] + [ -n "$(ip -f inet6 addr show tentative 2>/dev/null)" ] ;; *) local inet= address= rest= diff --git a/mk/rootfs/openrc/etc/init.d/procfs b/mk/rootfs/openrc/etc/init.d/procfs index 8837750..be016d9 100644 --- a/mk/rootfs/openrc/etc/init.d/procfs +++ b/mk/rootfs/openrc/etc/init.d/procfs @@ -7,6 +7,7 @@ description="Mounts misc filesystems in /proc." depend() { use modules devfs + need localmount } start() diff --git a/mk/rootfs/openrc/etc/init.d/swap b/mk/rootfs/openrc/etc/init.d/swap new file mode 100644 index 0000000..caff097 --- /dev/null +++ b/mk/rootfs/openrc/etc/init.d/swap @@ -0,0 +1,30 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +start() +{ + ebegin "Activating swap devices" + case "$RC_UNAME" in + Linux) swapon -a >/dev/null;; + NetBSD|OpenBSD) swapctl -A -t noblk >/dev/null;; + *) swapon -a >/dev/null;; + esac + eend 0 # If swapon has nothing todo it errors, so always return 0 +} + +stop() +{ + ebegin "Deactivating swap devices" + + # Try to unmount all tmpfs filesystems not in use, else a deadlock may + # occur. As $RC_SVCDIR may also be tmpfs we cd to it to lock it + cd "$RC_SVCDIR" + umount -a -t tmpfs 2>/dev/null + + case "$RC_UNAME" in + NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;; + *) swapoff -a >/dev/null;; + esac + eend 0 +} diff --git a/mk/rootfs/openrc/etc/init.d/urandom b/mk/rootfs/openrc/etc/init.d/urandom index edd645d..1498cc2 100644 --- a/mk/rootfs/openrc/etc/init.d/urandom +++ b/mk/rootfs/openrc/etc/init.d/urandom @@ -5,6 +5,11 @@ : ${urandom_seed:=${URANDOM_SEED:-/etc/random-seed}} description="Initializes the random number generator." +depend() +{ + need localmount +} + save_seed() { local psz=1 diff --git a/mk/rootfs/openrc/openrc.mk b/mk/rootfs/openrc/openrc.mk index bc2a80f..d14b27e 100644 --- a/mk/rootfs/openrc/openrc.mk +++ b/mk/rootfs/openrc/openrc.mk @@ -34,8 +34,8 @@ embtk_openrc_mk := $(EMBTK_ROOT)/mk/rootfs/openrc # sysinit runlevel scripts embtk_openrc_sysinit := devfs dmesg sysfs # boot runlevel scripts -embtk_openrc_boot := hostname loopback modules mtab network procfs -embtk_openrc_boot += root staticroute sysctl urandom +embtk_openrc_boot := hostname localmount loopback modules mtab network +embtk_openrc_boot += procfs root staticroute swap sysctl urandom # defaultrunlevel scripts embtk_openrc_default := netmount # shutdown runlevel scripts |