Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 488838 - sys-kernel/dracut-034-r1 adds /bin/bash to image when bash module is disabled and dash module is enabled
Summary: sys-kernel/dracut-034-r1 adds /bin/bash to image when bash module is disabled...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Amadeusz Żołnowski (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-21 04:01 UTC by Nikoli
Modified: 2014-07-27 11:25 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikoli 2013-10-21 04:01:44 UTC
When bash module is added to omit_dracutmodules and dash module is enabled dracut installs both /bin/dash and /bin/bash, symlink /bin/sh is correct - it uses dash. When tmpdir is mounted with noexec this bug does not happen. Commenting line 740 'inst /bin/sh' in /usr/bin/dracut solved bug for me. Seems the bug was introduced in this upstream commit:
commit bfd2e8c25ffc68bb98ca62049d709f378ac2ff1d
Author: Harald Hoyer <harald@redhat.com>
Date:   Mon Jul 30 13:02:41 2012 +0200

    dracut.sh: test if we can lazy resolve with ldd
Comment 1 Nikoli 2013-10-21 05:24:13 UTC
Full list of unwanted and useless files installed to initramfs:
+bin/bash
+lib64/libdl-2.15.so
+lib64/libdl.so.2
+lib64/libncurses.so.5
+lib64/libncurses.so.5.9
+lib64/libreadline.so.6
+lib64/libreadline.so.6.2

xz compressed image is 516K bigger. dracut installs bash even when system has '/bin/sh -> dash'.
Comment 2 Nikoli 2013-10-21 05:53:46 UTC
Editing /usr/bin/dracut is not enough, also it is required to do 'ln -snf dash /bin/sh', else dracut will install libs for bash. Not sure why, but dracut installs /bin/sh instead of /bin/dash:
# grep -e bin/sh -e bin/dash -e bin/bash /tmp/dracut_debug.log
/usr/bin/dracut@740(): inst /bin/sh
/usr/lib/dracut/dracut-functions.sh@718(inst): [[ -e /tmp/initramfs.gO2f9z//bin/sh ]]
/usr/lib/dracut/dracut-functions.sh@720(inst): /usr/libexec/dracut-install -D /tmp/initramfs.gO2f9z /bin/sh
dracut-install: Handle '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: dracut_install('/bin/dash', '/bin/dash')
dracut-install: cp '/bin/dash' '/tmp/initramfs.gO2f9z/bin/dash'
dracut-install: ln -s 'dash' '/tmp/initramfs.gO2f9z/bin/sh'
/usr/bin/dracut@741(): /usr/libexec/dracut-install -D /tmp/initramfs.gO2f9z -R /tmp/initramfs.gO2f9z/bin/sh
/usr/lib/dracut/modules.d/00dash/module-setup.sh@6(check): '[' -x /bin/dash ']'
/usr/lib/dracut/modules.d/00dash/module-setup.sh@15(install): [[ -x /tmp/initramfs.gO2f9z/bin/sh ]]
/usr/lib/dracut/modules.d/00dash/module-setup.sh@18(install): inst /bin/dash
/usr/lib/dracut/dracut-functions.sh@718(inst): [[ -e /tmp/initramfs.gO2f9z//bin/dash ]]
/usr/lib/dracut/dracut-functions.sh@720(inst): /usr/libexec/dracut-install -D /tmp/initramfs.gO2f9z -l /bin/dash
dracut-install: Handle '/bin/dash'
dracut-install: dracut_install('/bin/dash', '/bin/dash')
dracut-install: cp '/bin/dash' '/tmp/initramfs.gO2f9z/bin/dash'
/usr/lib/dracut/modules.d/00dash/module-setup.sh@18(install): ln -sf dash /tmp/initramfs.gO2f9z/bin/sh
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
/usr/lib/dracut/modules.d/99base/module-setup.sh@23(install): '[' '!' -e /tmp/initramfs.gO2f9z/bin/sh ']'
/usr/lib/dracut/modules.d/99base/module-setup.sh@29(install): echo root:x:0:0::/root:/bin/sh
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
dracut-install: Script install: '/bin/sh'
dracut-install: dracut_install('/bin/sh', '/bin/sh')
dracut-install: '/tmp/initramfs.gO2f9z/bin/sh' already exists, but checking for any deps
Comment 3 Alexander Tsoy 2013-10-21 10:46:04 UTC
Nikoli, are you sure about commit? Dracut removes all files inside ${initdir} after a test:

    inst /bin/sh
    if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
        unset DRACUT_RESOLVE_LAZY
        export DRACUT_RESOLVE_DEPS=1
    fi
    rm -fr -- ${initdir}/*
---/^^^^^^^^^^^^^^^^^^^^^^

I supect that /bin/bash comes from inst_rule_programs():

$ grep -r 'PROGRAM==\"/bin/sh' .
./modules.d/90dmraid/61-dmraid-imsm.rules:PROGRAM=="/bin/sh -c 'for i in $sys/$devpath/holders/dm-[0-9]*; do [ -e $$i ] && exit 0; done; exit 1;' ", \
./modules.d/90lvm/64-lvm.rules:PROGRAM=="/bin/sh -c 'for i in $sys/$devpath/holders/dm-[0-9]*; do [ -e $$i ] && exit 0; done; exit 1;' ", \
Comment 4 Alexander Tsoy 2013-10-21 12:20:47 UTC
No. It's actually modules.d/99base/uefi-lib.sh :(

From debug output:
dracut-install: resolve_deps('/var/tmp/initramfs.wBmBoS/lib64/uefi-lib.sh')
dracut-install: Script install: '/bin/bash'
dracut-install: dracut_install('/bin/bash', '/bin/bash')


$ head -n1 /usr/lib64/dracut/modules.d/99base/uefi-lib.sh
#!/bin/bash

$ checkbashisms /usr/lib64/dracut/modules.d/99base/uefi-lib.sh
script /usr/lib64/dracut/modules.d/99base/uefi-lib.sh does not appear to be a /bin/sh script
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 28 (alternative test command ([[ foo ]] should be [ foo ])):
    [[ -n $c ]] && c=$(printf '%u' "'$c") || c=0
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 37 ('((' should be '$(('):
    (( val = b2 * 256 + b1 ))
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 53 (alternative test command ([[ foo ]] should be [ foo ])):
        if [[ $first == 1 ]]; then
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 53 (should be 'b = a'):
        if [[ $first == 1 ]]; then
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 55 (alternative test command ([[ foo ]] should be [ foo ])):
        elif [[ $hextype != "7fff" ]]; then
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 70 (should be >word 2>&1):
                getword &>/dev/null
possible bashism in /usr/lib64/dracut/modules.d/99base/uefi-lib.sh line 71 (should be >word 2>&1):
                getword &>/dev/null
Comment 5 Alexander Tsoy 2013-10-21 12:24:42 UTC
(In reply to Nikoli from comment #0)
> When tmpdir is mounted with noexec this bug does not happen.

This is strange, because uefi-lib.sh is always installed.
Comment 6 Alexander Tsoy 2013-10-21 12:33:35 UTC
(In reply to Nikoli from comment #0)
> Seems the bug was introduced in this upstream commit:
> commit bfd2e8c25ffc68bb98ca62049d709f378ac2ff1d
> Author: Harald Hoyer <harald@redhat.com>
> Date:   Mon Jul 30 13:02:41 2012 +0200
> 
>     dracut.sh: test if we can lazy resolve with ldd

http://git.kernel.org/cgit/boot/dracut/dracut.git/commit/?id=46cc29261f9e6f5505d6d7ee84c10ea2a2de6469
Comment 7 Nikoli 2013-10-22 02:16:24 UTC
Indeed uefi-lib.sh has several bashisms and '#!/bin/bash', hope, it will be made optional and bashisms will be fixed. Most systems did not use Fibre Channel over Ethernet (FCoE) now anyway.
Comment 8 Alexander Tsoy 2013-12-17 21:37:05 UTC
Looks like it will be fixed in the next release:

http://git.kernel.org/cgit/boot/dracut/dracut.git/commit/?id=89031be3735045ae06d560bf4f42ec58d889fe8e
Comment 9 Alexander Tsoy 2014-02-19 18:33:24 UTC
This bug is almost fixed in 036. If I manually add "caps" to omitted modules, then bash is not included in initramfs.
Comment 10 Nikoli 2014-07-18 01:36:29 UTC
sys-kernel/dracut-037-r3 does not have this bug anymore :)
Comment 11 Amadeusz Żołnowski (RETIRED) gentoo-dev 2014-07-18 06:52:22 UTC
(In reply to Nikoli from comment #10)
> sys-kernel/dracut-037-r3 does not have this bug anymore :)

Thank you for reporting that, Nikoli.:-)
Comment 12 Alexander Tsoy 2014-07-27 11:25:33 UTC
systemd module pulls in bash in dracut-038 due to commit [1].

[1] http://git.kernel.org/cgit/boot/dracut/dracut.git/commit/?id=f232f6623d2b761c1538192c97e13842e5037adc