kernel-install: support the case /etc/machine-id is missing or empty#5975
kernel-install: support the case /etc/machine-id is missing or empty#5975keszybz merged 1 commit intosystemd:masterfrom
Conversation
|
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. |
|
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. |
|
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:
Then any script could check for defined-but-empty $KERNEL_INSTALL_MACHINE_ID (using 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. |
|
@keszybz Thank you for your comments. I've updated the patch along with your suggestion. Please take a look. |
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
@keszybz Thank you for the review. Updated. |
|
@haraldh can you comment as well? |
|
looks ok.. although the mktemp is ugly |
|
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. |
560235c to
ca52601
Compare
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.
|
Updated. I've added a warning message if the temporary directory is not empty and a news entry. |
|
Looks nice. |
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_IDvariable is empty or not.This may be useful for installing kernel for e.g. stateless systems
which initialize machine-id at booting the systems.