X Tutup
Skip to content

Commit 341890d

Browse files
committed
bootctl: create $BOOT/<machine-id> when installing sd-boot
1 parent d271c5d commit 341890d

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/boot/bootctl.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "pretty-print.h"
3636
#include "rm-rf.h"
3737
#include "stat-util.h"
38+
#include "stdio-util.h"
3839
#include "string-util.h"
3940
#include "strv.h"
4041
#include "terminal-util.h"
@@ -885,22 +886,17 @@ static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
885886
return 0;
886887
}
887888

888-
static int install_loader_config(const char *esp_path) {
889+
static int install_loader_config(const char *esp_path, sd_id128_t machine_id) {
889890
char machine_string[SD_ID128_STRING_MAX];
890891
_cleanup_(unlink_and_freep) char *t = NULL;
891892
_cleanup_fclose_ FILE *f = NULL;
892-
sd_id128_t machine_id;
893893
const char *p;
894894
int r, fd;
895895

896896
p = strjoina(esp_path, "/loader/loader.conf");
897897
if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
898898
return 0;
899899

900-
r = sd_id128_get_machine(&machine_id);
901-
if (r < 0)
902-
return log_error_errno(r, "Failed to get machine id: %m");
903-
904900
fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
905901
if (fd < 0)
906902
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) {
929925
return 1;
930926
}
931927

932-
static int install_entries_directory(const char *dollar_boot_path) {
928+
static int install_entries_directories(const char *dollar_boot_path, sd_id128_t machine_id) {
929+
int r;
930+
char buf[SD_ID128_STRING_MAX];
931+
933932
assert(dollar_boot_path);
934933

935-
return mkdir_one(dollar_boot_path, "/loader/entries");
934+
/* Both /loader/entries and the entry directories themselves should be located on the same
935+
* partition. Also create the parent directory for entry directories, so that kernel-install
936+
* knows where to put them. */
937+
938+
r = mkdir_one(dollar_boot_path, "/loader/entries");
939+
if (r < 0)
940+
return r;
941+
942+
return mkdir_one(dollar_boot_path, sd_id128_to_string(machine_id, buf));
936943
}
937944

938945
static int help(int argc, char *argv[], void *userdata) {
@@ -1243,6 +1250,7 @@ static int verb_install(int argc, char *argv[], void *userdata) {
12431250
sd_id128_t uuid = SD_ID128_NULL;
12441251
uint64_t pstart = 0, psize = 0;
12451252
uint32_t part = 0;
1253+
sd_id128_t machine_id;
12461254
bool install;
12471255
int r;
12481256

@@ -1254,6 +1262,10 @@ static int verb_install(int argc, char *argv[], void *userdata) {
12541262
if (r < 0)
12551263
return r;
12561264

1265+
r = sd_id128_get_machine(&machine_id);
1266+
if (r < 0)
1267+
return log_error_errno(r, "Failed to get machine id: %m");
1268+
12571269
install = streq(argv[0], "install");
12581270

12591271
RUN_WITH_UMASK(0002) {
@@ -1271,11 +1283,11 @@ static int verb_install(int argc, char *argv[], void *userdata) {
12711283
return r;
12721284

12731285
if (install) {
1274-
r = install_loader_config(arg_esp_path);
1286+
r = install_loader_config(arg_esp_path, machine_id);
12751287
if (r < 0)
12761288
return r;
12771289

1278-
r = install_entries_directory(arg_dollar_boot_path());
1290+
r = install_entries_directories(arg_dollar_boot_path(), machine_id);
12791291
if (r < 0)
12801292
return r;
12811293
}
@@ -1400,7 +1412,7 @@ static int run(int argc, char *argv[]) {
14001412
log_parse_environment();
14011413
log_open();
14021414

1403-
/* If we run in a container, automatically turn of EFI file system access */
1415+
/* If we run in a container, automatically turn off EFI file system access */
14041416
if (detect_container() > 0)
14051417
arg_touch_variables = false;
14061418

0 commit comments

Comments
 (0)
X Tutup