aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-08-24 12:15:48 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-08-24 12:15:48 +0000
commit0a85b3309e856b318cc9cdd2391dfbcd465a7ea4 (patch)
treefc60df505fd5181f66cad4a60a32794031eafbac
parentae6b3c68511bdb688085ad3e4074abf52a57198d (diff)
downloadmkinitfs-0a85b3309e856b318cc9cdd2391dfbcd465a7ea4.tar.bz2
mkinitfs-0a85b3309e856b318cc9cdd2391dfbcd465a7ea4.tar.xz
init: find UUID=, LABEL= and symlinked devices in fstabs
Remount devices to match fstab if found
-rwxr-xr-xinitramfs-init.in75
1 files changed, 57 insertions, 18 deletions
diff --git a/initramfs-init.in b/initramfs-init.in
index 2ff2585..f64ef26 100755
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -104,10 +104,32 @@ unpack_apkovl() {
}
# find mount dir for given device in an fstab
+# returns global MNTOPTS
find_mnt() {
- local dev="$1"
- local fsfile="$2"
- awk "\$1 == \"$dev\" {print \$2}\"" "$fsfile" 2>/dev/null
+ local search_dev="$1" fstab="$2"
+ MNTOPTS=
+ [ -r "$fstab" ] || return 1
+ local dev mnt fs chk
+ case "$search_dev" in
+ UUID=*|LABEL=*|/dev/*);;
+ *) 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
+ MNTOPTS=
}
# Wait for usb to settle
@@ -214,6 +236,29 @@ start_lvm() {
lvm vgchange --ignorelockingfailure -a y >/dev/null 2>&1
}
+# resolve an uuid or symlink to the real device
+resolve_dev() {
+ case "$1" in
+ UUID=*|LABEL=*) findfs "$1";;
+ *) readlink -f "$1";;
+ esac
+}
+
+# remount ALPINE_MNT according given fstab
+remount_alpine_mnt() {
+ local fstab="$1"
+ local mnt=$(find_mnt $ALPINE_DEV $fstab)
+ if [ "$ALPINE_MNT" != "$mnt" ]; then
+ mkdir -p "$mnt"
+ mount -o move $ALPINE_MNT $mnt
+ ALPINE_MNT=$mnt
+ fi
+ # respect users mount options in fstab
+ if [ -n "$MNTOPTS" ]; then
+ mount -o remount,$MNTOPTS "$ALPINE_MNT"
+ fi
+}
+
# gotta start from somewhere :)
echo "Alpine Init $VERSION"
@@ -270,7 +315,7 @@ if [ -n "$KOPT_ovl_dev" ] ; then
fi
case "$ALPINE_DEV" in
- UUID=*) ;;
+ UUID=*|LABEL=*) ;;
*) ALPINE_DEV=/dev/$ALPINE_DEV ;;
esac
@@ -453,20 +498,9 @@ pkgs="$pkgs alpine-base"
# move the ALPINE_MNT if ALPINE_DEV is specified in users fstab
# this is so a generated /etc/apk/repositories will use correct mount dir
-new_mnt=$(find_mnt $ALPINE_DEV $sysroot/etc/fstab)
-if [ -n "$new_mnt" ] && [ "$new_mnt" != "$ALPINE_MNT" ]; then
- mkdir -p $new_mnt
- mount -o move $ALPINE_MNT $new_mnt
- ALPINE_MNT="$new_mnt"
-fi
-
-# let user set ALPINE_MNT as readonly in fstab
-if [ -f $sysroot/etc/fstab ]; then
- mountopts=$(awk "\$2 == \"$ALPINE_MNT\" { print \$4 }" \
- $sysroot/etc/fstab)
- if [ -n "$mountopts" ]; then
- mount -o remount,$mountopts $ALPINE_MNT
- fi
+if [ -f "$sysroot"/etc/fstab ]; then
+ has_fstab=1
+ remount_alpine_mnt "$sysroot"/etc/fstab
fi
# copy keys so apk finds them. apk looks for stuff relative --root
@@ -503,6 +537,11 @@ else
fi
eend $?
+# remount ALPINE_MNT according default fstab from package
+if [ -z "$has_fstab" ] && [ -f "$sysroot"/etc/fstab ]; then
+ remount_alpine_mnt "$sysroot"/etc/fstab
+fi
+
# fix inittab if alternative console
setup_inittab_console $CONSOLE