• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 24697298032

20 Apr 2026 09:22PM UTC coverage: 72.23% (+1.6%) from 70.661%
24697298032

push

github

bluca
sysupdate: Emit READY=1 status when installing

`READY=1` is already correctly emitted when acquiring an update, but was
forgotten to be emitted when subsequently installing that update.

That meant that the state tracking code in `sysupdated` and hence
`updatectl` could not properly report the progress of the install
operation, and hence printed “Already up-to-date” after a successful
update installation, rather than “Done”.

Add a test to catch this in future.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: https://github.com/systemd/systemd/issues/41502

322667 of 446720 relevant lines covered (72.23%)

1191594.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.93
/src/bootctl/bootctl.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <sys/stat.h>
4

5
#include "sd-varlink.h"
6

7
#include "blockdev-util.h"
8
#include "boot-entry.h"
9
#include "bootctl.h"
10
#include "bootctl-cleanup.h"
11
#include "bootctl-install.h"
12
#include "bootctl-random-seed.h"
13
#include "bootctl-reboot-to-firmware.h"
14
#include "bootctl-set-efivar.h"
15
#include "bootctl-status.h"
16
#include "bootctl-uki.h"
17
#include "bootctl-unlink.h"
18
#include "bootctl-util.h"
19
#include "build.h"
20
#include "devnum-util.h"
21
#include "dissect-image.h"
22
#include "efi-loader.h"
23
#include "efivars.h"
24
#include "escape.h"
25
#include "fd-util.h"
26
#include "find-esp.h"
27
#include "format-table.h"
28
#include "image-policy.h"
29
#include "log.h"
30
#include "loop-util.h"
31
#include "main-func.h"
32
#include "mount-util.h"
33
#include "openssl-util.h"
34
#include "options.h"
35
#include "pager.h"
36
#include "parse-argument.h"
37
#include "path-util.h"
38
#include "pretty-print.h"
39
#include "string-table.h"
40
#include "string-util.h"
41
#include "strv.h"
42
#include "utf8.h"
43
#include "varlink-io.systemd.BootControl.h"
44
#include "varlink-util.h"
45
#include "verbs.h"
46
#include "virt.h"
47

48
static GracefulMode _arg_graceful = ARG_GRACEFUL_NO;
49

50
char *arg_esp_path = NULL;
51
char *arg_xbootldr_path = NULL;
52
bool arg_print_esp_path = false;
53
bool arg_print_dollar_boot_path = false;
54
bool arg_print_loader_path = false;
55
bool arg_print_stub_path = false;
56
bool arg_print_efi_architecture = false;
57
unsigned arg_print_root_device = 0;
58
int arg_touch_variables = -1;
59
bool arg_install_random_seed = true;
60
PagerFlags arg_pager_flags = 0;
61
bool arg_quiet = false;
62
int arg_make_entry_directory = false; /* tri-state: < 0 for automatic logic */
63
sd_id128_t arg_machine_id = SD_ID128_NULL;
64
char *arg_install_layout = NULL;
65
BootEntryTokenType arg_entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
66
char *arg_entry_token = NULL;
67
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
68
bool arg_arch_all = false;
69
char *arg_root = NULL;
70
char *arg_image = NULL;
71
InstallSource arg_install_source = INSTALL_SOURCE_AUTO;
72
char *arg_efi_boot_option_description = NULL;
73
bool arg_efi_boot_option_description_with_device = false;
74
bool arg_dry_run = false;
75
ImagePolicy *arg_image_policy = NULL;
76
bool arg_varlink = false;
77
bool arg_secure_boot_auto_enroll = false;
78
char *arg_certificate = NULL;
79
CertificateSourceType arg_certificate_source_type = OPENSSL_CERTIFICATE_SOURCE_FILE;
80
char *arg_certificate_source = NULL;
81
char *arg_private_key = NULL;
82
KeySourceType arg_private_key_source_type = OPENSSL_KEY_SOURCE_FILE;
83
char *arg_private_key_source = NULL;
84

85
STATIC_DESTRUCTOR_REGISTER(arg_esp_path, freep);
307✔
86
STATIC_DESTRUCTOR_REGISTER(arg_xbootldr_path, freep);
307✔
87
STATIC_DESTRUCTOR_REGISTER(arg_install_layout, freep);
307✔
88
STATIC_DESTRUCTOR_REGISTER(arg_entry_token, freep);
307✔
89
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
307✔
90
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
307✔
91
STATIC_DESTRUCTOR_REGISTER(arg_efi_boot_option_description, freep);
307✔
92
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
307✔
93
STATIC_DESTRUCTOR_REGISTER(arg_certificate, freep);
307✔
94
STATIC_DESTRUCTOR_REGISTER(arg_certificate_source, freep);
307✔
95
STATIC_DESTRUCTOR_REGISTER(arg_private_key, freep);
307✔
96
STATIC_DESTRUCTOR_REGISTER(arg_private_key_source, freep);
307✔
97

