#!/bin/busybox sh # Mount proc and sys mount -t proc none /proc mount -t sysfs none /sys # Create basic device nodes mknod /dev/null c 1 3 mknod /dev/tty c 5 0 # Functions for parsing command line options with "=" in them # eg.: get_opt_f2("init=/sbin/init") will return "/sbin/init" get_opt_f2() { echo "$@" | cut -d "=" -f2 } get_opt_f3() { echo "$@" | cut -d "=" -f3- } # Set defaults init="/sbin/init" root="/dev/hda1" rootfstype="" waitForDevices="true" # Process command line options for i in $(cat /proc/cmdline); do case $i in root\=*) argRoot="$(get_opt_f2 $i)=$(get_opt_f3 $i)" root=$(get_opt_f3 $i) ;; init\=*) init=$(get_opt_f2 $i) ;; rootfstype\=*) rootfstype=$(get_opt_f2 $i) ;; initrdnosleep) waitForDevices="false" ;; esac done # Sleep 15s if [ "$waitForDevices" == "true" ]; then echo "initrd: Waiting 15s before mounting root, for slow init devices" sleep 15s fi # Populate the rest of the /dev mdev -s # Translate UUID/LABEL to dev if [ "$(echo $root | grep /dev/)" -eq "" ]; then echo "initrd: Given root is not an /dev, finding the real /dev..." root=$(blkid -c /dev/null | grep $root | head -n1 | awk 'BEGIN{FS=":"}{print $1}') echo "initrd: Translated '${argRoot}' to '${root}'" fi # Mount the root device if [ "${rootfstype}" != "" ]; then mount -t "${rootfstype}" "${root}" /newroot else mount "${root}" /newroot fi # Check if $init exists and is executable if [[ -x "/newroot/${init}" ]] ; then umount /proc umount /sys exec switch_root /newroot "${init}" fi # This will only be run if the exec above failed echo "!!! Failed to switch_root, dropping to a shell" exec sh