cleanup init
This commit is contained in:
parent
1953b1760c
commit
5df6801525
32
init
32
init
@ -10,15 +10,16 @@ panic() {
|
||||
# TODO parse /proc/cmdline
|
||||
#}
|
||||
|
||||
mnt_pseudofs() {
|
||||
# mount pseudofs's
|
||||
mnt_pseudofs() {
|
||||
mount -t proc none /proc
|
||||
mount -t sysfs none /sys
|
||||
mount -t devtmpfs none /dev
|
||||
}
|
||||
|
||||
use_mdev() {
|
||||
# setup mdev
|
||||
use_mdev() {
|
||||
# setup hotplugger
|
||||
if [ -e /proc/sys/kernel/hotplug ]; then
|
||||
printf /sbin/mdev >/proc/sys/kernel/hotplug
|
||||
else
|
||||
@ -41,8 +42,9 @@ use_mdev() {
|
||||
find /sys -name "modalias" -type f -exec cat "{}" + | sort -u | xargs modprobe -ba
|
||||
}
|
||||
|
||||
use_mdevd() {
|
||||
# setup mdevd
|
||||
use_mdevd() {
|
||||
# setup daemon
|
||||
mdevd &
|
||||
# trigger uevents
|
||||
mdevd-coldplug
|
||||
@ -52,15 +54,17 @@ use_mdevd() {
|
||||
sleep 1.5
|
||||
}
|
||||
|
||||
use_udev() {
|
||||
# setup udev
|
||||
use_udev() {
|
||||
udevd --daemon
|
||||
udevadm trigger --action=add --type=subsystems
|
||||
udevadm trigger --action=add --type=devices
|
||||
udevadm settle
|
||||
}
|
||||
|
||||
# unlock LUKS container
|
||||
unlock_luks() {
|
||||
# TODO implement POSIX findfs
|
||||
# find device of 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"
|
||||
}
|
||||
|
||||
trigger_lvm() {
|
||||
# manually trigger LVM if udev disabled
|
||||
trigger_lvm() {
|
||||
lvm vgchange --sysinit -a y
|
||||
}
|
||||
|
||||
# mount rootfs to /mnt/root
|
||||
mnt_rootfs() {
|
||||
# merge mount flags
|
||||
[ -n "$root_args" ] && mount_args="$root_args"
|
||||
@ -83,28 +88,29 @@ mnt_rootfs() {
|
||||
mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs"
|
||||
}
|
||||
|
||||
# kill and unmount
|
||||
cleanup() {
|
||||
# clean up
|
||||
# stop mdev
|
||||
[ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
|
||||
# stop mdevd
|
||||
[ "$devmgr" = "mdevd" ] && killall mdevd
|
||||
# stop udev
|
||||
[ "$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
|
||||
}
|
||||
|
||||
# exec /mnt/root/sbin/init
|
||||
boot_system() {
|
||||
# boot system
|
||||
exec switch_root /mnt/root /sbin/init || panic "failed to boot system"
|
||||
}
|
||||
|
||||
# install busybox
|
||||
/sbin/busybox --install -s
|
||||
|
||||
# check config
|
||||
if [ -e /config ]; then
|
||||
. /config
|
||||
else
|
||||
panic "config doesn't exists"
|
||||
fi
|
||||
# source config
|
||||
. /config || panic "config doesn't exists"
|
||||
|
||||
if [ "$debug" = 1 ]; then
|
||||
# debug shell commands
|
||||
|
Loading…
Reference in New Issue
Block a user