98
static const char* const install_source_table[_INSTALL_SOURCE_MAX] = {
99
        [INSTALL_SOURCE_IMAGE] = "image",
100
        [INSTALL_SOURCE_HOST]  = "host",
101
        [INSTALL_SOURCE_AUTO]  = "auto",
102
};
103

104
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(install_source, InstallSource);
×
105

106
int acquire_esp(int unprivileged_mode,
263✔
107
                bool graceful,
108
                int *ret_fd,
109
                uint32_t *ret_part,
110
                uint64_t *ret_pstart,
111
                uint64_t *ret_psize,
112
                sd_id128_t *ret_uuid,
113
                dev_t *ret_devid) {
114

115
        _cleanup_free_ char *np = NULL;
263✔
116
        int r;
263✔
117

118
        /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on
119
         * its own, except for ENOKEY (which is good, we want to show our own message in that case,
120
         * suggesting use of --esp-path=) and EACCESS (only when we request unprivileged mode; in this case
121
         * we simply eat up the error here, so that --list and --status work too, without noise about
122
         * this). */
123

124
        r = find_esp_and_warn_full(arg_root, arg_esp_path, unprivileged_mode, &np, ret_fd, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
263✔
125
        if (r == -ENOKEY) {
263✔
126
                if (graceful)
5✔
127
                        return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_INFO, r,
×
128
                                              "Couldn't find EFI system partition, skipping.");
129

130
                return log_error_errno(r,
5✔
131
                                       "Couldn't find EFI system partition. It is recommended to mount it to /boot/ or /efi/.\n"
132
                                       "Alternatively, use --esp-path= to specify path to mount point.");
133
        }
134
        if (r < 0)
258✔
135
                return r;
136

137
        free_and_replace(arg_esp_path, np);
257✔
138
        log_debug("Using EFI System Partition at %s.", arg_esp_path);
257✔
139

140
        return 1; /* for symmetry with acquire_xbootldr() below: found */
141
}
142

143
int acquire_xbootldr(
207✔
144
                int unprivileged_mode,
145
                int *ret_fd,
146
                sd_id128_t *ret_uuid,
147
                dev_t *ret_devid) {
148

149
        int r;
207✔
150

151
        _cleanup_free_ char *np = NULL;
207✔
152
        _cleanup_close_ int fd = -EBADF;
207✔
153
        r = find_xbootldr_and_warn_full(
247✔
154
                        arg_root,
155
                        arg_xbootldr_path,
156
                        unprivileged_mode,
157
                        &np,
158
                        ret_fd ? &fd : NULL,
159
                        ret_uuid,
160
                        ret_devid);
161
        if (r == -ENOKEY || (r >= 0 && arg_esp_path && path_equal(np, arg_esp_path))) {
207✔
162

163
                if (arg_esp_path)
160✔
164
                        log_debug("Didn't find an XBOOTLDR partition, using the ESP as $BOOT.");
159✔
165
                else
166
                        log_debug("Found neither an XBOOTLDR partition, nor an ESP.");
1✔
167

168
                arg_xbootldr_path = mfree(arg_xbootldr_path);
160✔
169

170
                if (ret_fd)
160✔
171
                        *ret_fd = -EBADF;
139✔
172
                if (ret_uuid)
160✔
173
                        *ret_uuid = SD_ID128_NULL;
16✔
174
                if (ret_devid)
160✔
175
                        *ret_devid = 0;
21✔
176

177
                return 0; /* not found */
160✔
178
        }
179
        if (r < 0)
46✔
180
                return r;
181

182
        free_and_replace(arg_xbootldr_path, np);
46✔
183
        log_debug("Using XBOOTLDR partition at %s as $BOOT.", arg_xbootldr_path);
46✔
184

185
        if (ret_fd)
46✔
186
                *ret_fd = TAKE_FD(fd);
28✔
187

188
        return 1; /* found */
189
}
190

191
static int print_loader_or_stub_path(void) {
8✔
192
        _cleanup_free_ char *p = NULL;
8✔
193
        sd_id128_t uuid;
8✔
194
        int r;
8✔
195

196
        if (arg_print_loader_path) {
8✔
197
                r = efi_loader_get_device_part_uuid(&uuid);
1✔
198
                if (r == -ENOENT)
1✔
199
                        return log_error_errno(r, "No loader partition UUID passed.");
×
200
                if (r < 0)
1✔
201
                        return log_error_errno(r, "Unable to determine loader partition UUID: %m");
×
202

203
                r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("LoaderImageIdentifier"), &p);
1✔
204
                if (r == -ENOENT)
1✔
205
                        return log_error_errno(r, "No loader EFI binary path passed.");
×
206
                if (r < 0)
1✔
207
                        return log_error_errno(r, "Unable to determine loader EFI binary path: %m");
×
208
        } else {
209
                assert(arg_print_stub_path);
7✔
210

211
                r = efi_stub_get_device_part_uuid(&uuid);
7✔
212
                if (r == -ENOENT)
7✔
213
                        return log_error_errno(r, "No stub partition UUID passed.");
×
214
                if (r < 0)
7✔
215
                        return log_error_errno(r, "Unable to determine stub partition UUID: %m");
×
216

217
                r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("StubImageIdentifier"), &p);
7✔
218
                if (r == -ENOENT)
7✔
219
                        return log_error_errno(r, "No stub EFI binary path passed.");
×
220
                if (r < 0)
7✔
221
                        return log_error_errno(r, "Unable to determine stub EFI binary path: %m");
×
222
        }
223

224
        sd_id128_t esp_uuid;
8✔
225
        r = acquire_esp(/* unprivileged_mode= */ false,
8✔
226
                        /* graceful= */ false,
227
                        /* ret_fd= */ NULL,
228
                        /* ret_part= */ NULL,
229
                        /* ret_pstart= */ NULL,
230
                        /* ret_psize= */ NULL,
231
                        &esp_uuid,
232
                        /* ret_devid= */ NULL);
233
        if (r < 0)
8✔
234
                return r;
235

236
        const char *found_path = NULL;
8✔
237
        if (sd_id128_equal(esp_uuid, uuid))
8✔
238
                found_path = arg_esp_path;
8✔
239
        else if (arg_print_stub_path) { /* In case of the stub, also look for things in the xbootldr partition */
×
240
                sd_id128_t xbootldr_uuid;
×
241

242
                r = acquire_xbootldr(/* unprivileged_mode= */ false,
×
243
                                     /* ret_fd= */ NULL,
244
                                     &xbootldr_uuid,
245
                                     /* ret_devid= */ NULL);
246
                if (r < 0)
×
247
                        return r;
×
248

249
                if (sd_id128_equal(xbootldr_uuid, uuid))
×
250
                        found_path = arg_xbootldr_path;
×
251
        }
252

253
        if (!found_path)
8✔
254
                return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Failed to discover partition " SD_ID128_FORMAT_STR " among mounted boot partitions.", SD_ID128_FORMAT_VAL(uuid));
×
255

256
        _cleanup_free_ char *j = path_join(found_path, p);
16✔
257
        if (!j)
8✔
258
                return log_oom();
×
259

260
        puts(j);
8✔
261
        return 0;
262
}
263

264
GracefulMode arg_graceful(void) {
294✔
265
        static bool chroot_checked = false;
294✔
266

267
        if (!chroot_checked && running_in_chroot() > 0) {
294✔
268
                if (_arg_graceful == ARG_GRACEFUL_NO)
×
269
                        log_full(arg_quiet ? LOG_DEBUG : LOG_INFO, "Running in a chroot, enabling --graceful.");
×
270

271
                _arg_graceful = ARG_GRACEFUL_FORCE;
×
272
        }
273

274
        chroot_checked = true;
294✔
275

276
        return _arg_graceful;
294✔
277
}
278

279
static int help(void) {
3✔
280
        _cleanup_free_ char *link = NULL;
3✔
281
        int r;
3✔
282

283
        pager_open(arg_pager_flags);
3✔
284

285
        r = terminal_urlify_man("bootctl", "1", &link);
3✔
286
        if (r < 0)
3✔
287
                return log_oom();
×
288

289
        static const char *const verb_groups[] = {
3✔
290
                "Generic EFI Firmware/Boot Loader Commands",
291
                "Boot Loader Specification Commands",
292
                "Boot Loader Interface Commands",
293
                "systemd-boot Commands",
294
                "Kernel Image Commands",
295
        };
296

297
        static const char *const option_groups[] = {
3✔
298
                "Block Device Discovery Commands",
299
                "Options",
300
        };
301

302
        _cleanup_(table_unref_many) Table *verb_tables[ELEMENTSOF(verb_groups) + 1] = {};
3✔
303
        _cleanup_(table_unref_many) Table *option_tables[ELEMENTSOF(option_groups) + 1] = {};
3✔
304

305
        for (size_t i = 0; i < ELEMENTSOF(verb_groups); i++) {
18✔
306
                r = verbs_get_help_table_group(verb_groups[i], &verb_tables[i]);
15✔
307
                if (r < 0)
15✔
308
                        return r;
309
        }
310

311
        for (size_t i = 0; i < ELEMENTSOF(option_groups); i++) {
9✔
312
                r = option_parser_get_help_table_group(option_groups[i], &option_tables[i]);
6✔
313
                if (r < 0)
6✔
314
                        return r;
315
        }
316

317
        (void) table_sync_column_widths(0,
3✔
318
                                        verb_tables[0], verb_tables[1], verb_tables[2],
319
                                        verb_tables[3], verb_tables[4],
320
                                        option_tables[0], option_tables[1]);
321

322
        printf("%s [OPTIONS...] COMMAND ...\n"
6✔
323
               "\n%sControl EFI firmware boot settings and manage boot loader.%s\n",
324
               program_invocation_short_name,
325
               ansi_highlight(),
326
               ansi_normal());
327

328
        for (size_t i = 0; i < ELEMENTSOF(verb_groups); i++) {
18✔
329
                printf("\n%s%s:%s\n", ansi_underline(), verb_groups[i], ansi_normal());
45✔
330

331
                r = table_print_or_warn(verb_tables[i]);
15✔
332
                if (r < 0)
15✔
333
                        return r;
334
        }
335

336
        for (size_t i = 0; i < ELEMENTSOF(option_groups); i++) {
9✔
337
                printf("\n%s%s:%s\n", ansi_underline(), option_groups[i], ansi_normal());
18✔
338

339
                r = table_print_or_warn(option_tables[i]);
6✔
340
                if (r < 0)
6✔
341
                        return r;
342
        }
343

344
        printf("\nSee the %s for details.\n", link);
3✔
345
        return 0;
346
}
347

348
VERB_COMMON_HELP(help);
×
349

350
VERB_GROUP("Generic EFI Firmware/Boot Loader Commands");
351

352
VERB_SCOPE(, verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT,
353
           "Show status of installed boot loader and EFI variables");
354

355
VERB_SCOPE(, verb_reboot_to_firmware, "reboot-to-firmware", "[BOOL]", VERB_ANY, 2, 0,
356
           "Query or set reboot-to-firmware EFI flag");
357

358
VERB_GROUP("Boot Loader Specification Commands");
359

360
VERB_SCOPE_NOARG(, verb_list, "list",
361
           "List boot loader entries");
362

363
VERB_SCOPE(, verb_unlink, "unlink", "ID", 2, 2, 0,
364
           "Remove boot loader entry");
365

366
VERB_SCOPE_NOARG(, verb_cleanup, "cleanup",
367
           "Remove files in ESP not referenced in any boot entry");
368

369
VERB_GROUP("Boot Loader Interface Commands");
370

371
VERB_SCOPE(, verb_set_efivar, "set-default", "ID", 2, 2, 0,
372
           "Set default boot loader entry");
373

374
VERB_SCOPE(, verb_set_efivar, "set-oneshot", "ID", 2, 2, 0,
375
           "Set default boot loader entry, for next boot only");
376

377
VERB_SCOPE(, verb_set_efivar, "set-sysfail", "ID", 2, 2, 0,
378
           "Set boot loader entry used in case of a system failure");
379

380
VERB_SCOPE(, verb_set_efivar, "set-timeout", "SECONDS", 2, 2, 0,
381
           "Set the menu timeout");
382

383
VERB_SCOPE(, verb_set_efivar, "set-timeout-oneshot", "SECONDS", 2, 2, 0,
384
           "Set the menu timeout for the next boot only");
385

386
VERB_SCOPE(, verb_set_efivar, "set-preferred", "ID", 2, 2, 0,
387
           /* help= */ NULL);
388

389
VERB_GROUP("systemd-boot Commands");
390

391
VERB_SCOPE(, verb_install, "install", NULL, VERB_ANY, 1, 0,
392
           "Install systemd-boot to the ESP and EFI variables");
393

394
VERB_SCOPE(, verb_install, "update", NULL, VERB_ANY, 1, 0,
395
           "Update systemd-boot in the ESP and EFI variables");
396

397
VERB_SCOPE_NOARG(, verb_remove, "remove",
398
           "Remove systemd-boot from the ESP and EFI variables");
399

400
VERB_SCOPE_NOARG(, verb_is_installed, "is-installed",
401
           "Test whether systemd-boot is installed in the ESP");
