bootctl: create $BOOT/<machine-id> when installing sd-boot

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-03-08 16:33:57 +01:00
parent d271c5d345
commit 341890de86

View file

@ -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;