cleanup init

This commit is contained in:
illiliti 2020-02-02 15:37:14 +03:00
parent 1953b1760c
commit 5df6801525

32
init
View File

@ -10,15 +10,16 @@ panic() {
# TODO parse /proc/cmdline # TODO parse /proc/cmdline
#} #}
mnt_pseudofs() {
# mount pseudofs's # mount pseudofs's
mnt_pseudofs() {
mount -t proc none /proc mount -t proc none /proc
mount -t sysfs none /sys mount -t sysfs none /sys
mount -t devtmpfs none /dev mount -t devtmpfs none /dev
} }
use_mdev() {
# setup mdev # setup mdev
use_mdev() {
# setup hotplugger
if [ -e /proc/sys/kernel/hotplug ]; then if [ -e /proc/sys/kernel/hotplug ]; then
printf /sbin/mdev >/proc/sys/kernel/hotplug printf /sbin/mdev >/proc/sys/kernel/hotplug
else else
@ -41,8 +42,9 @@ use_mdev() {
find /sys -name "modalias" -type f -exec cat "{}" + | sort -u | xargs modprobe -ba find /sys -name "modalias" -type f -exec cat "{}" + | sort -u | xargs modprobe -ba
} }
use_mdevd() {
# setup mdevd # setup mdevd
use_mdevd() {
# setup daemon
mdevd & mdevd &
# trigger uevents # trigger uevents
mdevd-coldplug mdevd-coldplug
@ -52,15 +54,17 @@ use_mdevd() {
sleep 1.5 sleep 1.5
} }
use_udev() {
# setup udev # setup udev
use_udev() {
udevd --daemon udevd --daemon
udevadm trigger --action=add --type=subsystems udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices udevadm trigger --action=add --type=devices
udevadm settle udevadm settle
} }
# unlock LUKS container
unlock_luks() { unlock_luks() {
# TODO implement POSIX findfs
# find device of luks root # find device of luks root
luks_root="$(findfs $luks_root)" luks_root="$(findfs $luks_root)"
@ -69,11 +73,12 @@ unlock_luks() {
cryptsetup $luks_args luksOpen "$luks_root" luks_root || panic "failed to unlock luks container" cryptsetup $luks_args luksOpen "$luks_root" luks_root || panic "failed to unlock luks container"
} }
trigger_lvm() {
# manually trigger LVM if udev disabled # manually trigger LVM if udev disabled
trigger_lvm() {
lvm vgchange --sysinit -a y lvm vgchange --sysinit -a y
} }
# mount rootfs to /mnt/root
mnt_rootfs() { mnt_rootfs() {
# merge mount flags # merge mount flags
[ -n "$root_args" ] && mount_args="$root_args" [ -n "$root_args" ] && mount_args="$root_args"
@ -83,28 +88,29 @@ mnt_rootfs() {
mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs" mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs"
} }
# kill and unmount
cleanup() { cleanup() {
# clean up # stop mdev
[ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1 [ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
# stop mdevd
[ "$devmgr" = "mdevd" ] && killall mdevd [ "$devmgr" = "mdevd" ] && killall mdevd
# stop udev
[ "$devmgr" = "udev" ] && udevadm control --exit [ "$devmgr" = "udev" ] && udevadm control --exit
# if debug mode off then restore kernel logging
[ "$debug" = 0 ] && printf 1 >/proc/sys/kernel/printk
umount /dev /sys /proc umount /dev /sys /proc
} }
# exec /mnt/root/sbin/init
boot_system() { boot_system() {
# boot system
exec switch_root /mnt/root /sbin/init || panic "failed to boot system" exec switch_root /mnt/root /sbin/init || panic "failed to boot system"
} }
# install busybox # install busybox
/sbin/busybox --install -s /sbin/busybox --install -s
# check config # source config
if [ -e /config ]; then . /config || panic "config doesn't exists"
. /config
else
panic "config doesn't exists"
fi
if [ "$debug" = 1 ]; then if [ "$debug" = 1 ]; then
# debug shell commands # debug shell commands