mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-08-29 01:50:15 +03:00
bootctl: load /etc/kernel/install.conf's $layout field, too
bootctl so far tried to determine the layout from /etc/machine-info, but that's obsolete, and the kernel-install script never looked there. Let's read the setting from /etc/kernel/install.conf instead, where kernel-install actually looks. Support for reading the field from /etc/machine-info is retained for compat. This means we'll now read /etc/machine-id, /etc/machine-info and /etc/kernel/install.conf, and read the machine ID from the former too and the layout setting from the latter two.
This commit is contained in:
@ -144,7 +144,20 @@ static int acquire_xbootldr(
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_install_machine_id_and_layout(void) {
|
static int load_etc_machine_id(void) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = sd_id128_get_machine(&arg_machine_id);
|
||||||
|
if (IN_SET(r, -ENOENT, -ENOMEDIUM)) /* Not set or empty */
|
||||||
|
return 0;
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to get machine-id: %m");
|
||||||
|
|
||||||
|
log_debug("Loaded machine ID %s from /etc/machine-id.", SD_ID128_TO_STRING(arg_machine_id));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int load_etc_machine_info(void) {
|
||||||
/* systemd v250 added support to store the kernel-install layout setting and the machine ID to use
|
/* systemd v250 added support to store the kernel-install layout setting and the machine ID to use
|
||||||
* for setting up the ESP in /etc/machine-info. The newer /etc/kernel/entry-token file, as well as
|
* for setting up the ESP in /etc/machine-info. The newer /etc/kernel/entry-token file, as well as
|
||||||
* the $layout field in /etc/kernel/install.conf are better replacements for this though, hence this
|
* the $layout field in /etc/kernel/install.conf are better replacements for this though, hence this
|
||||||
@ -155,30 +168,46 @@ static int load_install_machine_id_and_layout(void) {
|
|||||||
r = parse_env_file(NULL, "/etc/machine-info",
|
r = parse_env_file(NULL, "/etc/machine-info",
|
||||||
"KERNEL_INSTALL_LAYOUT", &layout,
|
"KERNEL_INSTALL_LAYOUT", &layout,
|
||||||
"KERNEL_INSTALL_MACHINE_ID", &s);
|
"KERNEL_INSTALL_MACHINE_ID", &s);
|
||||||
if (r < 0 && r != -ENOENT)
|
if (r == -ENOENT)
|
||||||
|
return 0;
|
||||||
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to parse /etc/machine-info: %m");
|
return log_error_errno(r, "Failed to parse /etc/machine-info: %m");
|
||||||
|
|
||||||
if (isempty(s)) {
|
if (!isempty(s)) {
|
||||||
r = sd_id128_get_machine(&arg_machine_id);
|
|
||||||
if (r < 0 && !IN_SET(r, -ENOENT, -ENOMEDIUM))
|
|
||||||
return log_error_errno(r, "Failed to get machine-id: %m");
|
|
||||||
} else {
|
|
||||||
log_notice("Read $KERNEL_INSTALL_MACHINE_ID from /etc/machine-info. Please move it to /etc/kernel/entry-token.");
|
log_notice("Read $KERNEL_INSTALL_MACHINE_ID from /etc/machine-info. Please move it to /etc/kernel/entry-token.");
|
||||||
|
|
||||||
r = sd_id128_from_string(s, &arg_machine_id);
|
r = sd_id128_from_string(s, &arg_machine_id);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to parse KERNEL_INSTALL_MACHINE_ID=%s in /etc/machine-info: %m", s);
|
return log_error_errno(r, "Failed to parse KERNEL_INSTALL_MACHINE_ID=%s in /etc/machine-info: %m", s);
|
||||||
|
|
||||||
|
log_debug("Loaded KERNEL_INSTALL_MACHINE_ID=%s from KERNEL_INSTALL_MACHINE_ID in /etc/machine-info.",
|
||||||
|
SD_ID128_TO_STRING(arg_machine_id));
|
||||||
}
|
}
|
||||||
log_debug("Using KERNEL_INSTALL_MACHINE_ID=%s from %s.",
|
|
||||||
SD_ID128_TO_STRING(arg_machine_id),
|
|
||||||
isempty(s) ? "/etc/machine_id" : "KERNEL_INSTALL_MACHINE_ID in /etc/machine-info");
|
|
||||||
|
|
||||||
if (!isempty(layout)) {
|
if (!isempty(layout)) {
|
||||||
log_notice("Read $KERNEL_INSTALL_LAYOUT from /etc/machine-info. Please move it to the layout= setting of /etc/kernel/install.conf.");
|
log_notice("Read $KERNEL_INSTALL_LAYOUT from /etc/machine-info. Please move it to the layout= setting of /etc/kernel/install.conf.");
|
||||||
|
|
||||||
log_debug("KERNEL_INSTALL_LAYOUT=%s is specified in /etc/machine-info.", layout);
|
log_debug("KERNEL_INSTALL_LAYOUT=%s is specified in /etc/machine-info.", layout);
|
||||||
arg_install_layout = TAKE_PTR(layout);
|
free_and_replace(arg_install_layout, layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int load_etc_kernel_install_conf(void) {
|
||||||
|
_cleanup_free_ char *layout = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = parse_env_file(NULL, "/etc/kernel/install.conf",
|
||||||
|
"layout", &layout);
|
||||||
|
if (r == -ENOENT)
|
||||||
|
return 0;
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to parse /etc/kernel/install.conf: %m");
|
||||||
|
|
||||||
|
if (!isempty(layout)) {
|
||||||
|
log_debug("layout=%s is specified in /etc/machine-info.", layout);
|
||||||
|
free_and_replace(arg_install_layout, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -285,7 +314,15 @@ static bool use_boot_loader_spec_type1(void) {
|
|||||||
static int settle_make_entry_directory(void) {
|
static int settle_make_entry_directory(void) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = load_install_machine_id_and_layout();
|
r = load_etc_machine_id();
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = load_etc_machine_info();
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = load_etc_kernel_install_conf();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user