From 9f85179b7fd706ddc9b5386dfae3514f16ca26f9 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 5 Jan 2010 23:56:23 +0100 Subject: Start moving from klibc to glibc+busybox Remove klibc-isms from base and init (except kinit, which will be done in a later commit) Install busybox to the initramfs and change /init so it can be used with busybox --- init | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'init') diff --git a/init b/init index 8885b39..e77a0dc 100644 --- a/init +++ b/init @@ -1,11 +1,13 @@ -#!/bin/sh +#!/bin/busybox ash +# Mount /proc so busybox can access /proc/self/exe +/bin/busybox mount -t proc proc /proc +# Install busybox's applets as symlinks +/bin/busybox --install -s . /init_functions msg ":: Loading Initramfs" - /bin/mount -t sysfs none /sys -/bin/mount -t proc none /proc read CMDLINE Date: Sun, 10 Jan 2010 17:25:22 +0100 Subject: Do not mount /proc before busybox --install - this requires CONFIG_BUSYBOX_EXEC_PATH="/bin/busybox" in busybox --- init | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'init') diff --git a/init b/init index e77a0dc..c70d309 100644 --- a/init +++ b/init @@ -1,13 +1,12 @@ #!/bin/busybox ash -# Mount /proc so busybox can access /proc/self/exe -/bin/busybox mount -t proc proc /proc # Install busybox's applets as symlinks /bin/busybox --install -s . /init_functions msg ":: Loading Initramfs" -/bin/mount -t sysfs none /sys +/bin/mount -t proc proc /proc +/bin/mount -t sysfs sys /sys read CMDLINE Date: Sun, 10 Jan 2010 17:33:10 +0100 Subject: Remove kinit usage from /init: Implement parseblock and kinit in shell code, use busybox/switch_root for the final step. TODO: NFS --- init | 91 +++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 36 deletions(-) (limited to 'init') diff --git a/init b/init index c70d309..892e7fd 100644 --- a/init +++ b/init @@ -11,9 +11,8 @@ msg ":: Loading Initramfs" read CMDLINE /proc/sys/kernel/modprobe # if available, start udevd at this stage @@ -31,8 +30,6 @@ for cmd in ${CMDLINE}; do [0123456Ss]) ;; [0-9]*) ;; single) ;; - #Allow "init=X" to pass-through - init=*) kinit_params="${kinit_params} ${cmd}" ;; # only export stuff that does work with dash :) *=*) cmd="$(replace -s= "${cmd}" '.' '_')" cmd="$(replace -s= "${cmd}" '-' '_')" @@ -77,8 +74,6 @@ done if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then export rootdelay=10 fi -# We'll wait for the root device, so make sure klibc doesn't -export kinit_params="${kinit_params} rootdelay=0" if [ -e "/hooks" ]; then for h in ${HOOKS}; do @@ -100,38 +95,9 @@ if [ "${break}" = "y" ]; then PS1="ramfs$ " /bin/sh -i fi -# If we boot from NFS, don't check for a block device in /dev -# Let kinit do it all -if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then - if ! poll_device "${root}" ${rootdelay}; then - msg "\nRoot device '${root}' doesn't exist, attempting to create it" - - eval $(/bin/parseblock "${root}") - if [ -z "${BLOCKDEVICE}" ]; then - echo "ERROR: Failed to parse block device ids for '${root}'" - else - echo "/bin/mknod /dev/root b ${BLOCKDEVICE}" - /bin/mknod /dev/root b ${BLOCKDEVICE} >/dev/null - export root="/dev/root" - fi - if [ ! -b "${root}" -a ! -h "${root}" ]; then - err "Unable to detect or create root device '${root}'" - echo "You are being dropped to a recovery shell" - echo " Type 'reboot' to reboot" - echo " Type 'exit' to try and continue booting" - echo "" - echo "If the device '${root}' gets created while you are here," - echo "try adding 'rootdelay=10' or higher to the kernel command-line" - PS1="ramfs$ " /bin/sh -i - msg "Trying to continue (this will most likely fail)..." - fi - fi -fi - if [ -f "/message" ]; then msg "$(cat /message)" fi -msg ":: Initramfs Completed - control passing to kinit" #Special handling if udev is running udevpid=$(/bin/minips -C udevd -o pid=) @@ -140,4 +106,57 @@ if [ -n "${udevpid}" ]; then /bin/sleep 0.01 fi -exec /bin/kinit "$@" -- "root=${root}" ${kinit_params} > /dev/null 2>&1 +mkdir -p /new_root +if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then + if [ ${root:0:5} != "/dev/" ] || ! poll_device "${root}" ${rootdelay}; then + msg "\nRoot device '${root}' doesn't exist. Attempting to create it." + rootdev="" + if [ ${root:0:5} = "/dev/" ]; then + # It might be a block device (/dev/sda) + if [ -f /sys/block/${root:5}/dev ]; then + rootdev="$(cat /sys/block/${root:5}/dev | sed 's|:| |')" + # It might be a partition on any block device (/dev/sda1) + else + for dir in /sys/block/*; do + if [ -f ${dir}/${root:5}/dev ]; then + rootdev="$(cat /sys/block/${dir}/${root:5}/dev | sed 's|:| |')" + break + fi + done + fi + # It might be a major/minor pair (8:1) + elif echo ${root} | grep -q :; then + rootdev="$(echo ${root} | sed 's|:| |')" + root="/dev/root" + # It might be major/minor encoded as a single hex-number (lilo-style) (801) + elif [ ${#root} -le 4 -a ${#root} -gt 2 ] && echo "${root}" | grep -qe '^[A-Fa-f0-9]*$'; then + str_offset=$((${#root}-2)) + major=$(printf "%d" 0x${root:0:${str_offset}}) + minor=$(printf "%d" 0x${root:${str_offset}}) + rootdev="${major} ${minor}" + root="/dev/root" + fi + if [ -n "${rootdev}" ]; then + msg "Creating root device ${root} with major $(echo "${rootdev}" | cut -d\ -f1) and minor $(echo "${rootdev}" | cut -d\ -f2)." + mknod ${root} b ${rootdev} + else + err "Unable to determine major/minor number of root device '${root}'." + echo "You are being dropped to a recovery shell" + echo " Type 'reboot' to reboot" + echo " Type 'exit' to try and continue booting" + PS1="ramfs$ " /bin/sh -i + msg "Trying to continue (this will most likely fail) ..." + fi + fi + # We didn't build filesystem support into busybox, + # instead we use util-linux-ng's blkid for best compatibility + fstype=$(eval $(/sbin/blkid -o udev -p "${root}"); echo $ID_FS_TYPE) + mount ${fstype:+-t ${fstype}} -o ro "${root}" /new_root +else + # TODO: Actually implement this + err "Mounting NFS root is not implemented yet." +fi +umount /proc +umount /sys +[ -z "${init}" ] && init="/sbin/init" +exec /sbin/switch_root -c /dev/console /new_root ${init} "$@" -- cgit v1.2.3-24-g4f1b From cd0973a87d41a7a90808024861aff1af4d4d3096 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 12 Jan 2010 21:18:57 +0100 Subject: Replace the custom 'replace' tool with 'sed' --- init | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'init') diff --git a/init b/init index 892e7fd..aa46c48 100644 --- a/init +++ b/init @@ -30,32 +30,33 @@ for cmd in ${CMDLINE}; do [0123456Ss]) ;; [0-9]*) ;; single) ;; - # only export stuff that does work with dash :) - *=*) cmd="$(replace -s= "${cmd}" '.' '_')" - cmd="$(replace -s= "${cmd}" '-' '_')" - export "${cmd}" + # only export stuff that does work with ash :) + *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)" + cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|.|_|g')" + cmd="$(echo "${cmd}" | sed 's|-|_|g')=${rhs}" + (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}" + ;; + *) cmd="$(echo "${cmd}" | sed 's|.|_|g')" + cmd="$(echo "${cmd}" | sed 's|-|_|g')" + (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}=y" ;; - *) cmd="$(replace "${cmd}" '.' '_')" - cmd="$(replace "${cmd}" '-' '_')" - export "${cmd}=y" - ;; esac done if [ -n "${disablehooks}" ]; then - for d in $(replace "${disablehooks}" ','); do + for d in $(echo "${disablehooks}" | sed 's|,| |g'); do export "hook_${d}=disabled" done fi if [ -n "${disablemodules}" ]; then - for d in $(replace "${disablemodules}" ','); do + for d in $(echo "${disablemodules}" | sed 's|,| |g'); do export "mod_${d}=disabled" done fi if [ -n "${earlymodules}" ]; then - for m in $(replace "${earlymodules}" ','); do + for m in $(echo "${earlymodules}" | sed 's|,| |g'); do /sbin/modprobe -q ${m} > /dev/null 2>&1 done fi -- cgit v1.2.3-24-g4f1b From 9ca9d2fbf0af1f37678fb9835045141ac0cfc049 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 12 Jan 2010 21:26:45 +0100 Subject: Fix a small oops in the sed usage --- init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init') diff --git a/init b/init index aa46c48..94db351 100644 --- a/init +++ b/init @@ -32,11 +32,11 @@ for cmd in ${CMDLINE}; do single) ;; # only export stuff that does work with ash :) *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)" - cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|.|_|g')" + cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')" cmd="$(echo "${cmd}" | sed 's|-|_|g')=${rhs}" (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}" ;; - *) cmd="$(echo "${cmd}" | sed 's|.|_|g')" + *) cmd="$(echo "${cmd}" | sed 's|\.|_|g')" cmd="$(echo "${cmd}" | sed 's|-|_|g')" (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}=y" ;; -- cgit v1.2.3-24-g4f1b From 2538c6ce3382a394524d8a0f6a545f1a9f86ddbf Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 12 Jan 2010 21:31:52 +0100 Subject: Replace custom minips with busybox pidof --- init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index 94db351..4904d12 100644 --- a/init +++ b/init @@ -101,7 +101,7 @@ if [ -f "/message" ]; then fi #Special handling if udev is running -udevpid=$(/bin/minips -C udevd -o pid=) +udevpid=$(/bin/pidof udevd) if [ -n "${udevpid}" ]; then /bin/kill -9 ${udevpid} > /dev/null 2>&1 /bin/sleep 0.01 -- cgit v1.2.3-24-g4f1b From 7504fd6be397ac154ecd61ffab7b9fbafddc4a0c Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Fri, 29 Jan 2010 19:56:50 +0100 Subject: Nicer shell prompt in the break/emergency shell --- init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init') diff --git a/init b/init index 4904d12..6064f14 100644 --- a/init +++ b/init @@ -93,7 +93,7 @@ fi if [ "${break}" = "y" ]; then echo ":: Break requested, type 'exit' to resume operation" - PS1="ramfs$ " /bin/sh -i + launch_interactive_shell fi if [ -f "/message" ]; then @@ -145,7 +145,7 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then echo "You are being dropped to a recovery shell" echo " Type 'reboot' to reboot" echo " Type 'exit' to try and continue booting" - PS1="ramfs$ " /bin/sh -i + launch_interactive_shell msg "Trying to continue (this will most likely fail) ..." fi fi -- cgit v1.2.3-24-g4f1b From af47b16bdc76608b7edb17fa6b80c18e53c775ec Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Fri, 5 Feb 2010 23:38:28 +0100 Subject: Respect rootfstype command line parameter --- init | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index 6064f14..508c473 100644 --- a/init +++ b/init @@ -151,7 +151,11 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then fi # We didn't build filesystem support into busybox, # instead we use util-linux-ng's blkid for best compatibility - fstype=$(eval $(/sbin/blkid -o udev -p "${root}"); echo $ID_FS_TYPE) + if [ -n "${rootfstype}" ]; then + fstype="${rootfstype}" + else + fstype=$(eval $(/sbin/blkid -o udev -p "${root}"); echo $ID_FS_TYPE) + fi mount ${fstype:+-t ${fstype}} -o ro "${root}" /new_root else # TODO: Actually implement this -- cgit v1.2.3-24-g4f1b From 3c6a2fab7e5a347d92bba152dca367fcbfabc3a6 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Sun, 7 Feb 2010 10:55:34 +0100 Subject: Settle remaining uevents before killing udevd --- init | 2 ++ 1 file changed, 2 insertions(+) (limited to 'init') diff --git a/init b/init index 508c473..cfa6c75 100644 --- a/init +++ b/init @@ -103,6 +103,8 @@ fi #Special handling if udev is running udevpid=$(/bin/pidof udevd) if [ -n "${udevpid}" ]; then + # Settle pending uevents, then kill udev + /sbin/udevadm settle /bin/kill -9 ${udevpid} > /dev/null 2>&1 /bin/sleep 0.01 fi -- cgit v1.2.3-24-g4f1b From ba97db07a5bcbc5c0db2241a2f8ac4117d05c8f3 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Sun, 7 Feb 2010 21:57:45 +0100 Subject: Honor the rootflags= command line option This fixes FS#18213. --- init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index cfa6c75..6a78965 100644 --- a/init +++ b/init @@ -158,7 +158,7 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then else fstype=$(eval $(/sbin/blkid -o udev -p "${root}"); echo $ID_FS_TYPE) fi - mount ${fstype:+-t ${fstype}} -o ro "${root}" /new_root + mount ${fstype:+-t ${fstype}} -o ro${rootflags:+,${rootflags}} "${root}" /new_root else # TODO: Actually implement this err "Mounting NFS root is not implemented yet." -- cgit v1.2.3-24-g4f1b From d677a731301297c7bf4ffbe9c6735169150c4d4b Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Sun, 7 Feb 2010 22:10:27 +0100 Subject: udev: Do not try to resolve any group/user names There is no nss library or user/group database in initramfs, so tell udev to not try to resolve any names --- init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index 6a78965..823355c 100644 --- a/init +++ b/init @@ -19,7 +19,7 @@ echo "/sbin/modprobe" > /proc/sys/kernel/modprobe if [ -x /sbin/udevd ]; then msg ":: Starting udevd..." echo > /proc/sys/kernel/hotplug - /sbin/udevd --daemon + /sbin/udevd --daemon --resolve-names=never msg "done." fi -- cgit v1.2.3-24-g4f1b From 7d99fdb862b10e9019e5be78ad7afb6c1ae7f8c0 Mon Sep 17 00:00:00 2001 From: Gerardo Exequiel Pozzi Date: Mon, 8 Feb 2010 22:56:17 -0300 Subject: Fix path when looking at /sys/block for rootdev otherwise will access to /sys/block//sys/block/sda/sda1/dev (for example) Signed-off-by: Gerardo Exequiel Pozzi --- init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index 823355c..88cefc1 100644 --- a/init +++ b/init @@ -122,7 +122,7 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then else for dir in /sys/block/*; do if [ -f ${dir}/${root:5}/dev ]; then - rootdev="$(cat /sys/block/${dir}/${root:5}/dev | sed 's|:| |')" + rootdev="$(cat ${dir}/${root:5}/dev | sed 's|:| |')" break fi done -- cgit v1.2.3-24-g4f1b From 82e9837b9661ead8f78023ef645c7b6679786739 Mon Sep 17 00:00:00 2001 From: Simon Boulay Date: Mon, 8 Feb 2010 19:44:53 +0100 Subject: Add support for mounting root filesystem over NFS. --- init | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'init') diff --git a/init b/init index 88cefc1..05ec3d5 100644 --- a/init +++ b/init @@ -160,8 +160,15 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then fi mount ${fstype:+-t ${fstype}} -o ro${rootflags:+,${rootflags}} "${root}" /new_root else - # TODO: Actually implement this - err "Mounting NFS root is not implemented yet." + if [ -z "$nfs_server" -o -z "$nfs_path" ]; then + err "Unable to mount root filesystem over NFS: wrong parameters." + echo "You are being dropped to a recovery shell" + echo " Type 'reboot' to reboot" + echo " Type 'exit' to try and continue booting" + launch_interactive_shell + msg "Trying to continue (this will most likely fail) ..." + fi + nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" /new_root fi umount /proc umount /sys -- cgit v1.2.3-24-g4f1b From b4e4b6f268a293b3093f43afafe005cfccae24ca Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 9 Feb 2010 20:32:43 +0100 Subject: Remove the comment about 'reboot': busybox reboot requires init to run, thus typing reboot is ineffective --- init | 2 -- 1 file changed, 2 deletions(-) (limited to 'init') diff --git a/init b/init index 05ec3d5..cf55e51 100644 --- a/init +++ b/init @@ -145,7 +145,6 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then else err "Unable to determine major/minor number of root device '${root}'." echo "You are being dropped to a recovery shell" - echo " Type 'reboot' to reboot" echo " Type 'exit' to try and continue booting" launch_interactive_shell msg "Trying to continue (this will most likely fail) ..." @@ -163,7 +162,6 @@ else if [ -z "$nfs_server" -o -z "$nfs_path" ]; then err "Unable to mount root filesystem over NFS: wrong parameters." echo "You are being dropped to a recovery shell" - echo " Type 'reboot' to reboot" echo " Type 'exit' to try and continue booting" launch_interactive_shell msg "Trying to continue (this will most likely fail) ..." -- cgit v1.2.3-24-g4f1b From 2cc35c56773bc0ee06d32622dd2254f03e52a867 Mon Sep 17 00:00:00 2001 From: Thomas Bächler Date: Tue, 9 Feb 2010 20:37:38 +0100 Subject: Honor the "rw" command line flag, but still make "ro" the default if nothing is specified --- init | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'init') diff --git a/init b/init index cf55e51..7d4b226 100644 --- a/init +++ b/init @@ -30,6 +30,8 @@ for cmd in ${CMDLINE}; do [0123456Ss]) ;; [0-9]*) ;; single) ;; + rw) readwrite="yes" ;; + ro) readwrite="no" ;; # only export stuff that does work with ash :) *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)" cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')" @@ -157,7 +159,12 @@ if [ -z "${nfsroot}" -a "${root}" != "/dev/nfs" ]; then else fstype=$(eval $(/sbin/blkid -o udev -p "${root}"); echo $ID_FS_TYPE) fi - mount ${fstype:+-t ${fstype}} -o ro${rootflags:+,${rootflags}} "${root}" /new_root + if [ "${readwrite}" = "yes" ]; then + rwopt="rw" + else + rwopt="ro" + fi + mount ${fstype:+-t ${fstype}} -o ${rwopt}${rootflags:+,${rootflags}} "${root}" /new_root else if [ -z "$nfs_server" -o -z "$nfs_path" ]; then err "Unable to mount root filesystem over NFS: wrong parameters." -- cgit v1.2.3-24-g4f1b