Last active
December 17, 2015 01:49
-
-
Save JerryFleming/5530741 to your computer and use it in GitHub Desktop.
This is a init script for initramfs/initrd which parses rootfs given by LABEL/UUID.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/busybox sh | |
# Init for initram. | |
# by Jerry Fleming <[email protected]> on 2013-03-25. | |
# No rights reserved. Use at your own risk. | |
# utility functions {{{ | |
rescue_shell() | |
{ | |
echo "Something went wrong. Dropping you to a shell." | |
echo "Please switch root manually." | |
busybox --install -s /bin | |
exec /bin/sh | |
} | |
mount_root() | |
{ | |
for cmd in $(cat /proc/cmdline) ; do | |
case $cmd in | |
root=*) | |
root=$(echo $cmd | cut -d= -f2) | |
if [ $root == "LABEL" ] || [ $root == "UUID" ] ; then | |
param=$(echo $cmd | cut -d= -f2-3) | |
root= | |
cnt=1 | |
while [ -z $root ] | |
do | |
echo "Probing rootfs ($cnt) ..." | |
cnt=$(($cnt+1)) | |
sleep 3 | |
root=$(findfs $param) | |
if [ $cnt -gt 20 ] | |
then | |
echo "Max tries reached, still can't find rootfs." | |
rescue_shell | |
fi | |
done | |
fi | |
mount -o ro $root /mnt/root || rescue_shell | |
;; | |
esac | |
done | |
} | |
# utility functions }}} | |
echo "Initializing ramfs to boot rootfs." | |
# Mount the /proc and /sys filesystems. | |
mount -t proc none /proc | |
mount -t sysfs none /sys | |
# Do your stuff here: loading disk drivers. | |
mount_root | |
# Clean up. | |
umount /proc | |
umount /sys | |
# Boot the real thing. | |
exec switch_root /mnt/root /sbin/init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment