small rework
This commit is contained in:
parent
d1d2ae88bd
commit
ebc9b82c64
149
files/init
149
files/init
@ -14,23 +14,23 @@ parse_cmdline() {
|
|||||||
set -- $(cat /proc/cmdline)
|
set -- $(cat /proc/cmdline)
|
||||||
|
|
||||||
for line in "$@"; do
|
for line in "$@"; do
|
||||||
|
value="${line##*=}"
|
||||||
|
|
||||||
# parse options
|
|
||||||
case "${line%%=*}" in
|
case "${line%%=*}" in
|
||||||
debug) debug="${line##*=}" ;;
|
debug) debug="$value" ;;
|
||||||
init) init="${line##*=}" ;;
|
init) init="$value" ;;
|
||||||
root) root="${line##*=}" ;;
|
root) root="$value" ;;
|
||||||
root.type) root_type="${line##*=}" ;;
|
root.type) root_type="$value" ;;
|
||||||
root.opts) root_opts="${line##*=}" ;;
|
root.opts) root_opts="$value" ;;
|
||||||
lvm) lvm="${line##*=}" ;;
|
lvm) lvm="$value" ;;
|
||||||
lvm.name) lvm_name="${line##*=}" ;;
|
lvm.name) lvm_name="$value" ;;
|
||||||
lvm.group) lvm_group="${line##*=}" ;;
|
lvm.group) lvm_group="$value" ;;
|
||||||
lvm.args) lvm_args="${line##*=}" ;;
|
lvm.args) lvm_args="$value" ;;
|
||||||
luks) luks="${line##*=}" ;;
|
luks) luks="$value" ;;
|
||||||
luks.root) luks_root="${line##*=}" ;;
|
luks.root) luks_root="$value" ;;
|
||||||
luks.name) luks_name="${line##*=}" ;;
|
luks.name) luks_name="$value" ;;
|
||||||
luks.discard) luks_discard="${line##*=}" ;;
|
luks.discard) luks_discard="$value" ;;
|
||||||
luks.args) luks_args="${line##*=}" ;;
|
luks.args) luks_args="$value" ;;
|
||||||
# TODO implement
|
# TODO implement
|
||||||
#lvm.discard) ;;
|
#lvm.discard) ;;
|
||||||
#lvm.conf) ;;
|
#lvm.conf) ;;
|
||||||
@ -40,58 +40,52 @@ parse_cmdline() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
mnt_pseudofs() {
|
mount_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
|
||||||
mount -t tmpfs none /tmp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_mdev() {
|
setup_devmgr() {
|
||||||
# setup hotplugger
|
case "$devmgr" in
|
||||||
if [ -e /proc/sys/kernel/hotplug ]; then
|
udev)
|
||||||
printf /sbin/mdev > /proc/sys/kernel/hotplug
|
udevd -d
|
||||||
else
|
udevadm trigger -c add -t subsystems
|
||||||
uevent mdev &
|
udevadm trigger -c add -t devices
|
||||||
fi
|
udevadm settle
|
||||||
|
;;
|
||||||
|
mdev)
|
||||||
|
uevent mdev &
|
||||||
|
mdev -s
|
||||||
|
|
||||||
# trigger mdev
|
for device in /sys/bus/usb/devices/*; do
|
||||||
mdev -s
|
case "${device##*/}" in [0-9]*-[0-9]*)
|
||||||
|
printf add > "${device}/uevent" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
# trigger uevent for usb devices
|
find /sys -name modalias -type f -exec sort -u {} + |
|
||||||
for device in /sys/bus/usb/devices/*; do
|
xargs modprobe -b > /dev/null 2>&1
|
||||||
case "${device##*/}" in
|
;;
|
||||||
[0-9]*-[0-9]*) printf add > "${device}/uevent" ;;
|
mdevd)
|
||||||
esac
|
mdevd &
|
||||||
done
|
mdevd-coldplug
|
||||||
|
;;
|
||||||
# load drivers
|
*)
|
||||||
find /sys -name modalias -type f -exec sort -u {} + |
|
panic "devmgr option broken"
|
||||||
xargs modprobe -qba
|
;;
|
||||||
}
|
esac
|
||||||
|
|
||||||
setup_mdevd() {
|
|
||||||
# setup daemon
|
|
||||||
mdevd &
|
|
||||||
|
|
||||||
# trigger uevents
|
|
||||||
mdevd-coldplug
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_udev() {
|
|
||||||
udevd --daemon
|
|
||||||
udevadm trigger --action=add --type=subsystems
|
|
||||||
udevadm trigger --action=add --type=devices
|
|
||||||
udevadm settle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findfs_sh() {
|
findfs_sh() {
|
||||||
|
value="${1##*=}"
|
||||||
|
|
||||||
case "${1%%=*}" in
|
case "${1%%=*}" in
|
||||||
LABEL) device="/dev/disk/by-label/${1##*=}" ;;
|
LABEL) device="/dev/disk/by-label/${value}" ;;
|
||||||
UUID) device="/dev/disk/by-uuid/${1##*=}" ;;
|
UUID) device="/dev/disk/by-uuid/${value}" ;;
|
||||||
PARTUUID) device="/dev/disk/by-partuuid/${1##*=}" ;;
|
PARTUUID) device="/dev/disk/by-partuuid/${value}" ;;
|
||||||
/dev/*) device="$1" ;;
|
/dev/*) device="$1" ;;
|
||||||
*) panic "findfs option broken" ;;
|
*) panic "findfs option broken" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# avoid race condition
|
# avoid race condition
|
||||||
@ -116,28 +110,28 @@ unlock_luks() {
|
|||||||
|
|
||||||
trigger_lvm() {
|
trigger_lvm() {
|
||||||
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
||||||
lvm lvchange $lvm_args --quiet --sysinit -a y "${lvm_group}/${lvm_name}" > /dev/null
|
lvm lvchange $lvm_args --sysinit -q -a y "${lvm_group}/${lvm_name}" > /dev/null
|
||||||
elif [ "$lvm_group" ]; then
|
elif [ "$lvm_group" ]; then
|
||||||
lvm vgchange $lvm_args --quiet --sysinit -a y "$lvm_group" > /dev/null
|
lvm vgchange $lvm_args --sysinit -q -a y "$lvm_group" > /dev/null
|
||||||
else
|
else
|
||||||
lvm vgchange $lvm_args --quiet --sysinit -a y > /dev/null
|
lvm vgchange $lvm_args --sysinit -q -a y > /dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mnt_rootfs() {
|
mount_rootfs() {
|
||||||
mount ${root_type:+-t $root_type} ${root_opts:+-o $root_opts} $(findfs_sh "$root") /mnt/root ||
|
mount ${root_type:+-t $root_type} ${root_opts:+-o $root_opts} $(findfs_sh "$root") /mnt/root ||
|
||||||
panic "failed to mount rootfs"
|
panic "failed to mount rootfs"
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
mdev) { printf "" > /proc/sys/kernel/hotplug || killall uevent; } > /dev/null 2>&1 ;;
|
udev) udevadm control -e ;;
|
||||||
mdevd) killall mdevd ;;
|
mdev) killall uevent ;;
|
||||||
udev) udevadm control --exit ;;
|
mdevd) killall mdevd ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# unmount pseudofs's
|
# unmount pseudofs's
|
||||||
umount /dev /sys /proc /tmp
|
umount /dev /sys /proc
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_system() {
|
boot_system() {
|
||||||
@ -150,29 +144,24 @@ boot_system() {
|
|||||||
. /config ||
|
. /config ||
|
||||||
panic "failed to source config"
|
panic "failed to source config"
|
||||||
|
|
||||||
mnt_pseudofs
|
mount_pseudofs
|
||||||
parse_cmdline
|
parse_cmdline
|
||||||
|
|
||||||
# debug mode
|
|
||||||
[ "$debug" = 1 ] && set -x
|
[ "$debug" = 1 ] && set -x
|
||||||
|
|
||||||
case "$devmgr" in
|
setup_devmgr
|
||||||
mdev) setup_mdev ;;
|
|
||||||
mdevd) setup_mdevd ;;
|
|
||||||
udev) setup_udev ;;
|
|
||||||
*) panic "devmgr option broken" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# TODO handle situations when LUKS on LVM
|
# TODO handle situations when LUKS on LVM
|
||||||
[ "$luks" = 1 ] &&
|
[ "$luks" = 1 ] && command -v cryptsetup > /dev/null 2>&1 &&
|
||||||
command -v cryptsetup > /dev/null 2>&1 &&
|
unlock_luks
|
||||||
unlock_luks
|
|
||||||
|
|
||||||
[ "$lvm" = 1 ] &&
|
[ "$lvm" = 1 ] && command -v lvm > /dev/null 2>&1 &&
|
||||||
command -v lvm > /dev/null 2>&1 &&
|
trigger_lvm
|
||||||
trigger_lvm
|
|
||||||
|
mount_rootfs
|
||||||
|
|
||||||
|
[ "$debug" = 1 ] &&
|
||||||
|
panic "dropping to shell"
|
||||||
|
|
||||||
mnt_rootfs
|
|
||||||
[ "$debug" = 1 ] && panic "dropping to shell"
|
|
||||||
cleanup
|
cleanup
|
||||||
boot_system
|
boot_system
|
||||||
|
Loading…
Reference in New Issue
Block a user