Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use a machine-id value of uninitialized #2267

Closed
Cornelicorn opened this issue Mar 6, 2023 · 6 comments · Fixed by #2271
Closed

Do not use a machine-id value of uninitialized #2267

Cornelicorn opened this issue Mar 6, 2023 · 6 comments · Fixed by #2271
Labels
bug Our bugs

Comments

@Cornelicorn
Copy link
Contributor

Describe the bug
systemd supports writing uninitialized to /etc/machine-id, which can be used for systemd-firstboot instead of removing /etc/machine-id. Dracut does not check the contents of this file to populate MACHINE_ID, so the value unitialized is used

Distribution used
Debian bookworm (12)

Dracut version
059

Init system
systemd

To Reproduce

echo "uninitialized" > /etc/machine-id
dracut -f

Expected behavior
Dracut behaves as if there was no machine-id set, i.e. setting MACHINE_ID="Default".

Additional context

@Cornelicorn Cornelicorn added the bug Our bugs label Mar 6, 2023
@aafeijoo-suse
Copy link
Member

See #1873 (comment)

@Cornelicorn
Copy link
Contributor Author

See #1873 (comment)

This issue is about /etc/machine-id on the host system, not /etc/machine-id inside the initrd.

@LaszloGombos
Copy link
Collaborator

@Cornelicorn

Expected behavior
Dracut behaves as if there was no machine-id set, i.e. setting MACHINE_ID="Default".

From your POV would it be appropriate to make $initdir/etc/machine-id and empty file instead setting MACHINE_ID="Default".

@Cornelicorn
Copy link
Contributor Author

I think the reproducer would have been clearer with dracut --uefi -f, my bad.

In [dracut.sh[(https://github.com/dracutdevs/dracut/blob/master/dracut.sh#L1086#L1094), MACHINE_ID is set to the value of /etc/machine-id if ESPDIR/Default is not a directory.
My suggestion would be to only do this if the value is not uninitialized, e.g.

if [[ -d /efi/Default ]] || [[ -d /boot/Default ]] || [[ -d /boot/efi/Default ]]; then
    MACHINE_ID="Default"
elif [[ -f /etc/machine-id ]]; then
    read -r MACHINE_ID < /etc/machine-id
    if [[ "$MACHINE_ID" == uninitialized ]]; then
        MACHINE_ID="Default"
    fi
else
    MACHINE_ID="Default"
fi

Even better would be a regex check that's it's actually an UUID, the value uninitialized or empty and in the latter two cases use MACHINE_ID="Default".

@Cornelicorn
Copy link
Contributor Author

As far as I can tell, the value of MACHINE_ID never ends up in the initrd itself, only in the filename.

@aafeijoo-suse
Copy link
Member

Thanks for your further explanation, now the issue is clear.

aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this issue Mar 7, 2023
Handle the case where the user tries to generate the initrd after explicitly
resetting the /etc/machine-id file.

Fixes issue dracutdevs#2267
johannbg pushed a commit that referenced this issue Apr 26, 2023
Handle the case where the user tries to generate the initrd after explicitly
resetting the /etc/machine-id file.

Fixes issue #2267
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this issue Jun 15, 2023
Handle the case where the user tries to generate the initrd after explicitly
resetting the /etc/machine-id file.

Fixes issue dracutdevs#2267

(cherry picked from commit 97fe097)
pvalena pushed a commit to pvalena/dracut that referenced this issue Jul 23, 2023
Handle the case where the user tries to generate the initrd after explicitly
resetting the /etc/machine-id file.

Fixes issue dracutdevs#2267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Our bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants