summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinit40
-rw-r--r--scripts/functions40
2 files changed, 45 insertions, 35 deletions
diff --git a/init b/init
index f337b6a..4d49f33 100755
--- a/init
+++ b/init
@@ -71,41 +71,11 @@ for x in $(cat /proc/cmdline); do
;;
root=*)
ROOT=${x#root=}
- case $ROOT in
- LABEL=*)
- ROOT="${ROOT#LABEL=}"
-
- # support any / in LABEL= path (escape to \x2f)
- case "${ROOT}" in
- */*)
- if command -v sed >/dev/null 2>&1; then
- ROOT="$(echo ${ROOT} | sed 's,/,\\x2f,g')"
- else
- if [ "${ROOT}" != "${ROOT#/}" ]; then
- ROOT="\x2f${ROOT#/}"
- fi
- if [ "${ROOT}" != "${ROOT%/}" ]; then
- ROOT="${ROOT%/}\x2f"
- fi
- IFS='/'
- newroot=
- for s in $ROOT; do
- newroot="${newroot:+${newroot}\\x2f}${s}"
- done
- unset IFS
- ROOT="${newroot}"
- fi
- esac
- ROOT="/dev/disk/by-label/${ROOT}"
- ;;
- UUID=*)
- ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
- ;;
- /dev/nfs)
- [ -z "${BOOT}" ] && BOOT=nfs
- ;;
- esac
- ;;
+ ROOT=$(resolve_device "$ROOT")
+ if [ -z "${BOOT}" ] && [ "$ROOT" = "/dev/nfs" ]; then
+ BOOT=nfs
+ fi
+ ;;
rootflags=*)
ROOTFLAGS="-o ${x#rootflags=}"
;;
diff --git a/scripts/functions b/scripts/functions
index 81946d0..2122be6 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -457,3 +457,43 @@ read_fstab_entry() {
return $found
}
+
+# Resolve device node from a name. This expands any LABEL or UUID.
+# $1=name
+# Resolved name is echoed.
+resolve_device() {
+ DEV="$1"
+
+ case $DEV in
+ LABEL=*)
+ DEV="${DEV#LABEL=}"
+
+ # support any / in LABEL= path (escape to \x2f)
+ case "${DEV}" in
+ */*)
+ if command -v sed >/dev/null 2>&1; then
+ DEV="$(echo ${DEV} | sed 's,/,\\x2f,g')"
+ else
+ if [ "${DEV}" != "${DEV#/}" ]; then
+ DEV="\x2f${DEV#/}"
+ fi
+ if [ "${DEV}" != "${DEV%/}" ]; then
+ DEV="${DEV%/}\x2f"
+ fi
+ IFS='/'
+ newroot=
+ for s in $DEV; do
+ newroot="${newroot:+${newroot}\\x2f}${s}"
+ done
+ unset IFS
+ DEV="${newroot}"
+ fi
+ esac
+ DEV="/dev/disk/by-label/${DEV}"
+ ;;
+ UUID=*)
+ DEV="/dev/disk/by-uuid/${DEV#UUID=}"
+ ;;
+ esac
+ echo "$DEV"
+}