402

403
VERB_SCOPE_NOARG(, verb_random_seed, "random-seed",
404
           "Initialize or refresh random seed in ESP and EFI variables");
405

406
VERB_GROUP("Kernel Image Commands");
407

408
VERB_SCOPE(, verb_kernel_identify, "kernel-identify", "KERNEL-IMAGE", 2, 2, 0,
409
           "Identify kernel image type");
410

411
VERB_SCOPE(, verb_kernel_inspect, "kernel-inspect", "KERNEL-IMAGE", 2, 2, 0,
412
           "Prints details about the kernel image");
413

414
static int parse_argv(int argc, char *argv[], char ***ret_args) {
307✔
415
        int r;
307✔
416

417
        assert(argc >= 0);
307✔
418
        assert(argv);
307✔
419

420
        OptionParser state = { argc, argv };
307✔
421
        const char *arg;
307✔
422

423
        FOREACH_OPTION(&state, c, &arg, /* on_error= */ return c)
1,365✔
424
                switch (c) {
450✔
425

426
                OPTION_GROUP("Block Device Discovery Commands"):
427
                        break;
428

429
                OPTION('p', "print-esp-path", NULL, "Print path to the EFI System Partition mount point"): {}
48✔
430
                OPTION_LONG("print-path", NULL, /* help= */ NULL):  /* Compatibility alias */
48✔
431
                        arg_print_esp_path = true;
48✔
432
                        break;
48✔
433

434
                OPTION('x', "print-boot-path", NULL, "Print path to the $BOOT partition mount point"):
9✔
435
                        arg_print_dollar_boot_path = true;
9✔
436
                        break;
9✔
437

438
                OPTION_LONG("print-loader-path", NULL, "Print path to currently booted boot loader binary"):
1✔
439
                        arg_print_loader_path = true;
1✔
440
                        break;
1✔
441

442
                OPTION_LONG("print-stub-path", NULL, "Print path to currently booted unified kernel binary"):
7✔
443
                        arg_print_stub_path = true;
7✔
444
                        break;
7✔
445

446
                OPTION('R', "print-root-device", NULL,
9✔
447
                       "Print path to the block device node backing the root file system"
448
                       " (returns e.g. /dev/nvme0n1p5)"): {}
9✔
449
                OPTION_HELP_VERBATIM("-RR",
9✔
450
                                     "Print path to the whole disk block device node backing the root FS"
451
                                     " (returns e.g. /dev/nvme0n1)"):
452
                        arg_print_root_device++;
9✔
453
                        break;
9✔
454

455
                OPTION_LONG("print-efi-architecture", NULL, "Print the local EFI architecture string"):
1✔
456
                        arg_print_efi_architecture = true;
1✔
457
                        break;
1✔
458

459
                OPTION_GROUP("Options"):
460
                        break;
461

462
                OPTION_COMMON_HELP:
3✔
463
                        return help();
3✔
464

465
                OPTION_COMMON_VERSION:
3✔
466
                        return version();
3✔
467

468
                OPTION_LONG("esp-path", "PATH", "Path to the EFI System Partition (ESP)"): {}
3✔
469
                OPTION_LONG("path", "PATH", /* help= */ NULL):  /* Compatibility alias */
3✔
470
                        r = free_and_strdup(&arg_esp_path, arg);
3✔
471
                        if (r < 0)
3✔
472
                                return log_oom();
×
473
                        break;
474

475
                OPTION_LONG("boot-path", "PATH", "Path to the $BOOT partition"):
3✔
476
                        r = free_and_strdup(&arg_xbootldr_path, arg);
3✔
477
                        if (r < 0)
3✔
478
                                return log_oom();
×
479
                        break;
480

481
                OPTION_LONG("root", "PATH", "Operate on an alternate filesystem root"):
34✔
482
                        r = parse_path_argument(arg, /* suppress_root= */ true, &arg_root);
34✔
483
                        if (r < 0)
34✔
484
                                return r;
485
                        break;
486

487
                OPTION_LONG("image", "PATH", "Operate on disk image as filesystem root"):
29✔
488
                        r = parse_path_argument(arg, /* suppress_root= */ false, &arg_image);
29✔
489
                        if (r < 0)
29✔
490
                                return r;
491
                        break;
492

493
                OPTION_LONG("image-policy", "POLICY", "Specify disk image dissection policy"):
×
494
                        r = parse_image_policy_argument(arg, &arg_image_policy);
×
495
                        if (r < 0)
×
496
                                return r;
497
                        break;
498

499
                OPTION_LONG("install-source", "SOURCE",
×
500
                            "Where to pick files when using --root=/--image= (auto, image, host)"): {
501
                        InstallSource is = install_source_from_string(arg);
×
502
                        if (is < 0)
×
503
                                return log_error_errno(is, "Unexpected parameter for --install-source=: %s", arg);
×
504

505
                        arg_install_source = is;
×
506
                        break;
×
507
                }
508

509
                OPTION_LONG("variables", "BOOL", "Whether to modify EFI variables"):
121✔
510
                        r = parse_tristate_argument_with_auto("--variables=", arg, &arg_touch_variables);
121✔
511
                        if (r < 0)
121✔
512
                                return r;
513
#if !ENABLE_EFI
514
                        if (arg_touch_variables > 0)
515
                                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
516
                                                       "Compiled without support for EFI, --variables=%s cannot be specified.", arg);
517
#endif
518
                        break;
519

520
                OPTION_LONG("no-variables", NULL, /* help= */ NULL):  /* Compatibility alias */
×
521
                        arg_touch_variables = false;
×
522
                        break;
×
523

524
                OPTION_LONG("random-seed", "BOOL", "Whether to create random-seed file during install"):
×
525
                        r = parse_boolean_argument("--random-seed=", arg, &arg_install_random_seed);
×
526
                        if (r < 0)
×
527
                                return r;
528
                        break;
529

530
                OPTION_COMMON_NO_PAGER:
×
531
                        arg_pager_flags |= PAGER_DISABLE;
×
532
                        break;
×
533

534
                OPTION_LONG("graceful", NULL,
139✔
535
                            "Don't fail when the ESP cannot be found or EFI variables cannot be written"):
536
                        _arg_graceful = ARG_GRACEFUL_YES;
139✔
537
                        break;
139✔
538

539
                OPTION('q', "quiet", NULL, "Suppress output"):
6✔
540
                        arg_quiet = true;
6✔
541
                        break;
6✔
542

543
                OPTION_LONG("entry-token", "TOKEN",
×
544
                            "Entry token to use for this installation"
545
                            " (machine-id, os-id, os-image-id, auto, literal:…)"):
546
                        r = parse_boot_entry_token_type(arg, &arg_entry_token_type, &arg_entry_token);
×
547
                        if (r < 0)
×
548
                                return r;
549
                        break;
550

551
                OPTION_LONG("make-entry-directory", "yes|no|auto", "Create $BOOT/ENTRY-TOKEN/ directory"): {}
13✔
552
                OPTION_LONG("make-machine-id-directory", "BOOL", /* help= */ NULL):  /* Compatibility alias */
13✔
553
                        if (streq(arg, "auto"))  /* retained for backwards compatibility */
13✔
554
                                arg_make_entry_directory = -1; /* yes if machine-id is permanent */
×
555
                        else {
556
                                r = parse_boolean_argument("--make-entry-directory=", arg, NULL);
13✔
557
                                if (r < 0)
13✔
558
                                        return r;
559

560
                                arg_make_entry_directory = r;
13✔
561
                        }
562
                        break;
563

564
                OPTION_COMMON_JSON:
6✔
565
                        r = parse_json_argument(arg, &arg_json_format_flags);
6✔
566
                        if (r <= 0)
6✔
567
                                return r;
568
                        break;
569

570
                OPTION_LONG("all-architectures", NULL, "Install all supported EFI architectures"):
12✔
571
                        arg_arch_all = true;
12✔
572
                        break;
12✔
573

574
                OPTION_LONG("efi-boot-option-description", "DESCRIPTION",
×
575
                            "Description of the entry in the boot option list"):
576
                        if (isempty(arg) || !(string_is_safe(arg) && utf8_is_valid(arg))) {
×
577
                                _cleanup_free_ char *escaped = cescape(arg);
×
578
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
579
                                                       "Invalid --efi-boot-option-description=: %s", strna(escaped));
580
                        }
581
                        if (strlen(arg) > EFI_BOOT_OPTION_DESCRIPTION_MAX)
×
582
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
583
                                                       "--efi-boot-option-description= too long: %zu > %zu",
584
                                                       strlen(arg), EFI_BOOT_OPTION_DESCRIPTION_MAX);
585
                        r = free_and_strdup_warn(&arg_efi_boot_option_description, arg);
×
586
                        if (r < 0)
×
587
                                return r;
588
                        break;
589

590
                OPTION_LONG("efi-boot-option-description-with-device", "BOOL",
×
591
                            "Suffix description with disk vendor/model/serial"):
592
                        r = parse_boolean_argument("--efi-boot-option-description-with-device=", arg,
×
593
                                                   &arg_efi_boot_option_description_with_device);
594
                        if (r < 0)
×
595
                                return r;
596
                        break;
597

598
                OPTION_LONG("dry-run", NULL, "Dry run (unlink and cleanup)"):
×
599
                        arg_dry_run = true;
×
600
                        break;
×
601

602
                OPTION_LONG("secure-boot-auto-enroll", "BOOL", "Set up secure boot auto-enrollment"):
1✔
603
                        r = parse_boolean_argument("--secure-boot-auto-enroll=", arg,
1✔
604
                                                   &arg_secure_boot_auto_enroll);
