forked from ungleich-public/cdist
can generate initramfs from busybox
Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
This commit is contained in:
parent
f51a444012
commit
7ba6c0a44a
10 changed files with 119 additions and 29 deletions
60
hacking/v3-busybox/init
Normal file
60
hacking/v3-busybox/init
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/sh
|
||||
|
||||
#Mount things needed by this script
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
|
||||
#Disable kernel messages from popping onto the screen
|
||||
echo 0 > /proc/sys/kernel/printk
|
||||
|
||||
#Create all the symlinks to /bin/busybox
|
||||
busybox --install -s
|
||||
|
||||
#Create device nodes
|
||||
mknod /dev/null c 1 3
|
||||
mknod /dev/tty c 5 0
|
||||
mdev -s
|
||||
|
||||
#Function for parsing command line options with "=" in them
|
||||
# get_opt("init=/sbin/init") will return "/sbin/init"
|
||||
get_opt() {
|
||||
echo "$@" | cut -d "=" -f 2
|
||||
}
|
||||
|
||||
#Defaults
|
||||
init="/sbin/init"
|
||||
root="/dev/hda1"
|
||||
|
||||
#Process command line options
|
||||
for i in $(cat /proc/cmdline); do
|
||||
case $i in
|
||||
root\=*)
|
||||
root=$(get_opt $i)
|
||||
;;
|
||||
init\=*)
|
||||
init=$(get_opt $i)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
exec sh
|
||||
|
||||
# Skipping the rest
|
||||
|
||||
#Mount the root device
|
||||
mount "${root}" /newroot
|
||||
|
||||
#Check if $init exists and is executable
|
||||
if [[ -x "/newroot/${init}" ]] ; then
|
||||
#Unmount all other mounts so that the ram used by
|
||||
#the initramfs can be cleared after switch_root
|
||||
umount /sys /proc
|
||||
|
||||
#Switch to the new root and execute init
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue