#!/boot/bzImage
# Linux kernel initialization code, translated to bash
# (Minus floppy disk handling, because seriously, it's 2017.)
# Not 100% accurate, but gives you a good idea of how kernel init works
# GPLv2, Copyright 2017 Hector Martin <[email protected]>
# Based on Linux 4.10-rc2.
# Note: pretend chroot is a builtin and affects the current process
# Note: kernel actually uses major/minor device numbers instead of device name
# strings in a few places, but I simplified it by using strings
# everywhere even though that is not completely accurate.
panic() {
echo "$*"
while true; do
sleep 1
done
}
do_mount_root() {
mount -t $2 "$1" /root $rootflags || return $?
cd /root
echo "VFS: Mounted root ($2 filesystem) on device $major:$minor"
}
mount_block_root() {
if [ -z $rootfstype ]; then
rootfstype=$built_in_filesystem_types
fi
for fs in ${rootfstype//,/ }; do
do_mount_root $1 $fs
ret=$?
case $ret in
13|22) # EACCES or EINVAL
;;
*)
echo "VFS: Cannot open root device \"$root_device_name\" or $1: error $ret"
echo "Please append a correct \"root=\" boot option; here are the available partitions:"
printk_all_partitions
panic "VFS: Unable to mount root fs on $1"
esac
done
echo "List of all partitions:"
printk_all_partitions
echo "No filesystem could mount root, tried...