tinyramfs/init
2020-01-27 16:39:58 +03:00

59 lines
1.1 KiB
Plaintext

#!/sbin/busybox sh
# debugging
set -x
# install busybox
/sbin/busybox --install -s
panic() { echo "bruh moment :(" && sh; }
# silence is golden
#echo 0 > /proc/sys/kernel/printk
# check config
[ -f /config ] && . /config || panic
# mount pseudofs's
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
# TODO implement busybox mdev/mdevd
# setup mdev
#echo /sbin/mdev >/proc/sys/kernel/hotplug
#mdev -s
# setup udev
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
# TODO parse /proc/cmdline
# unlock cryptsetup container
[ "$use_luks" = 1 ] && {
luks_root="$(findfs $luks_root)"
# TODO improve mapper name ( crypttab or config option )
cryptsetup $luks_args luksOpen "$luks_root" luks_root || panic
}
# load drivers
#modprobe -a $drivers
# merge mount flags
[ -n "$root_args" ] && mount_args="$root_args"
[ -n "$root_type" ] && mount_args="$mount_args -t $root_type"
# mount rootfs
mount $mount_args "$root" /mnt/root || panic
# clean up
udevadm control --exit
umount /dev /sys /proc
# boot system
echo SUCCESS
exec switch_root /mnt/root /sbin/init