| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
#Create all the symlinks to /bin/busybox |
| 4 |
/bin/busybox --install -s |
| 5 |
|
| 6 |
#Mount things needed by this script |
| 7 |
mount -t proc proc /proc |
| 8 |
mount -t sysfs sysfs /sys |
| 9 |
|
| 10 |
#Disable kernel messages from popping onto the screen |
| 11 |
echo 0 > /proc/sys/kernel/printk |
| 12 |
|
| 13 |
|
| 14 |
#Create device nodes |
| 15 |
mknod /dev/null c 1 3 |
| 16 |
mknod /dev/tty c 5 0 |
| 17 |
mdev -s |
| 18 |
|
| 19 |
#Function for parsing command line options with "=" in them |
| 20 |
# get_opt("init=/sbin/init") will return "/sbin/init" |
| 21 |
get_opt() { |
| 22 |
echo "$@" | cut -d "=" -f 2 |
| 23 |
} |
| 24 |
|
| 25 |
#Defaults |
| 26 |
init="/sbin/init" |
| 27 |
root="/dev/hda1" |
| 28 |
|
| 29 |
#Process command line options |
| 30 |
for i in $(cat /proc/cmdline); do |
| 31 |
case $i in |
| 32 |
root\=*) |
| 33 |
root=$(get_opt $i) |
| 34 |
;; |
| 35 |
init\=*) |
| 36 |
init=$(get_opt $i) |
| 37 |
;; |
| 38 |
esac |
| 39 |
done |
| 40 |
|
| 41 |
|
| 42 |
exec sh |
| 43 |
|
| 44 |
# Skipping the rest |
| 45 |
|
| 46 |
#Mount the root device |
| 47 |
mount "${root}" /newroot |
| 48 |
|
| 49 |
#Check if $init exists and is executable |
| 50 |
if [[ -x "/newroot/${init}" ]] ; then |
| 51 |
#Unmount all other mounts so that the ram used by |
| 52 |
#the initramfs can be cleared after switch_root |
| 53 |
umount /sys /proc |
| 54 |
|
| 55 |
#Switch to the new root and execute init |
| 56 |
exec switch_root /newroot "${init}" |
| 57 |
fi |
| 58 |
|
| 59 |
#This will only be run if the exec above failed |
| 60 |
echo "Failed to switch_root, dropping to a shell" |
| 61 |
exec sh |