From 5eae5cd6a9f76eda4dd37d45e7e345b2edc8e636 Mon Sep 17 00:00:00 2001 From: illiliti Date: Mon, 27 Jul 2020 11:32:22 +0300 Subject: [PATCH] move device managers to hooks --- config | 17 ++---- hooks/eudev/eudev | 24 ++++++++ hooks/eudev/eudev.init | 15 +++++ hooks/eudev/eudev.init.late | 10 ++++ hooks/mdev/mdev | 22 +++++++ hooks/mdev/mdev.init | 19 ++++++ hooks/mdev/mdev.init.late | 10 ++++ hooks/mdevd/mdevd | 22 +++++++ hooks/mdevd/mdevd.init | 13 ++++ hooks/mdevd/mdevd.init.late | 10 ++++ hooks/proc/proc | 9 +++ hooks/proc/proc.init | 19 ++++++ hooks/proc/proc.init.late | 7 +++ hooks/systemd-udevd/systemd-udevd | 24 ++++++++ hooks/systemd-udevd/systemd-udevd.init | 15 +++++ hooks/systemd-udevd/systemd-udevd.init.late | 10 ++++ init | 50 +--------------- tinyramfs | 66 +-------------------- 18 files changed, 237 insertions(+), 125 deletions(-) create mode 100644 hooks/eudev/eudev create mode 100644 hooks/eudev/eudev.init create mode 100644 hooks/eudev/eudev.init.late create mode 100644 hooks/mdev/mdev create mode 100644 hooks/mdev/mdev.init create mode 100644 hooks/mdev/mdev.init.late create mode 100644 hooks/mdevd/mdevd create mode 100644 hooks/mdevd/mdevd.init create mode 100644 hooks/mdevd/mdevd.init.late create mode 100644 hooks/proc/proc create mode 100644 hooks/proc/proc.init create mode 100644 hooks/proc/proc.init.late create mode 100644 hooks/systemd-udevd/systemd-udevd create mode 100644 hooks/systemd-udevd/systemd-udevd.init create mode 100644 hooks/systemd-udevd/systemd-udevd.init.late diff --git a/config b/config index 160651c..e4e9d65 100644 --- a/config +++ b/config @@ -45,14 +45,6 @@ # #root_opts="" -# device manager -# -# supported - none, proc, udev, mdev, mdevd -# none means no device manager. requires monolithic kernel and you will unable to use UUID, LABEL, PARTUUID, /dev/mapper/* -# proc requires monolithic kernel and legacy CONFIG_UEVENT_HELPER -# -#devmgr="" - # hostonly mode # # default - 0 @@ -63,11 +55,12 @@ # hooks # -# currently supported - lvm, luks +# supported - proc, eudev, systemd-udevd, mdev, mdevd, lvm, luks # example - -# hooks="lvm luks" will support booting LUKS on LVM -# hooks="luks lvm" will support booting LVM on LUKS -# hooks="luks" will support booting only LUKS +# hooks="eudev lvm luks" will use eudev as device manager and support booting LUKS on LVM +# hooks="mdev luks lvm" will use mdev as device manager and support booting LVM on LUKS +# hooks="systemd-udevd luks" will use systemd-udevd as device manager and support booting only LUKS +# hooks="proc" will use CONFIG_UEVENT_HELPER as device manager # and so on... # #hooks="" diff --git a/hooks/eudev/eudev b/hooks/eudev/eudev new file mode 100644 index 0000000..e2e1d3c --- /dev/null +++ b/hooks/eudev/eudev @@ -0,0 +1,24 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# handle_eudev() +{ + print "configuring eudev" + + for _binary in udevd udevadm; do + copy_binary "$_binary" + done + + mkdir -p "${tmpdir}/lib/udev/rules.d" + + printf "%s\n" \ + 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ + > "${tmpdir}/lib/udev/rules.d/device-helper.rules" + + [ "$monolith" = 1 ] || printf "%s\n" \ + 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ + >> "${tmpdir}/lib/udev/rules.d/device-helper.rules" +} diff --git a/hooks/eudev/eudev.init b/hooks/eudev/eudev.init new file mode 100644 index 0000000..c39155b --- /dev/null +++ b/hooks/eudev/eudev.init @@ -0,0 +1,15 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2034 +# +# run_eudev() +{ + [ "$break" = devmgr ] && { print "break before run_eudev()"; sh; } + + udevd -N never & eudev_pid="$!" + udevadm trigger -c add -t subsystems + udevadm trigger -c add -t devices + udevadm settle +} diff --git a/hooks/eudev/eudev.init.late b/hooks/eudev/eudev.init.late new file mode 100644 index 0000000..6f2d3e4 --- /dev/null +++ b/hooks/eudev/eudev.init.late @@ -0,0 +1,10 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# stop_eudev() +{ + kill "$eudev_pid" +} diff --git a/hooks/mdev/mdev b/hooks/mdev/mdev new file mode 100644 index 0000000..61d35ef --- /dev/null +++ b/hooks/mdev/mdev @@ -0,0 +1,22 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2016 +# +# handle_mdev() +{ + print "configuring mdev" + + for _binary in mdev find; do + copy_binary "$_binary" + done + + printf "%s\n" \ + 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ + > "${tmpdir}/etc/mdev.conf" + + [ "$monolith" = 1 ] || printf "%s\n" \ + '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ + >> "${tmpdir}/etc/mdev.conf" +} diff --git a/hooks/mdev/mdev.init b/hooks/mdev/mdev.init new file mode 100644 index 0000000..4145486 --- /dev/null +++ b/hooks/mdev/mdev.init @@ -0,0 +1,19 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2034 +# +# run_mdev() +{ + [ "$break" = devmgr ] && { print "break before run_mdev()"; sh; } + + mdev -s + mdev -df 2> /dev/null & mdev_pid="$!" + + find /sys/devices -name uevent | + + while read -r uevent; do + printf add > "$uevent" + done 2> /dev/null +} diff --git a/hooks/mdev/mdev.init.late b/hooks/mdev/mdev.init.late new file mode 100644 index 0000000..63999c6 --- /dev/null +++ b/hooks/mdev/mdev.init.late @@ -0,0 +1,10 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# stop_mdev() +{ + kill "$mdev_pid" +} diff --git a/hooks/mdevd/mdevd b/hooks/mdevd/mdevd new file mode 100644 index 0000000..3ef85fd --- /dev/null +++ b/hooks/mdevd/mdevd @@ -0,0 +1,22 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2016 +# +# handle_mdevd() +{ + print "configuring mdevd" + + for _binary in mdevd mdevd-coldplug; do + copy_binary "$_binary" + done + + printf "%s\n" \ + 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ + > "${tmpdir}/etc/mdev.conf" + + [ "$monolith" = 1 ] || printf "%s\n" \ + '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ + >> "${tmpdir}/etc/mdev.conf" +} diff --git a/hooks/mdevd/mdevd.init b/hooks/mdevd/mdevd.init new file mode 100644 index 0000000..10863f1 --- /dev/null +++ b/hooks/mdevd/mdevd.init @@ -0,0 +1,13 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2034 +# +# run_mdevd() +{ + [ "$break" = devmgr ] && { print "break before run_mdevd()"; sh; } + + mdevd 2> /dev/null & mdevd_pid="$!" + mdevd-coldplug +} diff --git a/hooks/mdevd/mdevd.init.late b/hooks/mdevd/mdevd.init.late new file mode 100644 index 0000000..98d6e58 --- /dev/null +++ b/hooks/mdevd/mdevd.init.late @@ -0,0 +1,10 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# stop_mdevd() +{ + kill "$mdevd_pid" +} diff --git a/hooks/proc/proc b/hooks/proc/proc new file mode 100644 index 0000000..70e213e --- /dev/null +++ b/hooks/proc/proc @@ -0,0 +1,9 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# handle_proc() +{ + print "configuring /proc hotplugger" + + copy_binary find +} diff --git a/hooks/proc/proc.init b/hooks/proc/proc.init new file mode 100644 index 0000000..6fc2fb6 --- /dev/null +++ b/hooks/proc/proc.init @@ -0,0 +1,19 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# run_proc() +{ + [ "$break" = devmgr ] && { print "break before run_proc()"; sh; } + + command -v device-helper > /proc/sys/kernel/hotplug + + # get ready for fork bomb. kek + find /sys/devices -name uevent | + + while read -r uevent; do + printf add > "$uevent" + done 2> /dev/null +} diff --git a/hooks/proc/proc.init.late b/hooks/proc/proc.init.late new file mode 100644 index 0000000..331767e --- /dev/null +++ b/hooks/proc/proc.init.late @@ -0,0 +1,7 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# stop_proc() +{ + printf '\n' > /proc/sys/kernel/hotplug +} diff --git a/hooks/systemd-udevd/systemd-udevd b/hooks/systemd-udevd/systemd-udevd new file mode 100644 index 0000000..e7c6d55 --- /dev/null +++ b/hooks/systemd-udevd/systemd-udevd @@ -0,0 +1,24 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# handle_systemd_udevd() +{ + print "configuring systemd-udevd" + + for _binary in /lib/systemd/systemd-udevd udevadm; do + copy_binary "$_binary" + done + + mkdir -p "${tmpdir}/lib/udev/rules.d" + + printf "%s\n" \ + 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ + > "${tmpdir}/lib/udev/rules.d/device-helper.rules" + + [ "$monolith" = 1 ] || printf "%s\n" \ + 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ + >> "${tmpdir}/lib/udev/rules.d/device-helper.rules" +} diff --git a/hooks/systemd-udevd/systemd-udevd.init b/hooks/systemd-udevd/systemd-udevd.init new file mode 100644 index 0000000..de5e587 --- /dev/null +++ b/hooks/systemd-udevd/systemd-udevd.init @@ -0,0 +1,15 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154,2034 +# +# run_systemd_udevd() +{ + [ "$break" = devmgr ] && { print "break before run_systemd_udevd()"; sh; } + + /lib/systemd/systemd-udevd -N never & systemd_udevd_pid="$!" + udevadm trigger -c add -t subsystems + udevadm trigger -c add -t devices + udevadm settle +} diff --git a/hooks/systemd-udevd/systemd-udevd.init.late b/hooks/systemd-udevd/systemd-udevd.init.late new file mode 100644 index 0000000..3911dfe --- /dev/null +++ b/hooks/systemd-udevd/systemd-udevd.init.late @@ -0,0 +1,10 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# false positive +# shellcheck disable=2154 +# +# stop_systemd_udevd() +{ + kill "$systemd_udevd_pid" +} diff --git a/init b/init index d23a342..0540e05 100755 --- a/init +++ b/init @@ -86,44 +86,6 @@ parse_cmdline() esac 2> /dev/null || :; done } -setup_devmgr() -{ - [ "$break" = devmgr ] && { print "break before setup_devmgr()"; sh; } - - case "$devmgr" in - proc) - command -v device-helper > /proc/sys/kernel/hotplug - - # get ready for fork bomb. kek - find /sys/devices -name uevent | - - while read -r uevent; do - printf add > "$uevent" - done - ;; - udev) - udevd -N never & devmgr_pid="$!" - udevadm trigger -c add -t subsystems - udevadm trigger -c add -t devices - udevadm settle - ;; - mdev) - mdev -s - mdev -df & devmgr_pid="$!" - - find /sys/devices -name uevent | - - while read -r uevent; do - printf add > "$uevent" - done - ;; - mdevd) - mdevd & devmgr_pid="$!" - mdevd-coldplug - ;; - esac 2> /dev/null -} - mount_root() { [ "$break" = root ] && { print "break before mount_root()"; sh; } @@ -143,10 +105,6 @@ boot_system() { [ "$break" = boot ] && { print "break before boot_system()"; sh; } - { - kill "$devmgr_pid" || printf '\n' > /proc/sys/kernel/hotplug - } 2> /dev/null || : - for dir in run dev sys proc; do mount -o move "$dir" "/mnt/root/${dir}" done @@ -169,14 +127,8 @@ boot_system() prepare_environment parse_cmdline - - run_hook init.early - - # XXX may be moved to hooks soon - setup_devmgr - run_hook init - mount_root + run_hook init.late boot_system } diff --git a/tinyramfs b/tinyramfs index c19f1de..8dcb211 100755 --- a/tinyramfs +++ b/tinyramfs @@ -134,7 +134,7 @@ prepare_initramfs() copy_binary "$_binary" done - if command -v blkid; then + if command -v blkid > /dev/null; then copy_binary blkid else print "blkid not found. you will unable to use UUID, LABEL, PARTUUID" @@ -260,7 +260,7 @@ copy_hook() print "running $hook hook"; . "${_dir}/${hook}/${hook}" - for _file in init init.early; do + for _file in init init.late; do [ -f "${_dir}/${hook}/${hook}.${_file}" ] || continue { @@ -357,67 +357,6 @@ copy_modules() depmod -b "$tmpdir" "$kernel" } -copy_devmgr() -{ - print "configuring device manager" - - # false positive - # shellcheck disable=2016 - case "$devmgr" in - proc) - copy_binary find - ;; - mdev) - for _binary in mdev find; do - copy_binary "$_binary" - done - - printf "%s\n" \ - 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ - > "${tmpdir}/etc/mdev.conf" - - [ "$monolith" = 1 ] || printf "%s\n" \ - '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ - >> "${tmpdir}/etc/mdev.conf" - ;; - mdevd) - for _binary in mdevd mdevd-coldplug; do - copy_binary "$_binary" - done - - printf "%s\n" \ - 'SUBSYSTEM=block;.* 0:0 660 @device-helper' \ - > "${tmpdir}/etc/mdev.conf" - - [ "$monolith" = 1 ] || printf "%s\n" \ - '$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \ - >> "${tmpdir}/etc/mdev.conf" - ;; - udev) - # why systemd violates FHS and places daemon in /lib ? - if [ -e /lib/systemd/systemd-udevd ]; then - copy_binary /lib/systemd/systemd-udevd - mv "${tmpdir}/lib/systemd/systemd-udevd" "${tmpdir}/bin/udevd" - rmdir "${tmpdir}/lib/systemd" - else - copy_binary udevd - fi - - copy_binary udevadm - - mkdir -p "${tmpdir}/lib/udev/rules.d" - - printf "%s\n" \ - 'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \ - > "${tmpdir}/lib/udev/rules.d/device-helper.rules" - - [ "$monolith" = 1 ] || printf "%s\n" \ - 'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \ - >> "${tmpdir}/lib/udev/rules.d/device-helper.rules" - ;; - esac -} - make_initramfs() ( print "generating initramfs image" @@ -449,7 +388,6 @@ make_initramfs() copy_hook "$_hook" done - copy_devmgr copy_modules make_initramfs }