summaryrefslogtreecommitdiff
path: root/src/boot/bootctl.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-08 16:33:57 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-12 09:45:16 +0100
commit341890de866f2ee34919a47ce3fc6c8cd3c1924c (patch)
treee891052e4298d6087ef31da809c3240d44543724 /src/boot/bootctl.c
parentd271c5d345f25d9b49f929d620df47f21968886d (diff)
downloadsystemd-341890de866f2ee34919a47ce3fc6c8cd3c1924c.tar.gz
bootctl: create $BOOT/<machine-id> when installing sd-boot
Diffstat (limited to 'src/boot/bootctl.c')
-rw-r--r--src/boot/bootctl.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index b5f4b8e5a3..ff830dc745 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -35,6 +35,7 @@
#include "pretty-print.h"
#include "rm-rf.h"
#include "stat-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
@@ -885,11 +886,10 @@ static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
return 0;
}
-static int install_loader_config(const char *esp_path) {
+static int install_loader_config(const char *esp_path, sd_id128_t machine_id) {
char machine_string[SD_ID128_STRING_MAX];
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_fclose_ FILE *f = NULL;
- sd_id128_t machine_id;
const char *p;
int r, fd;
@@ -897,10 +897,6 @@ static int install_loader_config(const char *esp_path) {
if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
return 0;
- r = sd_id128_get_machine(&machine_id);
- if (r < 0)
- return log_error_errno(r, "Failed to get machine id: %m");
-
fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
if (fd < 0)
return log_error_errno(fd, "Failed to open \"%s\" for writing: %m", p);
@@ -929,10 +925,21 @@ static int install_loader_config(const char *esp_path) {
return 1;
}
-static int install_entries_directory(const char *dollar_boot_path) {
+static int install_entries_directories(const char *dollar_boot_path, sd_id128_t machine_id) {
+ int r;
+ char buf[SD_ID128_STRING_MAX];
+
assert(dollar_boot_path);
- return mkdir_one(dollar_boot_path, "/loader/entries");
+ /* Both /loader/entries and the entry directories themselves should be located on the same
+ * partition. Also create the parent directory for entry directories, so that kernel-install
+ * knows where to put them. */
+
+ r = mkdir_one(dollar_boot_path, "/loader/entries");
+ if (r < 0)
+ return r;
+
+ return mkdir_one(dollar_boot_path, sd_id128_to_string(machine_id, buf));
}
static int help(int argc, char *argv[], void *userdata) {
@@ -1243,6 +1250,7 @@ static int verb_install(int argc, char *argv[], void *userdata) {
sd_id128_t uuid = SD_ID128_NULL;
uint64_t pstart = 0, psize = 0;
uint32_t part = 0;
+ sd_id128_t machine_id;
bool install;
int r;
@@ -1254,6 +1262,10 @@ static int verb_install(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
+ r = sd_id128_get_machine(&machine_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get machine id: %m");
+
install = streq(argv[0], "install");
RUN_WITH_UMASK(0002) {
@@ -1271,11 +1283,11 @@ static int verb_install(int argc, char *argv[], void *userdata) {
return r;
if (install) {
- r = install_loader_config(arg_esp_path);
+ r = install_loader_config(arg_esp_path, machine_id);
if (r < 0)
return r;
- r = install_entries_directory(arg_dollar_boot_path());
+ r = install_entries_directories(arg_dollar_boot_path(), machine_id);
if (r < 0)
return r;
}
@@ -1400,7 +1412,7 @@ static int run(int argc, char *argv[]) {
log_parse_environment();
log_open();
- /* If we run in a container, automatically turn of EFI file system access */
+ /* If we run in a container, automatically turn off EFI file system access */
if (detect_container() > 0)
arg_touch_variables = false;