diff options
-rw-r--r-- | main/openrc/APKBUILD | 8 | ||||
-rw-r--r-- | main/openrc/modloop.initd | 147 |
2 files changed, 66 insertions, 89 deletions
diff --git a/main/openrc/APKBUILD b/main/openrc/APKBUILD index bcd561f10f..cc45966028 100644 --- a/main/openrc/APKBUILD +++ b/main/openrc/APKBUILD @@ -2,7 +2,7 @@ pkgname=openrc pkgver=0.18.3 _ver=${pkgver/_git*/} -pkgrel=0 +pkgrel=1 pkgdesc="OpenRC manages the services, startup and shutdown of a host" url="http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git" arch="all" @@ -88,7 +88,7 @@ d83df5513f08f09fa9e7353327701bf7 openrc.logrotate 887eba592d487d6ffe2b42cfcd2813df hwdrivers.initd 41974f5408fd2e92892f891b58f2e49f keymaps.initd 0ece77eff8f163b36f6f0e7a6d422866 modules.initd -a76e20fe5abea4449ed4e560a11334a4 modloop.initd +ddf2204a61d3230a3bc51a4e4f0af394 modloop.initd 27c22aa4e5cdba499ac9a0b6b9385f7d networking.initd c1ec888202d868710b5749f7b217d1e3 modloop.confd bd51c5353d6dbbb34d929bf59097b232 consolefont.initd @@ -106,7 +106,7 @@ e23db45e9399dab96d6c922af6c0cd6c243bbcc43756c845b70a9c7222a96313 hostname.initd 6cb4d9ea3ad562bcf2697f61f5a76a10481d23f5dead570f82eff576eaca5236 hwdrivers.initd 32562d39ade4092df8163c2e8cf0b31eeec06aa5713d343e1c487bfa6d9f7c84 keymaps.initd a145636e84547d76b8a188a94c0a76fcc266cd0f486be6cf24d2d74f03038118 modules.initd -61fb9e41c28f3632cc47e4ebd12fa856d0f80803aca1cd3446de3522829f308f modloop.initd +fbbcd903601dde931d25c5b9a37859b3c7289673b820865cd1f0cc8a39e3cadf modloop.initd 66151b5cc199485ddd188528a0f22f081994721f04c15b33df38f41a5d08ea78 networking.initd a5a0316cd59f5401b1d789bb466c98186201277ba6f014017b14965fcc10c254 modloop.confd 8a3f663e9ac14f62c3aef4121736a71edd676bdc9dd93c1d411f13a0e7ab4ee6 consolefont.initd @@ -124,7 +124,7 @@ a6e2b44dd548a2470971a44b61ddaaec037438050fe3411b4ea3fe5d36e9ad4cf5b5e226f8d4aacb b51d95df7b692aaea3e14ed009d99b46b82500d505e2eeecb6a20136cee140aea4a7377a65ccc5c51fff64be7a50666be48616d179888eaeff9d35178a7a772b hwdrivers.initd 584ecbbcecb284527d7616790b6e337ace610e4b3cedf2993eca294bfbef54674aeaee3078b6c17d746a0c48b5a64a813c3534136915947e6f62a6fa206cd3ca keymaps.initd 7702e2704e4bcfad7c0736eec4cb0e8b20a685851afb5bd9022c5056ea78b8598a9402bae9644ae3268e2ff1c566e147cbb8d00e143491841682e4125fde2a75 modules.initd -992fbeded59679963a8d0154415c44949c7cd9719d85190ff57b3cf9db00c1daac090e1f45580cbf446e4d8fb65d21209d529e5709eb27ea2ecc31d75245f969 modloop.initd +bf9f40a8f65816a2f4ba4856120bac31d6f21d5f0997e1dbe62864bb707466bb2a2844b0a95dee05b0580527a008465613bc923b9419d24f531a80ca8c211e4c modloop.initd 9aeba2c5cae539f16185b82c6e6e84c1b044e838749b92e8994172296d86ec3f1c674d62d54db1e08a8191e513ddb0ab3509f50ccae6cb5d7ba5ff5a5b6abb46 networking.initd aa702a7da8e6c0e5d8738febaf6b4e4cb021b30ce5c1809b530abf2b36739079446b16fc054740da8d86ed099942cf5deed6597cedb64c058f3def587a8b4689 modloop.confd c8d52d69692a00862cd55719174d7a260d5149f4951dd71196f5e9cebce3a75420a8815f0fe8b186d00b4d46739dc54542dae01a941605fcb1435f4385e444b7 consolefont.initd diff --git a/main/openrc/modloop.initd b/main/openrc/modloop.initd index 2e7331be11..6bd2e8a2f5 100644 --- a/main/openrc/modloop.initd +++ b/main/openrc/modloop.initd @@ -11,115 +11,89 @@ depend() { # read kernel options init_KOPT() { eval set -- $(cat /proc/cmdline 2>/dev/null) - # in case syslinux does not set BOOT_IMAGE - KOPT_BOOT_IMAGE="${1}" for opt; do case "$opt" in - alpine_dev=*|modloop=*|BOOT_IMAGE=*) + modloop=*) eval "KOPT_${opt%%=*}='${opt#*=}'" ;; - esac + esac done } -resolve_dev() { - case "$1" in - UUID=*|LABEL=*) findfs "$1";; - *) readlink -f "$1";; - esac +mountdirs() { + awk '$2 !~ /^\/(sys|proc|dev|run)/ && $2 != "/" {print $2}' /proc/mounts } -find_mnt() { - local search_dev="$1" fstab="$2" - local dev mnt fs mntopts chk - case "$search_dev" in - UUID=*|LABEL=*|/dev/*);; - nfs) search_dev="${KOPT_alpine_dev#nfs:}";; - *) search_dev=/dev/$search_dev;; - esac - local search_real_dev=$(resolve_dev $search_dev) - while read dev mnt fs mntopts chk; do - local real_dev=$(resolve_dev $dev) - local i j - for i in "$search_dev" "$search_real_dev"; do - [ -z "$i" ] && continue - for j in "$dev" "$real_dev"; do - [ -z "$j" ] && continue - if [ "$i" = "$j" ]; then - echo "$mnt" - return - fi - done - done - done < $fstab 2>/dev/null +find_modloop() { + local dir="$1" + local kver=$(uname -r) + local oifs="$IFS" + IFS=$'\n' + set -- $(blkid "$dir"/boot/* "$dir"/*) + IFS="$oifs" + for line; do + img=${line%%:*} + mount "$img" -o loop,ro /.modloop || continue + if [ -d /.modloop/modules/$kver ]; then + return 0 + fi + umount /.modloop + done + return 1 } -# initialies: alpine_dev, alpine_mnt, alpine_fs, alpine_mounted -find_media() { - init_KOPT - [ -z "$KOPT_alpine_dev" ] && return 0 - alpine_mounted= - alpine_dev=${KOPT_alpine_dev%%:*} - alpine_fs=${KOPT_alpine_dev#*:} - [ "$alpine_fs" = "$KOPT_alpine_dev" ] && unset alpine_fs - # first we check if alpine_dev is mounted and use this - alpine_mnt=$(find_mnt $alpine_dev /proc/mounts) - if [ -z "$alpine_mnt" ]; then - # then we check fstab - alpine_mnt=$(find_mnt $alpine_dev /etc/fstab) - else - alpine_mounted=yes +find_backing_file() { + local dir="$1" + local dev=$(df -P "$dir" | tail -1 | awk '{print $1}') + cat /sys/block/${dev#/dev/}/loop/backing_file 2>/dev/null +} + +find_alpine_mnt() { + local img="$(find_backing_file $1)" + if [ -n "$img" ]; then + df -P "$img" | tail -1 | awk '{print $6}' fi - # finally we fallback to /media/<devicename> - [ -z "$alpine_mnt" ] && alpine_mnt=/media/$alpine_dev } start() { local modloop= mount_opts= modloop_dldir="/lib" - find_media - + mkdir -p /.modloop /lib case "$KOPT_modloop" in http://*|https://|ftp://*) wget -P "$modloop_dldir" "$KOPT_modloop" \ && modloop=$modloop_dldir/$(basename $KOPT_modloop) ;; + "") + ewarn "WARNING! modloop boot option is missing." + ;; *) - if [ -z "$alpine_dev" ]; then - return 0 - fi - if [ -z "$alpine_mounted" ]; then - ebegin "Mounting $alpine_mnt" - [ -n "$alpine_fs" ] && mount_opts="-t $alpine_fs" - mount $mount_opts /dev/$alpine_dev $alpine_mnt 2>/dev/null - eend $? || return 1 - fi - - bootimagedir=${KOPT_BOOT_IMAGE%/*} - bootdir=${alpine_mnt}${bootimagedir} - kver=$(uname -r) - case $kver in - *-rc[0-9]) kflavor=vanilla;; - *-[a-z]*) kflavor=${kver##*-};; - *) kflavor=vanilla;; - esac - for modloop in ${alpine_mnt}$KOPT_modloop \ - ${bootdir}/modloop-$kver \ - ${bootdir}/modloop-$kflavor \ - ${bootdir}/modloop \ - ${alpine_mnt}/boot/modloop-$kver \ - ${alpine_mnt}/boot/modloop-$kflavor \ - ${alpine_mnt}/boot/modloop \ - ${alpine_mnt}$KOPT_BOOT_IMAGE.modloop.*; do - - [ -f "$modloop" -o -n "$KOPT_modloop" ] && break + for dir in $(mountdirs); do + if [ -f "$dir"/$KOPT_modloop ]; then + modloop="$dir/${KOPT_modloop##/}" + alpine_mnt="$dir" + break + fi done ;; esac ebegin "Mounting modloop $modloop" - mkdir -p /.modloop /lib - mount -o loop,ro $fs_opt $modloop /.modloop - eend $? || return 1 + if [ -n "$modloop" ]; then + mount -o loop,ro $modloop /.modloop + eend $? || return 1 + else + for dir in $(mountdirs); do + if find_modloop "$dir"; then + alpine_mnt="$dir" + break + fi + done + if [ -d /.modloop/modules/$(uname -r) ]; then + eend 0 + else + eend 1 || return 1 + fi + fi #use unionfs is available and configured if grep -q -w "unionfs$" /proc/filesystems && [ -n "$unionfs_size" ]; then @@ -146,14 +120,17 @@ start() { stop() { local rc=0 - find_media - [ -z "$alpine_dev" ] && return 0 + alpine_mnt=$(find_alpine_mnt /.modloop) + if mountinfo --quiet /.modunisonfs/modules && mountinfo --quiet /lib/modules; then + umount /lib/modules + umount /.modunisonfs/modules + fi if mountinfo --quiet /.modloop; then ebegin "Unmounting /.modloop" umount -d /.modloop eend $? || return 1 fi - if mountinfo --quiet $alpine_mnt; then + if [ -n "$alpine_mnt" ] && mountinfo --quiet $alpine_mnt; then ebegin "Unmounting $alpine_mnt" umount $alpine_mnt eend $? |