diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-11-12 06:18:48 +0100 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-11-15 01:11:09 +0100 |
commit | fe5d6c51c4ace947060fe49914d8224c836a31e4 (patch) | |
tree | 36b6795d3d2a9ba687f1963e8c6e6f66cd3dbdb5 | |
parent | a684ee7ccade5d996e23dd635efc0ec8886fd5f8 (diff) | |
download | mkinitcpio-fe5d6c51c4ace947060fe49914d8224c836a31e4.tar.gz mkinitcpio-fe5d6c51c4ace947060fe49914d8224c836a31e4.tar.xz |
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 <dreisner@archlinux.org>
-rw-r--r-- | init_functions | 22 |
1 files 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 |