Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 676268 - sys-kernel/dracut-049 drops to shell with /lib/fs-lib.sh: line 109: _drv=e2fsck fsck_drv_com: command not found
Summary: sys-kernel/dracut-049 drops to shell with /lib/fs-lib.sh: line 109: _drv=e2fs...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: Patrick McLean
URL:
Whiteboard:
Keywords: PullRequest
Depends on: 676344
Blocks:
  Show dependency tree
 
Reported: 2019-01-26 11:14 UTC by Vadim Dyadkin
Modified: 2019-12-29 19:39 UTC (History)
9 users (show)

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


Attachments
test.sh (test_dracut.sh,250 bytes, text/plain)
2019-01-26 19:00 UTC, Alexander Tsoy
Details
test2.sh (test2.sh,151 bytes, text/plain)
2019-01-26 19:25 UTC, Alexander Tsoy
Details
test2.sh (test2.sh,168 bytes, text/plain)
2019-01-26 19:41 UTC, Alexander Tsoy
Details
Use bash for init rather than sh so bashisms work (file_676268.txt,328 bytes, patch)
2019-02-13 01:17 UTC, Mark Wagner
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim Dyadkin 2019-01-26 11:14:52 UTC
I have a disk encrypted by luks, the encrypted key is stored on a usb stick. When dracut boots the kernel, it gives this error message:
[    3.466770] dracut: Probing /dev/sde1 for /key... 
[    3.629063] EXT4-fs (sde1): mounted filesystem with ordered data mode. Opts: (null) 
[    3.641960] dracut: Found /key on /dev/sde1 
[    3.652221] dracut: luksOpen /dev/nvme0n1p2 luks-0cd5d4cd-730f-42c1-a2c5-d9ce3dbbff96  
[    3.658428] dracut: Using '/key' on '/dev/sde1' 
[    3.821279] EXT4-fs (sde1): mounted filesystem with ordered data mode. Opts: (null) 
[    6.882036] EXT4-fs (dm-0): INFO: recovery required on readonly filesystem 
[    6.883338] EXT4-fs (dm-0): write access will be enabled during recovery 
[    7.275155] EXT4-fs (dm-0): orphan cleanup on readonly fs 
[    7.276663] EXT4-fs (dm-0): 2 orphan inodes deleted 
[    7.277893] EXT4-fs (dm-0): recovery complete 
[    7.294063] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: data=ordered 
[    7.322992] dracut: Checking ext4: /dev/disk/by-uuid/7cec672b-cb75-4f9f-812d-77fe1fdb3124 
[    7.324296] dracut: issuing _drv=e2fsck fsck_drv_com -a  /dev/disk/by-uuid/7cec672b-cb75-4f9f-812d-77fe1fdb3124 
[    7.327145] /lib/fs-lib.sh: line 109: _drv=e2fsck fsck_drv_com: command not found 
[    7.327145] dracut Warning: _drv=e2fsck fsck_drv_com returned with 127 
[    7.329694] dracut Warning: *** An error occurred during the file system check. 
[    7.332215] dracut Warning: *** Dropping you to a shell; the system will try 
[    7.334721] dracut Warning: *** to mount the filesystem(s), when you leave the shell. 
[    7.339653] dracut Warning: 

/usr/lib64/dracut/modules.d/99fs-lib/fs-lib.sh: 
# common code for checkers that follow usual subset of options and return codes 
fsck_drv_com() { 
    local _ret 
    local _out 

    if ! strglobin "$_fop" "-[ynap]"; then 
        _fop="-a ${_fop}" 
    fi 

    info "issuing $_drv $_fop $_dev" 
    # we enforce non-interactive run, so $() is fine 
    _out=$($_drv $_fop "$_dev") 
    _ret=$? 
    fsck_tail 
        
    return $_ret 
} 
Line 109 is that one which starts with _out. It looks like a bug or typo in those dracut script, like it does not evaluate the variable $_drv, just running _drv, or there is a problem in those magic $($_...).
Comment 1 Mike Gilbert gentoo-dev 2019-01-26 17:36:40 UTC
It doesn't seem like the dracut code has changed much recently.

Does this work in earlier versions of dracut?
Comment 2 Alexander Tsoy 2019-01-26 19:00:23 UTC
Created attachment 562912 [details]
test.sh

