tinyramfs/init

59 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-01-27 16:39:58 +03:00
#!/sbin/busybox sh
2020-01-05 21:01:39 +03:00
# debugging
set -x
# install busybox
2020-01-27 16:39:58 +03:00
/sbin/busybox --install -s
2020-01-05 21:01:39 +03:00
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
2020-01-25 14:27:02 +03:00
# TODO implement busybox mdev/mdevd
2020-01-05 21:01:39 +03:00
# setup mdev
2020-01-25 14:27:02 +03:00
#echo /sbin/mdev >/proc/sys/kernel/hotplug
2020-01-05 21:01:39 +03:00
#mdev -s
2020-01-19 00:01:21 +03:00
# setup udev
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
2020-01-05 21:01:39 +03:00
# TODO parse /proc/cmdline
2020-01-25 14:27:02 +03:00
# 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
}
2020-01-05 21:01:39 +03:00
# load drivers
2020-01-19 00:01:21 +03:00
#modprobe -a $drivers
2020-01-05 21:01:39 +03:00
2020-01-19 00:01:21 +03:00
# merge mount flags
2020-01-25 14:27:02 +03:00
[ -n "$root_args" ] && mount_args="$root_args"
[ -n "$root_type" ] && mount_args="$mount_args -t $root_type"
2020-01-05 21:01:39 +03:00
# mount rootfs
2020-01-25 14:27:02 +03:00
mount $mount_args "$root" /mnt/root || panic
2020-01-05 21:01:39 +03:00
# clean up
2020-01-19 00:01:21 +03:00
udevadm control --exit
2020-01-25 14:27:02 +03:00
umount /dev /sys /proc
2020-01-05 21:01:39 +03:00
# boot system
echo SUCCESS
2020-01-25 14:27:02 +03:00
exec switch_root /mnt/root /sbin/init