Skip to content

kernel-install: support the case /etc/machine-id is missing or empty#5975

Merged
keszybz merged 1 commit intosystemd:masterfrom
yuwata:kernel-install
May 30, 2017
Merged

kernel-install: support the case /etc/machine-id is missing or empty#5975
keszybz merged 1 commit intosystemd:masterfrom
yuwata:kernel-install

Conversation

@yuwata
Copy link
Copy Markdown
Member

@yuwata yuwata commented May 17, 2017

Some plugins does not require non-empty /etc/machine-id such as
20-grubby.install for Fedora and 50-depmod.install.
To support such plugins to run without valid machine-id, let's remove to check
if MACHINE_ID variable is empty or not.
This may be useful for installing kernel for e.g. stateless systems
which initialize machine-id at booting the systems.

@poettering
Copy link
Copy Markdown
Member

Supporting stateless systems definitely makes sense to me, but this patch is too simple. For example, for BOOT_DIR_ABS we should carefully come up with alternative paths if machine ID is not set.

Moreover 90-loaderentry.install should really be changed accordingly, too.

@poettering poettering added kernel-install reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 17, 2017
@yuwata
Copy link
Copy Markdown
Member Author

yuwata commented May 18, 2017

Thank you for the review. In the updated version, if machine ID is not set or ESP is not detected, BOOT_DIR_ABS is set to /boot. And 90-loaderentry.install does nothing if BOOT_DIR_ABS is /boot.
What do you think this approach?

@keszybz keszybz removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label May 19, 2017
@keszybz
Copy link
Copy Markdown
Member

keszybz commented May 19, 2017

I don't think this is going to fly. There are external scripts, even possibly custom scripts that admins added, and we cannot just set BOOT_DIR_ABS to an existing directory and hope for the best. Something that is backwards compatible must be invented.

I'd propose the following:

  • run the .install helpers with an environment variable set (KERNEL_INSTALL_MACHINE_ID=...), that'd be empty if /etc/machine-id is missing.
  • create a temporary directory to call the scripts with (mktemp -d ...) when /etc/machine-id is missing, and use that as BOOT_DIR_ABS argument.

Then any script could check for defined-but-empty $KERNEL_INSTALL_MACHINE_ID (using [[ -z ${KERNEL_INSTALL_MACHINE_ID+x} ]] to differentiate older kernel-install versions that simply do not set the variable), and in that case assume that BOOT_DIR_ABS is fake, and skip the parts that require BOOT_DIR_ABS.

Then 90-loaderentry.install would be updated along the lines you proposed, but with the updated condition.

This way we would keep existing scripts happy, and allow updated scripts to be smart. Unupdated scripts would do some pointless work, but at least they would not wreck any existing directory.

@yuwata
Copy link
Copy Markdown
Member Author

yuwata commented May 24, 2017

@keszybz Thank you for your comments. I've updated the patch along with your suggestion. Please take a look.

@yuwata yuwata changed the title kernel-install: do not exit if /etc/machine-id is empty or does not exist kernel-install: support the case /etc/machine-id is missing or empty May 25, 2017
if [[ ${KERNEL_INSTALL_MACHINE_ID+x} ]]; then
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
elif [[ -f /etc/machine-id ]]; then
read MACHINE_ID < /etc/machine-id
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to read machine-id here? kernel-install already did that for us, so the elif can be dropped.


if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
if ! [[ $MACHINE_ID ]]; then
BOOT_DIR_ABS=$(mktemp -d /tmp/kernel-install.XXXXX) || exit 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will "leak" the temporary directory on each premature exit, e.g. when kernel-install add is called without the proper arguments. Please install the cleanup function in a trap, see https://github.com/systemd/systemd/blob/master/test/hwdb-test.sh#L32.

@yuwata
Copy link
Copy Markdown
Member Author

yuwata commented May 26, 2017

@keszybz Thank you for the review. Updated.

@poettering
Copy link
Copy Markdown
Member

@haraldh can you comment as well?

@haraldh
Copy link
Copy Markdown
Member

haraldh commented May 29, 2017

looks ok.. although the mktemp is ugly

@keszybz
Copy link
Copy Markdown
Member

keszybz commented May 30, 2017

I think we should announce that requiring BOOT_DIR to be present is deprecated for scripts, then wait two releases, then warn if the scripts put anything in BOOT_DIR, and then stop setting after two more releases. This should give us the new semantics without breaking compatibility too quickly.

@yuwata yuwata force-pushed the kernel-install branch 2 times, most recently from 560235c to ca52601 Compare May 30, 2017 06:56
Some .install plugins does not require that machine ID is set such as
20-grubby.install for Fedora and 50-depmod.install.
To support such plugins to run without valid machine-id, this commit
makes the following change:
* if /etc/machine-id is missing or empty, create temporary directory
  and set its path to BOOT_DIR_ABS,
* run the .install helpers with KERNEL_INSTALL_MACHINE_ID environment
  variable that'd be empty if /etc/machine-id is missing or empty.
This may be useful for installing kernel for e.g. stateless systems
which initialize machine-id while booting the systems.
@yuwata
Copy link
Copy Markdown
Member Author

yuwata commented May 30, 2017

Updated. I've added a warning message if the temporary directory is not empty and a news entry.

@keszybz
Copy link
Copy Markdown
Member

keszybz commented May 30, 2017

Looks nice.

@keszybz keszybz merged commit 9d8813b into systemd:master May 30, 2017
@yuwata yuwata deleted the kernel-install branch November 12, 2017 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants