tinyramfs/init

54 lines
957 B
Plaintext
Raw Normal View History

2020-01-07 19:35:34 +05:30
#!/usr/bin/busybox sh
2020-01-05 23:31:39 +05:30
# debugging
set -x
# install busybox
2020-01-07 19:35:34 +05:30
/usr/bin/busybox --install -s /usr/bin
2020-01-05 23:31:39 +05:30
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
# setup mdev
2020-01-19 02:31:21 +05:30
#echo "/sbin/mdev" >/proc/sys/kernel/hotplug
2020-01-05 23:31:39 +05:30
#mdev -s
2020-01-19 02:31:21 +05:30
# setup udev
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
2020-01-05 23:31:39 +05:30
# TODO parse /proc/cmdline
# load drivers
2020-01-19 02:31:21 +05:30
#modprobe -a $drivers
2020-01-05 23:31:39 +05:30
2020-01-19 02:31:21 +05:30
# merge mount flags
2020-01-05 23:31:39 +05:30
[ -n "$rootflags" ] && mountargs="$rootflags"
[ -n "$rootfstype" ] && mountargs="$mountargs -t $rootfstype"
# mount rootfs
mount $mountargs "$root" "/mnt/root" || panic
# clean up
2020-01-19 02:31:21 +05:30
udevadm control --exit
2020-01-05 23:31:39 +05:30
umount "/dev"
umount "/sys"
umount "/proc"
# boot system
echo SUCCESS
exec switch_root "/mnt/root" "/sbin/init"