605
                        if (r < 0)
1✔
606
                                return r;
607
                        break;
608

609
                OPTION_LONG("private-key", "PATH|URI",
1✔
610
                            "Private key for Secure Boot auto-enrollment"):
611
                        r = free_and_strdup_warn(&arg_private_key, arg);
1✔
612
                        if (r < 0)
1✔
613
                                return r;
614
                        break;
615

616
                OPTION_LONG("private-key-source", "SOURCE",
×
617
                            "Specify how to use the private key "
618
                            "(file, provider:PROVIDER, engine:ENGINE)"):
619
                        r = parse_openssl_key_source_argument(arg,
×
620
                                                              &arg_private_key_source,
621
                                                              &arg_private_key_source_type);
622
                        if (r < 0)
×
623
                                return r;
624
                        break;
625

626
                OPTION_LONG("certificate", "PATH|URI",
1✔
627
                            "PEM certificate to use when setting up Secure Boot auto-enrollment, "
628
                            "or a provider specific designation if --certificate-source= is used"):
629
                        r = free_and_strdup_warn(&arg_certificate, arg);
1✔
630
                        if (r < 0)
1✔
631
                                return r;
632
                        break;
633

634
                OPTION_LONG("certificate-source", "SOURCE",
×
635
                            "Specify how to interpret the certificate from --certificate=. "
636
                            "Allows the certificate to be loaded from an OpenSSL provider "
637
                            "(file, provider:PROVIDER)"):
638
                        r = parse_openssl_certificate_source_argument(arg,
×
639
                                                                      &arg_certificate_source,
640
                                                                      &arg_certificate_source_type);
641
                        if (r < 0)
×
642
                                return r;
643
                        break;
644
                }
645

646
        char **args = option_parser_get_args(&state);
301✔
647

648
        if (!!arg_print_esp_path + !!arg_print_dollar_boot_path + (arg_print_root_device > 0) + arg_print_loader_path + arg_print_stub_path + arg_print_efi_architecture > 1)
301✔
649
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
650
                                                       "--print-esp-path/-p, --print-boot-path/-x, --print-root-device=/-R, --print-loader-path, --print-stub-path, --print-efi-architecture cannot be combined.");
651

652
        if ((arg_root || arg_image) && args[0] && !STR_IN_SET(args[0], "status", "list",
301✔
653
                        "install", "update", "remove", "is-installed", "random-seed", "unlink", "cleanup"))
654
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
655
                                       "Options --root= and --image= are not supported with verb %s.",
656
                                       args[0]);
657

658
        if (arg_root && arg_image)
301✔
659
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root= or --image=, the combination of both is not supported.");
×
660

661
        if (arg_install_source != INSTALL_SOURCE_AUTO && !arg_root && !arg_image)
301✔
662
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--install-from-host is only supported with --root= or --image=.");
×
663

664
        if (arg_dry_run && args[0] && !STR_IN_SET(args[0], "unlink", "cleanup"))
301✔
665
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--dry-run is only supported with --unlink or --cleanup");
×
666

667
        if (arg_secure_boot_auto_enroll) {
301✔
668
#if HAVE_OPENSSL
669
                if (!arg_certificate)
1✔
670
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Secure boot auto-enrollment requested but no certificate provided.");
×
671

672
                if (!arg_private_key)
1✔
673
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Secure boot auto-enrollment requested but no private key provided.");
×
674
#else
675
                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Secure boot auto-enrollment requested but OpenSSL support is disabled.");
676
#endif
677
        }
678

679
        r = sd_varlink_invocation(SD_VARLINK_ALLOW_ACCEPT);
301✔
680
        if (r < 0)
301✔
681
                return log_error_errno(r, "Failed to check if invoked in Varlink mode: %m");
×
682
        if (r > 0) {
301✔
683
                arg_varlink = true;
15✔
684
                arg_pager_flags |= PAGER_DISABLE;
15✔
685
        }
686

