initramfs: respect "init=", "root=" in kernel parameters 86/33486/1
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 12 Jan 2015 07:08:38 +0000 (16:08 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 12 Jan 2015 07:15:15 +0000 (16:15 +0900)
Change-Id: Id35d3b96deefc9df2b22471b734f6cebd9c79b97
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
ramfs/init

index 5b8ed28..1a5d8fc 100644 (file)
@@ -8,6 +8,14 @@ NO_COLOR="\033[0m"
 
 NEW_ROOT="/new_root"
 
+cmdline() {
+    local value
+    value=" $(cat /proc/cmdline) "
+    value="${value##* $1=}"
+    value="${value%% *}"
+    [ "$value" != "" ] && echo "$value"
+}
+
 /bin/busybox mkdir -p /dev
 /bin/busybox mount -t devtmpfs devtmpfs /dev
 
@@ -22,14 +30,26 @@ echo -e "${COLOR_GREEN}Preparing...${NO_COLOR}"
 /bin/busybox mkdir -p /sys
 /bin/busybox mount -t sysfs sys /sys
 
+# for init...
+INIT=$(cmdline init)
+if [ -z $INIT ]; then
+    INIT="/sbin/init"
+fi
+
 # mount root...
 echo -e "${COLOR_GREEN}Mount image...${NO_COLOR}"
-/bin/busybox mount -o rw /dev/vda $NEW_ROOT
+ROOT=$(cmdline root)
+if [ -z $ROOT ]; then
+    echo -e "${COLOR_BLUE}Mount legacy image...${NO_COLOR}"
+    /bin/busybox mount -o rw /dev/vda $NEW_ROOT
+else
+    echo -e "${COLOR_BLUE}Mount ${ROOT}...${NO_COLOR}"
+    /bin/busybox mount -o rw $ROOT $NEW_ROOT
+fi
 
 # clean up...
 /bin/busybox umount /proc
 /bin/busybox umount /sys
 
-# switch root...
 echo -e "${COLOR_GREEN}Switching root...${NO_COLOR}"
-exec /bin/busybox switch_root -c /dev/console $NEW_ROOT /sbin/init
+exec /bin/busybox switch_root -c /dev/console $NEW_ROOT $INIT