cleanup init
This commit is contained in:
parent
1953b1760c
commit
5df6801525
32
init
32
init
@ -10,15 +10,16 @@ panic() {
|
|||||||
# TODO parse /proc/cmdline
|
# TODO parse /proc/cmdline
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# mount pseudofs's
|
||||||
mnt_pseudofs() {
|
mnt_pseudofs() {
|
||||||
# mount pseudofs's
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# setup mdev
|
||||||
use_mdev() {
|
use_mdev() {
|
||||||
# setup 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# setup mdevd
|
||||||
use_mdevd() {
|
use_mdevd() {
|
||||||
# setup 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# setup udev
|
||||||
use_udev() {
|
use_udev() {
|
||||||
# setup 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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# manually trigger LVM if udev disabled
|
||||||
trigger_lvm() {
|
trigger_lvm() {
|
||||||
# manually trigger LVM if udev disabled
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user