This is a problem with POSIX mode in bash-5.0:

dash:
$ dash test.sh 
issuing echo hello
hello world

bash-4.3:
$ bash test.sh 
issuing echo hello
hello world
$ bash --posix test.sh 
issuing echo hello
hello world

bash-5.0:
$ bash test.sh 
issuing echo hello
hello world
$ bash --posix test.sh 
issuing _drv=echo fsck_drv_com hello
test.sh: line 10: _drv=echo: command not found
Comment 3 Alexander Tsoy 2019-01-26 19:01:26 UTC
Note: when bash is called via /bin/sh symlink, then POSIX mode is enabled.
Comment 4 Alexander Tsoy 2019-01-26 19:21:02 UTC
(In reply to Alexander Tsoy from comment #2)
> Created attachment 562912 [details]
> test.sh

After commenting out "local _drv" in fsck_single(), with bash-5.0:
$ bash test.sh 
issuing echo hello
hello world
$ bash --posix test.sh 
issuing echo hello
hello world
Comment 5 Alexander Tsoy 2019-01-26 19:25:43 UTC
Created attachment 562914 [details]
test2.sh

Minimal test case.

$ bash test2.sh 
foo: hello world
bar: hello world
$ bash --posix test2.sh 

bar: hello world
Comment 6 Alexander Tsoy 2019-01-26 19:41:08 UTC
Created attachment 562916 [details]
test2.sh

This should better demonstrate what's going on:

$ bash --posix test2.sh 
foo: bye bye
bar: hello world
$ bash test2.sh 
foo: hello world
bar: hello world
Comment 7 Vadim Dyadkin 2019-01-26 20:24:25 UTC
(In reply to Mike Gilbert from comment #1)
> It doesn't seem like the dracut code has changed much recently.
> 
> Does this work in earlier versions of dracut?

No, it started to happen like a week ago, after a typical "emerge -uDN world".
When it started on I second computer, I got worried.
Comment 8 Vadim Dyadkin 2019-01-26 20:31:11 UTC
(In reply to Alexander Tsoy from comment #6)
> Created attachment 562916 [details]
> test2.sh
> 
> This should better demonstrate what's going on:

Do I still need to test it with earlier versions of dracut as Mike suggested? Or the problem is clearly in bash?
Comment 9 khoul81 2019-01-26 21:25:20 UTC
I just hit the same issue after updating the system and getting bash 5. I found a patch used by Void Linux: https://raw.githubusercontent.com/void-linux/void-packages/fdeed0979a8f63e380d7b8cba24fa0eb2d6f5c7f/srcpkgs/dracut/patches/fix-bash-5.patch

I applied it to dracut 049 and after that the boot process works fine.
Comment 10 Mike Gilbert gentoo-dev 2019-01-27 02:40:27 UTC
(In reply to Vadim Dyadkin from comment #8)

No need to test older dracut versions.
Comment 11 Paul Hartman 2019-01-29 18:17:26 UTC
I had the same error.

I found the following Debian bug report which has some more info. I applied the one-line fix locally ("3rd option" as suggested in the Debian bug) and it worked for me. YMMV

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920563

> The 3rd option could be easily accomplished by adding the following line
> to the top of /init (/usr/lib/dracut/modules.d/99base/init.sh) after the
> initial comment block:
> 
> [ -f /bin/bash ] && [ "$BASH" = "/bin/sh" ] && exec /bin/bash /init
Comment 12 Martin Mokrejš 2019-02-09 16:01:32 UTC
Have same problem after dracut and bash-5.0_p2 upgrade.
Comment 13 Mike Gilbert gentoo-dev 2019-02-10 15:41:55 UTC
It would be helpful if someone would report this to dracut upstream, since bash-5.0 is not going to be "fixed".

Maybe Alexander can send a patch with rationale?
Comment 14 Mark Wagner 2019-02-13 01:17:29 UTC
Created attachment 565024 [details, diff]
Use bash for init rather than sh so bashisms work
Comment 15 Mark Wagner 2019-02-13 01:23:24 UTC
(In reply to Mark Wagner from comment #14)
> Created attachment 565024 [details, diff] [details, diff]
> Use bash for init rather than sh so bashisms work

:) From a brief examination of the source code dracut is full of bashisms and other shells have given in and implemented them (in various ways because there is no standard.)

The most egregious is local variables which dracut uses heavily. Other shells have implemented local in kinda the same way which leads to problems on edge cases.

See http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_09_18

"Local variables within a function were considered and included in another early proposal (controlled by the special built-in local), but were removed because they do not fit the simple model developed for functions and because there was some opposition to adding yet another new special built-in that was not part of historical practice."

See however http://austingroupbugs.net/view.php?id=767
Comment 16 Mike Gilbert gentoo-dev 2019-02-13 03:46:07 UTC
Send patches upstream.
Comment 17 Mark Wagner 2019-02-13 18:03:41 UTC
(In reply to Mike Gilbert from comment #16)
> Send patches upstream.

I didn't send my patch upstream but I did create a bug report:

https://bugzilla.redhat.com/show_bug.cgi?id=1676988
Comment 18 Alexander Tsoy 2019-02-25 15:20:23 UTC
(In reply to Mike Gilbert from comment #13)
> Maybe Alexander can send a patch with rationale?
Sorry, I was on vacation. I'll look into it this week if I have time.
Comment 19 Martin Mokrejš 2019-03-15 09:48:08 UTC
Please block >=app-shells/bash-5.0 from within sys-kernel/dracut-049 until a fix lands portage tree.
Comment 20 Mike Gilbert gentoo-dev 2019-03-15 14:38:28 UTC
(In reply to Martin Mokrejš from comment #19)
> Please block >=app-shells/bash-5.0 from within sys-kernel/dracut-049 until a
> fix lands portage tree.

I hesitate to do that because only a subset of dracut users are affected. Anyone using the systemd module does not run into the problem.
Comment 21 Alexander Tsoy 2019-03-21 14:18:56 UTC
Please try with app-shells/bash-5.0_p3-r1
Comment 22 James Le Cuirot gentoo-dev 2019-03-21 22:37:57 UTC
(In reply to Alexander Tsoy from comment #21)
> Please try with app-shells/bash-5.0_p3-r1

That fixed it for me!
Comment 23 Martin Mokrejš 2019-03-22 07:46:20 UTC
(In reply to Alexander Tsoy from comment #21)
> Please try with app-shells/bash-5.0_p3-r1

Fixed for me too.
Comment 24 Larry the Git Cow gentoo-dev 2019-12-29 19:39:52 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=980830b7e4a2953550338f13dd8525bcad28d8fc

commit 980830b7e4a2953550338f13dd8525bcad28d8fc
Author:     Alexander Tsoy <alexander@tsoy.me>
AuthorDate: 2019-12-26 14:26:15 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2019-12-29 19:36:23 +0000

    sys-kernel/dracut: Add a bunch of upstream patches
    
    * fix dracut-install crashes
    * install kernel module dependencies of dependencies
    * add support for compressed firmware files
    * add support for rngd service
    * bash-5 compatibility
    * add fts-standalone dependency and configure check for musl
    * fix udevdir detection
    
    Closes: https://bugs.gentoo.org/676268
    Closes: https://bugs.gentoo.org/677788
    Closes: https://bugs.gentoo.org/687602
    Bug: https://bugs.gentoo.org/703438
    Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 sys-kernel/dracut/dracut-049-r3.ebuild             | 176 +++++++++++++++++++++
 ...gure-find-cflags-and-libs-for-fts-on-musl.patch |  97 ++++++++++++
 ...t-create-locking-directory-run-cryptsetup.patch |  32 ++++
 ...all-Support-the-compressed-firmware-files.patch |  63 ++++++++
 .../049-dracut.sh-Fix-udevdir-detection.patch      |  38 +++++
 .../dracut/files/049-fs-lib-drop-a-bashism.patch   |  99 ++++++++++++
 ...cut-install.c-install-module-dependencies.patch |  79 +++++++++
 ...ing_hash_func-should-not-be-fed-with-NULL.patch |  38 +++++
 ...g-the-systemdutildir-variable-before-it-s.patch |  55 +++++++
 ...ager-call-the-online-hook-for-connected-d.patch |  32 ++++
 ...ager-fix-getting-of-ifname-from-the-sysfs.patch |  37 +++++
 ...rk-manager-remove-useless-use-of-basename.patch |  26 +++
 ...dule-running-early-during-boot-to-help-ge.patch |  88 +++++++++++
 13 files changed, 860 insertions(+)