687
        *ret_args = args;
301✔
688
        return 1;
301✔
689
}
690

691
static int vl_server(void) {
15✔
692
        _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL;
15✔
693
        int r;
15✔
694

695
        /* Invocation as Varlink service */
696

697
        r = varlink_server_new(
15✔
698
                        &varlink_server,
699
                        SD_VARLINK_SERVER_ROOT_ONLY|SD_VARLINK_SERVER_ALLOW_FD_PASSING_INPUT,
700
                        /* userdata= */ NULL);
701
        if (r < 0)
15✔
702
                return log_error_errno(r, "Failed to allocate Varlink server: %m");
×
703

704
        r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_BootControl);
15✔
705
        if (r < 0)
15✔
706
                return log_error_errno(r, "Failed to add Varlink interface: %m");
×
707

708
        r = sd_varlink_server_bind_method_many(
15✔
709
                        varlink_server,
710
                        "io.systemd.BootControl.ListBootEntries",     vl_method_list_boot_entries,
711
                        "io.systemd.BootControl.SetRebootToFirmware", vl_method_set_reboot_to_firmware,
712
                        "io.systemd.BootControl.GetRebootToFirmware", vl_method_get_reboot_to_firmware,
713
                        "io.systemd.BootControl.Install",             vl_method_install);
714
        if (r < 0)
15✔
715
                return log_error_errno(r, "Failed to bind Varlink methods: %m");
×
716

717
        r = sd_varlink_server_loop_auto(varlink_server);
15✔
718
        if (r < 0)
15✔
719
                return log_error_errno(r, "Failed to run Varlink event loop: %m");
×
720

721
        return 0;
722
}
723

724
static int run(int argc, char *argv[]) {
307✔
725
        _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
307✔
726
        _cleanup_(umount_and_freep) char *mounted_dir = NULL;
307✔
727
        int r;
307✔
728

729
        log_setup();
307✔
730

731
        char **args = NULL;
307✔
732
        r = parse_argv(argc, argv, &args);
307✔
733
        if (r <= 0)
307✔
734
                return r;
735

736
        if (arg_varlink)
301✔
737
                return vl_server();
15✔
738

739
        if (arg_print_root_device > 0) {
286✔
740
                _cleanup_free_ char *path = NULL;
6✔
741
                dev_t devno;
6✔
742

743
                r = blockdev_get_root(LOG_ERR, &devno);
6✔
744
                if (r < 0)
6✔
745
                        return r;
746
                if (r == 0) {
6✔
747
                        log_error("Root file system not backed by a (single) whole block device.");
×
748
                        return 80; /* some recognizable error code */
×
749
                }
750

751
                if (arg_print_root_device > 1) {
6✔
752
                        r = block_get_whole_disk(devno, &devno);
3✔
753
                        if (r < 0)
3✔
754
                                log_debug_errno(r, "Unable to find whole block device for root block device, ignoring: %m");
×
755
                }
756

757
                r = device_path_make_canonical(S_IFBLK, devno, &path);
6✔
758
                if (r < 0)
6✔
759
                        return log_error_errno(r,
×
760
                                               "Failed to format canonical device path for devno '" DEVNUM_FORMAT_STR "': %m",
761
                                               DEVNUM_FORMAT_VAL(devno));
762

763
                puts(path);
6✔
764
                return 0;
765
        }
766

767
        if (arg_print_loader_path || arg_print_stub_path)
280✔
768
                return print_loader_or_stub_path();
8✔
769

770
        if (arg_print_efi_architecture) {
272✔
771
                printf("%s\n", get_efi_arch());
1✔
772
                return 0;
773
        }
774

775
        /* Open up and mount the image */
776
        if (arg_image) {
271✔
777
                assert(!arg_root);
26✔
778

779
                r = mount_image_privately_interactively(
26✔
780
                                arg_image,
781
                                arg_image_policy,
782
                                DISSECT_IMAGE_GENERIC_ROOT |
783
                                DISSECT_IMAGE_USR_NO_ROOT |
784
                                DISSECT_IMAGE_RELAX_VAR_CHECK |
785
                                DISSECT_IMAGE_ALLOW_USERSPACE_VERITY,
786
                                &mounted_dir,
787
                                /* ret_dir_fd= */ NULL,
788
                                &loop_device);
789
                if (r < 0)
26✔
790
                        return r;
791

792
                arg_root = strdup(mounted_dir);
26✔
793
                if (!arg_root)
26✔
794
                        return log_oom();
×
795
        }
796

797
        return dispatch_verb_with_args(args, NULL);
271✔
798
}
799

800
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);
307✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc