2020-01-27 19:09:58 +05:30
|
|
|
#!/sbin/busybox sh
|
2020-01-30 20:10:13 +05:30
|
|
|
#
|
|
|
|
# tiny init script
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
panic() {
|
|
|
|
printf "panic >> %s\n" "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
info() {
|
|
|
|
printf "info >> %s\n" "$@"
|
|
|
|
}
|
2020-01-28 20:43:42 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
# parse_cmdline() {
|
2020-01-28 20:43:42 +05:30
|
|
|
# TODO parse /proc/cmdline
|
2020-01-30 20:10:13 +05:30
|
|
|
#}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
mnt_pseudofs() {
|
|
|
|
# mount pseudofs's
|
|
|
|
mount -t proc none /proc
|
|
|
|
mount -t sysfs none /sys
|
|
|
|
mount -t devtmpfs none /dev
|
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
use_mdev() {
|
2020-01-28 20:43:42 +05:30
|
|
|
# setup mdev
|
|
|
|
if [ -e /proc/sys/kernel/hotplug ]; then
|
2020-01-30 20:10:13 +05:30
|
|
|
printf /sbin/mdev >/proc/sys/kernel/hotplug
|
2020-01-28 20:43:42 +05:30
|
|
|
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]*)
|
2020-01-30 20:10:13 +05:30
|
|
|
printf add > "${u}/uevent"
|
2020-01-28 20:43:42 +05:30
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# load drivers
|
|
|
|
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -ba
|
2020-01-30 20:10:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
use_mdevd() {
|
|
|
|
# setup mdevd
|
|
|
|
mdevd &
|
|
|
|
# trigger uevents
|
|
|
|
mdevd-coldplug
|
|
|
|
|
|
|
|
# TODO investigate this
|
|
|
|
# avoid race condition
|
|
|
|
sleep 1.5
|
|
|
|
}
|
|
|
|
|
|
|
|
use_udev() {
|
2020-01-28 20:43:42 +05:30
|
|
|
# setup udev
|
|
|
|
udevd --daemon
|
|
|
|
udevadm trigger --action=add --type=subsystems
|
|
|
|
udevadm trigger --action=add --type=devices
|
|
|
|
udevadm settle
|
2020-01-30 20:10:13 +05:30
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
unlock_luks() {
|
|
|
|
# find device of luks root
|
2020-01-25 16:57:02 +05:30
|
|
|
luks_root="$(findfs $luks_root)"
|
2020-01-30 20:10:13 +05:30
|
|
|
|
2020-01-25 16:57:02 +05:30
|
|
|
# TODO improve mapper name ( crypttab or config option )
|
2020-01-30 20:10:13 +05:30
|
|
|
# unlock luks container
|
|
|
|
cryptsetup $luks_args luksOpen "$luks_root" luks_root || panic "failed to unlock luks container"
|
2020-01-25 16:57:02 +05:30
|
|
|
}
|
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
trigger_lvm() {
|
|
|
|
# manually trigger LVM if udev disabled
|
2020-01-28 20:43:42 +05:30
|
|
|
lvm vgchange --sysinit -a y
|
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
mnt_rootfs() {
|
|
|
|
# merge mount flags
|
|
|
|
[ -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
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
# mount rootfs
|
|
|
|
mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs"
|
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
cleanup() {
|
|
|
|
# clean up
|
|
|
|
[ "$use_mdev" = 1 ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
|
|
|
|
[ "$use_mdevd" = 1 ] && killall mdevd
|
|
|
|
[ "$use_udev" = 1 ] && udevadm control --exit
|
|
|
|
umount /dev /sys /proc
|
|
|
|
}
|
2020-01-05 23:31:39 +05:30
|
|
|
|
2020-01-30 20:10:13 +05:30
|
|
|
boot_system() {
|
|
|
|
# boot system
|
|
|
|
[ "$debug" = 1 ] && info SUCCESS
|
|
|
|
exec switch_root /mnt/root /sbin/init || panic "failed to boot system"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$debug" = 1 ]; then
|
|
|
|
# debug shell commands
|
|
|
|
set -x
|
|
|
|
else
|
|
|
|
# silence is golden
|
|
|
|
printf 0 >/proc/sys/kernel/printk
|
|
|
|
fi
|
|
|
|
|
|
|
|
# install busybox
|
|
|
|
/sbin/busybox --install -s
|
|
|
|
|
|
|
|
# check config
|
|
|
|
if [ -e /config ]; then
|
|
|
|
. /config
|
|
|
|
else
|
|
|
|
panic "config doesn't exists"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#parse_cmdline
|
|
|
|
mnt_pseudofs
|
|
|
|
case "$devmgr" in
|
|
|
|
mdev) use_mdev ;;
|
|
|
|
mdevd) use_mdevd ;;
|
|
|
|
udev) use_udev ;;
|
|
|
|
esac
|
|
|
|
# TODO handle situations when LUKS on LVM
|
|
|
|
[ "$use_luks" = 1 ] && unlock_luks
|
|
|
|
[ "$use_lvm" = 1 ] && [ "$use_udev" = 0 ] && trigger_lvm
|
|
|
|
mnt_rootfs
|
|
|
|
cleanup
|
|
|
|
boot_system
|