From fe5d6c51c4ace947060fe49914d8224c836a31e4 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 12 Nov 2011 00:18:48 -0500 Subject: init_functions: resolve M:m to device file Rather than immediately defaulting to /dev/root, attempt to resolve the major/minor pair back to a block device. If we can't do this properly, then fallback to /dev/root. Signed-off-by: Dave Reisner --- init_functions | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/init_functions b/init_functions index d3e6292..eb8b918 100644 --- a/init_functions +++ b/init_functions @@ -31,6 +31,19 @@ launch_interactive_shell() { sh -i } +major_minor_to_device() { + local dev + + [ -e "/sys/dev/block/$1:$2" ] || return 1 + + if dev=$(readlink -f "/sys/dev/block/$1:$2" 2>/dev/null); then + echo "/dev/${dev##*/}" + return 0 + fi + + return 1 +} + parse_cmdline() { local w in_quotes lhs rhs in_quotes=0 @@ -109,9 +122,12 @@ resolve_device() { esac if [ -n "$major" -a -n "$minor" ]; then - device=/dev/root - msg "Creating device node with major $major and minor $minor." >&2 - mknod "$device" b "$major" "$minor" + device=$(major_minor_to_device "$major" "$minor" || echo '/dev/root') + + if [ ! -b "$device" ]; then + msg "Creating device node with major $major and minor $minor." >&2 + mknod "$device" b "$major" "$minor" + fi echo "$device" return 0 fi -- cgit v1.2.3-24-g4f1b