tinyramfs/init

96 lines
2.0 KiB
Plaintext
Raw Normal View History

2020-01-27 19:09:58 +05:30
#!/sbin/busybox sh
2020-01-05 23:31:39 +05:30
# debugging
set -x
# install busybox
2020-01-27 19:09:58 +05:30
/sbin/busybox --install -s
2020-01-05 23:31:39 +05:30
panic() { echo "bruh moment :(" && sh; }
# silence is golden
2020-01-28 20:43:42 +05:30
#echo 0 >/proc/sys/kernel/printk
# TODO parse /proc/cmdline
2020-01-05 23:31:39 +05:30
# 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-28 20:43:42 +05:30
# handle device managers
if [ "$use_mdevd" = 1 ]; then
# setup mdevd
mdevd &
# trigger uevents
mdevd-coldplug
2020-01-05 23:31:39 +05:30
2020-01-28 20:43:42 +05:30
# TODO investigate this
# avoid race condition
sleep 1.5
elif [ "$use_mdev" = 1 ]; then
# setup mdev
if [ -e /proc/sys/kernel/hotplug ]; then
echo /sbin/mdev >/proc/sys/kernel/hotplug
else
uevent mdev &
fi
2020-01-19 02:31:21 +05:30
2020-01-28 20:43:42 +05:30
# trigger mdev
mdev -s
# trigger uevent for usb devices
for u in /sys/bus/usb/devices/*; do
case ${u##*/} in
[0-9]*-[0-9]*)
echo add > "$u/uevent"
;;
esac
done
# load drivers
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -ba
elif [ "$use_udev" = 1 ]; then
# setup udev
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
else
panic
fi
# TODO handle situations when LUKS on LVM
2020-01-05 23:31:39 +05:30
2020-01-25 16:57:02 +05:30
# 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-28 20:43:42 +05:30
# manually trigger LVM if udev disabled
[ "$use_lvm" = 1 ] && [ "$use_udev" = 0 ] && {
lvm vgchange --sysinit -a y
}
2020-01-05 23:31:39 +05:30
2020-01-19 02:31:21 +05:30
# merge mount flags
2020-01-25 16:57:02 +05:30
[ -n "$root_args" ] && mount_args="$root_args"
[ -n "$root_type" ] && mount_args="$mount_args -t $root_type"
2020-01-05 23:31:39 +05:30
# mount rootfs
2020-01-25 16:57:02 +05:30
mount $mount_args "$root" /mnt/root || panic
2020-01-05 23:31:39 +05:30
# clean up
2020-01-28 20:43:42 +05:30
[ "$use_mdevd" = 1 ] && killall mdevd
[ "$use_mdev" = 1 ] && { echo "" >/proc/sys/kernel/hotplug || killall uevent; }
[ "$use_udev" = 1 ] && udevadm control --exit
2020-01-25 16:57:02 +05:30
umount /dev /sys /proc
2020-01-05 23:31:39 +05:30
# boot system
echo SUCCESS
2020-01-25 16:57:02 +05:30
exec switch_root /mnt/root /sbin/init