Skip to content

fix(fs-lib): append root fstab entry only when missing - #2600

Open
prabhakarpujeri wants to merge 1 commit into
dracut-ng:mainfrom
prabhakarpujeri:fix/fs-lib-write-fs-tab
Open

fix(fs-lib): append root fstab entry only when missing#2600
prabhakarpujeri wants to merge 1 commit into
dracut-ng:mainfrom
prabhakarpujeri:fix/fs-lib-write-fs-tab

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Problem

Commit b12f818 ("feat(nbd): support ipv6 link local nbds") changed the previously unconditional append in write_fs_tab() into a conditional — to avoid duplicate entries — but inverted the test:

if grep -q "$_root /sysroot" /etc/fstab; then
    echo "$_root /sysroot ..." >> /etc/fstab
else
    return
fi

As a result:

  • Normal case (entry absent): the function returns early and the /sysroot entry is never added to the initramfs fstab.
  • Already-present case (e.g. a iscsi/nbd hook runs twice): the entry is appended again, creating a duplicate.

Callers in the iscsi and nbd modules (iscsiroot.sh, parse-iscsiroot.sh, nbdroot.sh) rely on write_fs_tab() to record the root filesystem with the resolved rootfstype/rootflags and to trigger daemon-reload + initrd-root-fs.target.

Fix

Negate the test so the entry is appended exactly when it is missing, and drop the now-pointless else return. This preserves the original de-duplication intent of b12f818.

Testing

Sandboxed harness executing the real write_fs_tab() (old from git show HEAD:, new from the working tree), with /etc/fstab repointed to a scratch file:

case before after
entry missing nothing written one correct entry (auto ro,x-initrd.mount 0 0)
entry pre-seeded duplicate appended still exactly one entry
rw on cmdline ro,x-initrd.mount,rw

shellcheck modules.d/70fs-lib/fs-lib.sh clean.

Fixes: b12f818 ("feat(nbd): support ipv6 link local nbds")

@prabhakarpujeri
prabhakarpujeri requested a review from a team as a code owner August 17, 2026 08:43
@github-actions github-actions Bot added fs-lib Issues related to the fs-lib module modules Issue tracker for all modules labels Aug 17, 2026
@devkontrol

Copy link
Copy Markdown
Collaborator

CC @mwilck

Commit b12f818 ("feat(nbd): support ipv6 link local nbds") changed
the previously unconditional append in write_fs_tab() into a
conditional to avoid duplicate entries, but inverted the test: the
/sysroot entry is appended only when it is already present (creating
duplicates), and the function returns early in the normal case where
it is absent, so the entry is never written.

Callers in the iscsi and nbd modules rely on write_fs_tab() to record
the root filesystem in the initramfs fstab with the resolved
rootfstype/rootflags and to trigger daemon-reload and
initrd-root-fs.target.

Negate the grep test so the entry is appended exactly when it is
missing, preserving the intended de-duplication.

Verified in a sandboxed harness running the extracted function: with
an empty fstab the old code writes nothing while the new code appends
one correct entry; with a pre-existing entry the old code duplicates
it while the new code keeps exactly one.

Fixes: b12f818 ("feat(nbd): support ipv6 link local nbds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs-lib Issues related to the fs-lib module modules Issue tracker for all modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants