tinyramfs/init

54 lines
957 B
Plaintext
Raw Normal View History

2020-01-07 17:05:34 +03:00
#!/usr/bin/busybox sh
2020-01-05 21:01:39 +03:00
# debugging
set -x
# install busybox
2020-01-07 17:05:34 +03:00
/usr/bin/busybox --install -s /usr/bin
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
# setup mdev
2020-01-19 00:01:21 +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
# 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-05 21:01:39 +03:00
[ -n "$rootflags" ] && mountargs="$rootflags"
[ -n "$rootfstype" ] && mountargs="$mountargs -t $rootfstype"
# mount rootfs
mount $mountargs "$root" "/mnt/root" || panic
# clean up
2020-01-19 00:01:21 +03:00
udevadm control --exit
2020-01-05 21:01:39 +03:00
umount "/dev"
umount "/sys"
umount "/proc"
# boot system
echo SUCCESS
exec switch_root "/mnt/root" "/sbin/init"