summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-05-27 14:58:14 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-06-02 12:13:23 +0000
commita97dea93d28ba272613029e46a8a0b1f699729d8 (patch)
tree165ea42f2c45b7f0620a2acfc32bd444a69d4dab
downloadinitramfs-scripts-a97dea93d28ba272613029e46a8a0b1f699729d8.tar.gz
Add initial version of initramfs script
-rw-r--r--init107
-rw-r--r--initramfs-scripts.morph5
2 files changed, 112 insertions, 0 deletions
diff --git a/init b/init
new file mode 100644
index 0000000..fa31c0e
--- /dev/null
+++ b/init
@@ -0,0 +1,107 @@
+#!/bin/sh
+set -e
+
+# We need proc for reading the kernel command line
+mount -n -t proc none /proc
+
+set -- $(cat /proc/cmdline)
+
+# We don't want to leave mount points around
+umount /proc
+
+for arg; do
+ case "$arg" in
+ root=LABEL=*)
+ if [ x"$root_type" != x ]; then
+ echo "Warning, multiple root= specified, using latest."
+ fi
+ root_type=label
+ root="${arg#root=LABEL=}"
+ ;;
+ root=UUID=*)
+ if [ x"$root_type" != x ]; then
+ echo "Warning, multiple root= specified, using latest."
+ fi
+ root_type=uuid
+ root="${arg#root=UUID=}"
+ ;;
+ root=*)
+ if [ x"$root_type" != x ]; then
+ echo "Warning, multiple root= specified, using latest."
+ fi
+ root_type=disk
+ root="${arg#root=}"
+ ;;
+ rootflags=*)
+ if [ x"$rootflags" != x ]; then
+ echo "Warning, multiple rootflags= specified, using latest."
+ fi
+ rootflags=",${arg#rootflags=}"
+ ;;
+ rootfstype=*)
+ if [ x"$rootflags" != x ]; then
+ echo "Warning, multiple rootfstype= specified, using latest."
+ fi
+ rootfstype="${arg#rootfstype=}"
+ ;;
+ rootdelay=*)
+ if [ x"$rootflags" != x ]; then
+ echo "Warning, multiple rootdelay= specified, using latest."
+ fi
+ rootfstype="${arg#rootdelay=}"
+ ;;
+ ro)
+ ro=ro
+ ;;
+ rw)
+ ro=rw
+ ;;
+ init=*)
+ init="${arg#init=}"
+ ;;
+ esac
+done
+
+if [ x"$rootdelay" != x ]; then
+ sleep "$rootdelay"
+fi
+
+if [ x"$rootfstype" = x ]; then
+ # Warn that busybox may not be able to auto-detect rootfs type
+ cat <<\EOF
+Warning, rootfs type not specified, auto-detection of type is slow and
+may fail. Please add rootfstype=$type to kernel command line.
+EOF
+fi
+
+mount -n -t devtmpfs devtmpfs /dev
+case "$root_type" in
+disk)
+ mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$root" /mnt
+ ;;
+label)
+ disk="$(findfs LABEL="$root")"
+ if [ x"$disk" = x ]; then
+ echo disk with label $root not found
+ blkid
+ exit 1
+ fi
+ mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$disk" /mnt
+ ;;
+uuid)
+ disk="$(findfs UUID="$root")"
+ if [ x"$disk" = x ]; then
+ echo disk with UUID $root not found
+ blkid
+ exit 1
+ fi
+ mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$disk" /mnt
+ ;;
+'')
+ echo "Error, no root specified"
+ exit 1
+ ;;
+esac
+umount -n /dev
+
+exec switch_root -c /dev/console /mnt "${init-/sbin/init}"
diff --git a/initramfs-scripts.morph b/initramfs-scripts.morph
new file mode 100644
index 0000000..77bba20
--- /dev/null
+++ b/initramfs-scripts.morph
@@ -0,0 +1,5 @@
+name: initramfs-scripts
+kind: chunk
+build-system: manual
+install-commands:
+- install -m 755 init "$DESTDIR/init"