[arch-projects] [mkinitcpio][PATCH 0/4] more low hanging froot
There's a couple new minor features proposed in here, but most of it is in the name of simplification: 1/4: set fewer vars, which means we remove a bunch of eval usage. Just mark the hook as unreadable to disable it from running. 2/4: support identifying root by tag name. There's a bit of a conflict here, though. The kernel will support mounting root when provided as PARTUUID=, but util-linux's blkid won't support this. We can, however, support LABEL= and UUID= syntax by resolving via blkid, and trimming the 'PART' from PARTUUID is trivial. 3/4: just a shortcut when we need to create the root device in the non-udev use case when its specified as something like /dev/sdxy. 4/4: cleanse the environment before leaving early userspace. self explanatory. d init | 23 +++++++++-------------- init_functions | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-)
Instead of dynamically creating variables to test against, simply remove the read permission from the hook. Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 21 ++++++++------------- 1 files changed, 8 insertions(+), 13 deletions(-) diff --git a/init b/init index 1f6bc4e..67039c8 100644 --- a/init +++ b/init @@ -40,9 +40,9 @@ else fi if [ -n "${disablehooks}" ]; then - for d in $(echo "${disablehooks}" | sed 's|,| |g'); do - eval "hook_${d}=disabled" - done + cd /hooks >/dev/null + chmod -r ${disablehooks//,/ } 2>/dev/null + cd - >/dev/null fi if [ -n "${earlymodules}" ]; then @@ -60,16 +60,11 @@ fi if [ -e "/hooks" ]; then for h in ${HOOKS}; do - TST="" - eval "TST=\$hook_${h}" - if [ "${TST}" != "disabled" ]; then - run_hook () { msg "${h}: no run function defined"; } - if [ -e "/hooks/${h}" ]; then - . /hooks/${h} - msg ":: Running Hook [${h}]" - run_hook - fi - fi + [ -r "/hooks/$h" ] || continue + run_hook () { msg "${h}: no run function defined"; } + . /hooks/${h} + msg ":: Running Hook [${h}]" + run_hook done fi -- 1.7.5.4
On Sat, Jun 04, 2011 at 01:17:58PM -0400, Dave Reisner wrote:
Instead of dynamically creating variables to test against, simply remove the read permission from the hook.
Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 21 ++++++++------------- 1 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/init b/init index 1f6bc4e..67039c8 100644 --- a/init +++ b/init @@ -40,9 +40,9 @@ else fi
if [ -n "${disablehooks}" ]; then - for d in $(echo "${disablehooks}" | sed 's|,| |g'); do - eval "hook_${d}=disabled" - done + cd /hooks >/dev/null + chmod -r ${disablehooks//,/ } 2>/dev/null + cd - >/dev/null fi
if [ -n "${earlymodules}" ]; then @@ -60,16 +60,11 @@ fi
if [ -e "/hooks" ]; then for h in ${HOOKS}; do - TST="" - eval "TST=\$hook_${h}" - if [ "${TST}" != "disabled" ]; then - run_hook () { msg "${h}: no run function defined"; } - if [ -e "/hooks/${h}" ]; then - . /hooks/${h} - msg ":: Running Hook [${h}]" - run_hook - fi - fi + [ -r "/hooks/$h" ] || continue + run_hook () { msg "${h}: no run function defined"; } + . /hooks/${h} + msg ":: Running Hook [${h}]" + run_hook done fi
-- 1.7.5.4
Strike this. The shell test passes regardless since we're root. d
use blkid to resolve a tag name to a block device. Signed-off-by: Dave Reisner <d@falconindy.com> --- init_functions | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/init_functions b/init_functions index be3599e..f9f1742 100644 --- a/init_functions +++ b/init_functions @@ -73,6 +73,15 @@ parse_cmdline() { } default_mount_handler() { + # resolve tag name to block device + if [ "${root:0:9}" = 'PARTUUID=' ] || [ "${root:0:5}" = 'UUID=' ] || [ "${root:0:6}" = 'LABEL=' ]; then + device=$(blkid -t "${root#PART}") + if [ -n "$device" ]; then + root=$device + fi + unset device + fi + if [ ${root:0:5} != "/dev/" ] || ! poll_device "${root}" ${rootdelay}; then msg "Root device '${root}' doesn't exist. Attempting to create it." major="" -- 1.7.5.4
On Sat, Jun 04, 2011 at 01:17:59PM -0400, Dave Reisner wrote:
use blkid to resolve a tag name to a block device.
Signed-off-by: Dave Reisner <d@falconindy.com> --- init_functions | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/init_functions b/init_functions index be3599e..f9f1742 100644 --- a/init_functions +++ b/init_functions @@ -73,6 +73,15 @@ parse_cmdline() { }
default_mount_handler() { + # resolve tag name to block device + if [ "${root:0:9}" = 'PARTUUID=' ] || [ "${root:0:5}" = 'UUID=' ] || [ "${root:0:6}" = 'LABEL=' ]; then + device=$(blkid -t "${root#PART}") + if [ -n "$device" ]; then + root=$device + fi + unset device + fi + if [ ${root:0:5} != "/dev/" ] || ! poll_device "${root}" ${rootdelay}; then msg "Root device '${root}' doesn't exist. Attempting to create it." major="" -- 1.7.5.4
This patch sucks. It misses an option to blkid. Also, I've got a working branch on Github for this now: https://github.com/falconindy/mkinitcpio/tree/working Destroyed add_module and add_binary today, with great success... dave
/sys/class/block contains all of our block devices, including the partitions of each parent block device, so directly check for the existance of the dev file rather than looping. Signed-off-by: Dave Reisner <d@falconindy.com> --- init_functions | 14 +++++--------- 1 files changed, 5 insertions(+), 9 deletions(-) diff --git a/init_functions b/init_functions index f9f1742..95aa98f 100644 --- a/init_functions +++ b/init_functions @@ -87,15 +87,11 @@ default_mount_handler() { major="" minor="" if [ ${root:0:5} = "/dev/" ]; then - # It might be a block device (/dev/sda) -> /sys/block/sda/dev - # or a partition (/dev/sda1) -> /sys/block/sda/sda1/dev - for dir in /sys/block /sys/block/*; do - if [ -f ${dir}/${root:5}/dev ]; then - major="$(cat ${dir}/${root:5}/dev | cut -d: -f1)" - minor="$(cat ${dir}/${root:5}/dev | cut -d: -f2)" - break - fi - done + # It might be a block device (/dev/sda) -> /sys/class/block/sda/dev + if [ -e /sys/class/block/${root:5}/dev ]; then + IFS=':' read major minor < "/sys/class/block/${root:5}/dev" + break + fi # It might be a major/minor pair (8:1) elif echo ${root} | grep -q :; then major="$(echo ${root} | cut -d: -f1)" -- 1.7.5.4
We preserve TERM, but everything else can be destroyed from the environment. Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/init b/init index 67039c8..db93e9b 100644 --- a/init +++ b/init @@ -112,4 +112,4 @@ for d in proc sys dev run; do /bin/umount /${d} fi done -exec /sbin/switch_root -c /dev/console /new_root ${init} "$@" +exec env -i TERM=$TERM /sbin/switch_root -c /dev/console /new_root ${init} "$@" -- 1.7.5.4
On Sat, Jun 4, 2011 at 7:17 PM, Dave Reisner <d@falconindy.com> wrote:
2/4: support identifying root by tag name. There's a bit of a conflict here, though. The kernel will support mounting root when provided as PARTUUID=, but util-linux's blkid won't support this. We can, however, support LABEL= and UUID= syntax by resolving via blkid, and trimming the 'PART' from PARTUUID is trivial.
This is great! I wonder, is it possible to tell the kernel to try mounting the rootfs directly, and only if it cannot be found, start the initramfs?
3/4: just a shortcut when we need to create the root device in the non-udev use case when its specified as something like /dev/sdxy.
4/4: cleanse the environment before leaving early userspace. self explanatory.
You push patches faster than I can ack them ;-) Ack to everything (minus the one you withdrew). Cheers, Tom
On Sat, Jun 04, 2011 at 07:34:37PM +0200, Tom Gundersen wrote:
On Sat, Jun 4, 2011 at 7:17 PM, Dave Reisner <d@falconindy.com> wrote:
2/4: support identifying root by tag name. There's a bit of a conflict here, though. The kernel will support mounting root when provided as PARTUUID=, but util-linux's blkid won't support this. We can, however, support LABEL= and UUID= syntax by resolving via blkid, and trimming the 'PART' from PARTUUID is trivial.
This is great! I wonder, is it possible to tell the kernel to try mounting the rootfs directly, and only if it cannot be found, start the initramfs?
3/4: just a shortcut when we need to create the root device in the non-udev use case when its specified as something like /dev/sdxy.
4/4: cleanse the environment before leaving early userspace. self explanatory.
You push patches faster than I can ack them ;-)
Ack to everything (minus the one you withdrew).
Cheers,
Tom
And I've got one more on the way for you, Tom. I'm killing everything dmesg related because we've been, as the internet might say, "doing it wrong". The kernel reads loglevel= from the cmdline, which sets kloglevel. dave
On Sat, Jun 4, 2011 at 7:40 PM, Dave Reisner <d@falconindy.com> wrote:
And I've got one more on the way for you, Tom. I'm killing everything dmesg related because we've been, as the internet might say, "doing it wrong". The kernel reads loglevel= from the cmdline, which sets kloglevel.
Brilliant, I was not aware of that (and I'm all for "doing it right"). -t
participants (2)
-
Dave Reisner
-
Tom Gundersen