1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 #include "sd-varlink.h"
11 #include "alloc-util.h"
12 #include "ask-password-api.h"
14 #include "bus-error.h"
15 #include "bus-locator.h"
16 #include "bus-unit-util.h"
18 #include "bus-wait-for-jobs.h"
21 #include "creds-util.h"
22 #include "dissect-image.h"
24 #include "errno-util.h"
28 #include "glyph-util.h"
29 #include "hostname-util.h"
30 #include "image-policy.h"
33 #include "label-util.h"
34 #include "libcrypt-util.h"
35 #include "locale-setup.h"
36 #include "locale-util.h"
37 #include "lock-util.h"
38 #include "loop-util.h"
39 #include "main-func.h"
40 #include "memory-util.h"
41 #include "mount-util.h"
43 #include "parse-argument.h"
44 #include "parse-util.h"
45 #include "password-quality-util.h"
46 #include "path-util.h"
47 #include "pretty-print.h"
48 #include "proc-cmdline.h"
49 #include "prompt-util.h"
50 #include "runtime-scope.h"
51 #include "smack-util.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "terminal-util.h"
56 #include "time-util.h"
57 #include "tmpfile-util-label.h"
58 #include "user-util.h"
59 #include "vconsole-util.h"
61 static char *arg_root
= NULL
;
62 static char *arg_image
= NULL
;
63 static char *arg_locale
= NULL
; /* $LANG */
64 static char *arg_locale_messages
= NULL
; /* $LC_MESSAGES */
65 static char *arg_keymap
= NULL
;
66 static char *arg_timezone
= NULL
;
67 static char *arg_hostname
= NULL
;
68 static sd_id128_t arg_machine_id
= {};
69 static char *arg_root_password
= NULL
;
70 static char *arg_root_shell
= NULL
;
71 static char *arg_kernel_cmdline
= NULL
;
72 static bool arg_prompt_locale
= false;
73 static bool arg_prompt_keymap
= false;
74 static bool arg_prompt_keymap_auto
= false;
75 static bool arg_prompt_timezone
= false;
76 static bool arg_prompt_hostname
= false;
77 static bool arg_prompt_root_password
= false;
78 static bool arg_prompt_root_shell
= false;
79 static bool arg_copy_locale
= false;
80 static bool arg_copy_keymap
= false;
81 static bool arg_copy_timezone
= false;
82 static bool arg_copy_root_password
= false;
83 static bool arg_copy_root_shell
= false;
84 static bool arg_force
= false;
85 static bool arg_delete_root_password
= false;
86 static bool arg_root_password_is_hashed
= false;
87 static bool arg_welcome
= true;
88 static bool arg_reset
= false;
89 static ImagePolicy
*arg_image_policy
= NULL
;
90 static bool arg_chrome
= true;
91 static bool arg_mute_console
= false;
93 STATIC_DESTRUCTOR_REGISTER(arg_root
, freep
);
94 STATIC_DESTRUCTOR_REGISTER(arg_image
, freep
);
95 STATIC_DESTRUCTOR_REGISTER(arg_locale
, freep
);
96 STATIC_DESTRUCTOR_REGISTER(arg_locale_messages
, freep
);
97 STATIC_DESTRUCTOR_REGISTER(arg_keymap
, freep
);
98 STATIC_DESTRUCTOR_REGISTER(arg_timezone
, freep
);
99 STATIC_DESTRUCTOR_REGISTER(arg_hostname
, freep
);
100 STATIC_DESTRUCTOR_REGISTER(arg_root_password
, erase_and_freep
);
101 STATIC_DESTRUCTOR_REGISTER(arg_root_shell
, freep
);
102 STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline
, freep
);
103 STATIC_DESTRUCTOR_REGISTER(arg_image_policy
, image_policy_freep
);
105 static void print_welcome(int rfd
, sd_varlink
**mute_console_link
) {
106 _cleanup_free_
char *pretty_name
= NULL
, *os_name
= NULL
, *ansi_color
= NULL
;
107 static bool done
= false;
112 assert(mute_console_link
);
114 if (!*mute_console_link
&& arg_mute_console
)
115 (void) mute_console(mute_console_link
);
121 putchar('\n'); /* Add some breathing room between multiple prompts */
125 (void) terminal_reset_defensive_locked(STDOUT_FILENO
, /* flags= */ 0);
128 chrome_show("Initial Setup", /* bottom= */ NULL
);
130 r
= parse_os_release_at(rfd
,
131 "PRETTY_NAME", &pretty_name
,
133 "ANSI_COLOR", &ansi_color
);
135 log_full_errno(r
== -ENOENT
? LOG_DEBUG
: LOG_WARNING
, r
,
136 "Failed to read os-release file, ignoring: %m");
138 pn
= os_release_pretty_name(pretty_name
, os_name
);
139 ac
= isempty(ansi_color
) ? "0" : ansi_color
;
141 if (colors_enabled())
142 printf(ANSI_HIGHLIGHT
"Welcome to " ANSI_NORMAL
"\x1B[%sm%s" ANSI_HIGHLIGHT
"!" ANSI_NORMAL
"\n", ac
, pn
);
144 printf("Welcome to %s!\n", pn
);
147 if (emoji_enabled()) {
148 fputs(glyph(GLYPH_SPARKLES
), stdout
);
151 printf("Please configure the system!\n\n");
156 static int should_configure(int dir_fd
, const char *filename
) {
157 _cleanup_fclose_
FILE *passwd
= NULL
, *shadow
= NULL
;
163 if (streq(filename
, "passwd") && !arg_force
)
164 /* We may need to do additional checks, so open the file. */
165 r
= xfopenat(dir_fd
, filename
, "re", O_NOFOLLOW
, &passwd
);
167 r
= RET_NERRNO(faccessat(dir_fd
, filename
, F_OK
, AT_SYMLINK_NOFOLLOW
));
170 return true; /* missing */
172 return log_error_errno(r
, "Failed to access %s: %m", filename
);
174 return true; /* exists, but if --force was given we should still configure the file. */
179 /* In case of /etc/passwd, do an additional check for the root password field.
180 * We first check that passwd redirects to shadow, and then we check shadow.
183 while ((r
= fgetpwent_sane(passwd
, &i
)) > 0) {
184 if (!streq(i
->pw_name
, "root"))
187 if (streq_ptr(i
->pw_passwd
, PASSWORD_SEE_SHADOW
))
189 log_debug("passwd: root account with non-shadow password found, treating root as configured");
193 return log_error_errno(r
, "Failed to read %s: %m", filename
);
195 log_debug("No root account found in %s, assuming root is not configured.", filename
);
199 r
= xfopenat(dir_fd
, "shadow", "re", O_NOFOLLOW
, &shadow
);
201 log_debug("No shadow file found, assuming root is not configured.");
202 return true; /* missing */
205 return log_error_errno(r
, "Failed to access shadow: %m");
208 while ((r
= fgetspent_sane(shadow
, &j
)) > 0) {
209 if (!streq(j
->sp_namp
, "root"))
212 bool unprovisioned
= streq_ptr(j
->sp_pwdp
, PASSWORD_UNPROVISIONED
);
213 log_debug("Root account found, %s.",
214 unprovisioned
? "with unprovisioned password, treating root as not configured" :
215 "treating root as configured");
216 return unprovisioned
;
219 return log_error_errno(r
, "Failed to read shadow: %m");
221 log_debug("No root account found in shadow, assuming root is not configured.");
225 static int locale_is_ok(const char *name
, void *userdata
) {
226 int rfd
= ASSERT_FD(PTR_TO_FD(userdata
)), r
;
228 r
= dir_fd_is_root(rfd
);
230 log_debug_errno(r
, "Unable to determine if operating on host root directory, assuming we are: %m");
232 return r
!= 0 ? locale_is_installed(name
) > 0 : locale_is_valid(name
);
235 static int prompt_locale(int rfd
, sd_varlink
**mute_console_link
) {
236 _cleanup_strv_free_
char **locales
= NULL
;
237 bool acquired_from_creds
= false;
242 if (arg_locale
|| arg_locale_messages
)
245 r
= read_credential("firstboot.locale", (void**) &arg_locale
, NULL
);
247 log_debug_errno(r
, "Failed to read credential firstboot.locale, ignoring: %m");
249 acquired_from_creds
= true;
251 r
= read_credential("firstboot.locale-messages", (void**) &arg_locale_messages
, NULL
);
253 log_debug_errno(r
, "Failed to read credential firstboot.locale-messages, ignoring: %m");
255 acquired_from_creds
= true;
257 if (acquired_from_creds
) {
258 log_debug("Acquired locale from credentials.");
262 if (!arg_prompt_locale
) {
263 log_debug("Prompting for locale was not requested.");
267 r
= get_locales(&locales
);
269 return log_error_errno(r
, "Cannot query locales list: %m");
271 if (strv_isempty(locales
))
272 log_debug("No locales found, skipping locale selection.");
273 else if (strv_length(locales
) == 1) {
275 if (streq(locales
[0], SYSTEMD_DEFAULT_LOCALE
))
276 log_debug("Only installed locale is default locale anyway, not setting locale explicitly.");
278 log_debug("Only a single locale available (%s), selecting it as default.", locales
[0]);
280 arg_locale
= strdup(locales
[0]);
284 /* Not setting arg_locale_message here, since it defaults to LANG anyway */
287 print_welcome(rfd
, mute_console_link
);
289 r
= prompt_loop("Please enter the new system locale name or number",
292 /* accepted= */ NULL
,
293 /* ellipsize_percentage= */ 60,
295 /* column_width= */ 20,
299 PROMPT_MAY_SKIP
|PROMPT_SHOW_MENU
,
303 if (isempty(arg_locale
))
306 r
= prompt_loop("Please enter the new system message locale name or number",
309 /* accepted= */ NULL
,
310 /* ellipsize_percentage= */ 60,
312 /* column_width= */ 20,
316 PROMPT_MAY_SKIP
|PROMPT_SHOW_MENU
,
317 &arg_locale_messages
);
321 /* Suppress the messages setting if it's the same as the main locale anyway */
322 if (streq_ptr(arg_locale
, arg_locale_messages
))
323 arg_locale_messages
= mfree(arg_locale_messages
);
329 static int process_locale(int rfd
, sd_varlink
**mute_console_link
) {
330 _cleanup_close_
int pfd
= -EBADF
;
331 _cleanup_free_
char *f
= NULL
;
338 pfd
= chase_and_open_parent_at(rfd
, etc_locale_conf(),
339 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
342 return log_error_errno(pfd
, "Failed to chase /etc/locale.conf: %m");
344 r
= should_configure(pfd
, f
);
346 log_debug("Found /etc/locale.conf, assuming locale information has been configured.");
350 r
= dir_fd_is_root(rfd
);
352 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
354 if (arg_copy_locale
&& r
== 0) {
355 r
= copy_file_atomic_at(AT_FDCWD
, etc_locale_conf(), pfd
, f
, 0644, COPY_REFLINK
);
358 return log_error_errno(r
, "Failed to copy host's /etc/locale.conf: %m");
360 log_info("Copied host's /etc/locale.conf.");
365 r
= prompt_locale(rfd
, mute_console_link
);
369 if (!isempty(arg_locale
))
370 locales
[i
++] = strjoina("LANG=", arg_locale
);
371 if (!isempty(arg_locale_messages
) && !streq_ptr(arg_locale_messages
, arg_locale
))
372 locales
[i
++] = strjoina("LC_MESSAGES=", arg_locale_messages
);
384 WRITE_ENV_FILE_LABEL
);
386 return log_error_errno(r
, "Failed to write /etc/locale.conf: %m");
388 log_info("/etc/locale.conf written.");
392 static int keymap_is_ok(const char* name
, void *userdata
) {
393 int rfd
= ASSERT_FD(PTR_TO_FD(userdata
)), r
;
395 r
= dir_fd_is_root(rfd
);
397 log_debug_errno(r
, "Unable to determine if operating on host root directory, assuming we are: %m");
399 return r
!= 0 ? keymap_exists(name
) > 0 : keymap_is_valid(name
);
402 static int prompt_keymap(int rfd
, sd_varlink
**mute_console_link
) {
403 _cleanup_strv_free_
char **kmaps
= NULL
;
411 r
= read_credential("firstboot.keymap", (void**) &arg_keymap
, NULL
);
413 log_debug_errno(r
, "Failed to read credential firstboot.keymap, ignoring: %m");
415 log_debug("Acquired keymap from credential.");
420 if (arg_prompt_keymap_auto
) {
421 _cleanup_free_
char *ttyname
= NULL
;
423 r
= getttyname_harder(STDOUT_FILENO
, &ttyname
);
425 log_debug_errno(r
, "Cannot determine TTY we are connected, ignoring: %m");
426 b
= false; /* if we can't resolve this, it's probably not a VT */
428 b
= tty_is_vc_resolve(ttyname
);
429 log_debug("Detected connection to local console: %s", yes_no(b
));
432 b
= arg_prompt_keymap
;
434 log_debug("Prompting for keymap was not requested.");
438 r
= get_keymaps(&kmaps
);
439 if (r
== -ENOENT
) /* no keymaps installed */
440 return log_debug_errno(r
, "No keymaps are installed.");
442 return log_error_errno(r
, "Failed to read keymaps: %m");
444 print_welcome(rfd
, mute_console_link
);
447 "Please enter the new keymap name or number",
450 /* accepted= */ NULL
,
451 /* ellipsize_percentage= */ 60,
453 /* column_width= */ 20,
457 PROMPT_MAY_SKIP
|PROMPT_SHOW_MENU
,
461 static int process_keymap(int rfd
, sd_varlink
**mute_console_link
) {
462 _cleanup_close_
int pfd
= -EBADF
;
463 _cleanup_free_
char *f
= NULL
;
464 _cleanup_strv_free_
char **keymap
= NULL
;
469 pfd
= chase_and_open_parent_at(rfd
, etc_vconsole_conf(),
470 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
473 return log_error_errno(pfd
, "Failed to chase /etc/vconsole.conf: %m");
475 r
= should_configure(pfd
, f
);
477 log_debug("Found /etc/vconsole.conf, assuming console has been configured.");
481 r
= dir_fd_is_root(rfd
);
483 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
485 if (arg_copy_keymap
&& r
== 0) {
486 r
= copy_file_atomic_at(AT_FDCWD
, etc_vconsole_conf(), pfd
, f
, 0644, COPY_REFLINK
);
489 return log_error_errno(r
, "Failed to copy host's /etc/vconsole.conf: %m");
491 log_info("Copied host's /etc/vconsole.conf.");
496 r
= prompt_keymap(rfd
, mute_console_link
);
498 return 0; /* don't fail if no keymaps are installed */
502 if (isempty(arg_keymap
))
506 .keymap
= arg_keymap
,
508 _cleanup_(x11_context_clear
) X11Context xc
= {};
510 r
= vconsole_convert_to_x11(&vc
, /* verify= */ NULL
, &xc
);
512 return log_error_errno(r
, "Failed to convert keymap data: %m");
514 r
= vconsole_serialize(&vc
, &xc
, &keymap
);
516 return log_error_errno(r
, "Failed to serialize keymap data: %m");
518 r
= write_vconsole_conf(pfd
, f
, keymap
);
520 return log_error_errno(r
, "Failed to write /etc/vconsole.conf: %m");
522 log_info("/etc/vconsole.conf written.");
526 static int timezone_is_ok(const char *name
, void *userdata
) {
527 return timezone_is_valid(name
, LOG_DEBUG
);
530 static int prompt_timezone(int rfd
, sd_varlink
**mute_console_link
) {
531 _cleanup_strv_free_
char **zones
= NULL
;
539 r
= read_credential("firstboot.timezone", (void**) &arg_timezone
, NULL
);
541 log_debug_errno(r
, "Failed to read credential firstboot.timezone, ignoring: %m");
543 log_debug("Acquired timezone from credential.");
547 if (!arg_prompt_timezone
) {
548 log_debug("Prompting for timezone was not requested.");
552 r
= get_timezones(&zones
);
554 return log_error_errno(r
, "Cannot query timezone list: %m");
556 print_welcome(rfd
, mute_console_link
);
559 "Please enter the new timezone name or number",
562 /* accepted= */ NULL
,
563 /* ellipsize_percentage= */ 30,
565 /* column_width= */ 20,
569 PROMPT_MAY_SKIP
|PROMPT_SHOW_MENU
,
573 static int process_timezone(int rfd
, sd_varlink
**mute_console_link
) {
574 _cleanup_close_
int pfd
= -EBADF
;
575 _cleanup_free_
char *f
= NULL
, *relpath
= NULL
;
581 pfd
= chase_and_open_parent_at(rfd
, etc_localtime(),
582 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
585 return log_error_errno(pfd
, "Failed to chase /etc/localtime: %m");
587 r
= should_configure(pfd
, f
);
589 log_debug("Found /etc/localtime, assuming timezone has been configured.");
593 r
= dir_fd_is_root(rfd
);
595 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
597 if (arg_copy_timezone
&& r
== 0) {
598 _cleanup_free_
char *s
= NULL
;
600 r
= readlink_malloc(etc_localtime(), &s
);
603 return log_error_errno(r
, "Failed to read host's /etc/localtime: %m");
605 r
= symlinkat_atomic_full(s
, pfd
, f
, SYMLINK_LABEL
);
607 return log_error_errno(r
, "Failed to create /etc/localtime symlink: %m");
609 log_info("Copied host's /etc/localtime.");
614 r
= prompt_timezone(rfd
, mute_console_link
);
618 if (isempty(arg_timezone
))
621 e
= strjoina("/usr/share/zoneinfo/", arg_timezone
);
622 r
= path_make_relative_parent(etc_localtime(), e
, &relpath
);
626 r
= symlinkat_atomic_full(relpath
, pfd
, f
, SYMLINK_LABEL
);
628 return log_error_errno(r
, "Failed to create /etc/localtime symlink: %m");
630 log_info("/etc/localtime written");
634 static int hostname_is_ok(const char *name
, void *userdata
) {
635 return hostname_is_valid(name
, VALID_HOSTNAME_TRAILING_DOT
);
638 static int prompt_hostname(int rfd
, sd_varlink
**mute_console_link
) {
646 if (!arg_prompt_hostname
) {
647 log_debug("Prompting for hostname was not requested.");
651 print_welcome(rfd
, mute_console_link
);
653 r
= prompt_loop("Please enter the new hostname",
656 /* accepted= */ NULL
,
657 /* ellipsize_percentage= */ 100,
659 /* column_width= */ 20,
669 hostname_cleanup(arg_hostname
);
674 static int process_hostname(int rfd
, sd_varlink
**mute_console_link
) {
675 _cleanup_close_
int pfd
= -EBADF
;
676 _cleanup_free_
char *f
= NULL
;
681 pfd
= chase_and_open_parent_at(rfd
, etc_hostname(),
682 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
,
685 return log_error_errno(pfd
, "Failed to chase /etc/hostname: %m");
687 r
= should_configure(pfd
, f
);
689 log_debug("Found /etc/hostname, assuming hostname has been configured.");
693 r
= prompt_hostname(rfd
, mute_console_link
);
697 if (isempty(arg_hostname
))
700 r
= write_string_file_at(pfd
, f
, arg_hostname
,
701 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
703 return log_error_errno(r
, "Failed to write /etc/hostname: %m");
705 log_info("/etc/hostname written.");
709 static int process_machine_id(int rfd
) {
710 _cleanup_close_
int pfd
= -EBADF
;
711 _cleanup_free_
char *f
= NULL
;
716 pfd
= chase_and_open_parent_at(rfd
, "/etc/machine-id",
717 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
720 return log_error_errno(pfd
, "Failed to chase /etc/machine-id: %m");
722 r
= should_configure(pfd
, f
);
724 log_debug("Found /etc/machine-id, assuming machine-id has been configured.");
728 if (sd_id128_is_null(arg_machine_id
)) {
729 log_debug("Initialization of machine-id was not requested, skipping.");
733 r
= write_string_file_at(pfd
, "machine-id", SD_ID128_TO_STRING(arg_machine_id
),
734 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
736 return log_error_errno(r
, "Failed to write /etc/machine-id: %m");
738 log_info("/etc/machine-id written.");
742 static int prompt_root_password(int rfd
, sd_varlink
**mute_console_link
) {
743 const char *msg1
, *msg2
;
748 if (arg_root_password
)
751 if (get_credential_user_password("root", &arg_root_password
, &arg_root_password_is_hashed
) >= 0)
754 if (!arg_prompt_root_password
) {
755 log_debug("Prompting for root password was not requested.");
759 print_welcome(rfd
, mute_console_link
);
761 msg1
= "Please enter the new root password (empty to skip):";
762 msg2
= "Please enter the new root password again:";
767 _cleanup_strv_free_erase_
char **a
= NULL
, **b
= NULL
;
768 _cleanup_free_
char *error
= NULL
;
770 AskPasswordRequest req
= {
773 .until
= USEC_INFINITY
,
777 r
= ask_password_tty(&req
, /* flags= */ 0, &a
);
779 return log_error_errno(r
, "Failed to query root password: %m");
780 if (strv_length(a
) != 1)
781 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
782 "Received multiple passwords, where we expected one.");
785 log_info("No password entered, skipping.");
789 r
= check_password_quality(*a
, /* old = */ NULL
, "root", &error
);
790 if (ERRNO_IS_NEG_NOT_SUPPORTED(r
))
791 log_warning("Password quality check is not supported, proceeding anyway.");
793 return log_error_errno(r
, "Failed to check password quality: %m");
795 log_warning("Password is weak, accepting anyway: %s", error
);
799 r
= ask_password_tty(&req
, /* flags= */ 0, &b
);
801 return log_error_errno(r
, "Failed to query root password: %m");
802 if (strv_length(b
) != 1)
803 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
804 "Received multiple passwords, where we expected one.");
806 if (!streq(*a
, *b
)) {
807 log_error("Entered passwords did not match, please try again.");
811 arg_root_password
= TAKE_PTR(*a
);
818 static int find_shell(int rfd
, const char *path
) {
823 if (!valid_shell(path
))
824 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "%s is not a valid shell", path
);
826 r
= chaseat(rfd
, path
, CHASE_AT_RESOLVE_IN_ROOT
, NULL
, NULL
);
828 return log_error_errno(r
, "Failed to resolve shell %s: %m", path
);
833 static int shell_is_ok(const char *path
, void *userdata
) {
834 int rfd
= ASSERT_FD(PTR_TO_FD(userdata
));
836 return find_shell(rfd
, path
) >= 0;
839 static int prompt_root_shell(int rfd
, sd_varlink
**mute_console_link
) {
847 r
= read_credential("passwd.shell.root", (void**) &arg_root_shell
, NULL
);
849 log_debug_errno(r
, "Failed to read credential passwd.shell.root, ignoring: %m");
851 log_debug("Acquired root shell from credential.");
855 if (!arg_prompt_root_shell
) {
856 log_debug("Prompting for root shell was not requested.");
860 print_welcome(rfd
, mute_console_link
);
863 "Please enter the new root shell",
866 /* accepted= */ NULL
,
867 /* ellipsize_percentage= */ 0,
869 /* column_width= */ 20,
877 static int write_root_passwd(int rfd
, int etc_fd
, const char *password
, const char *shell
) {
878 _cleanup_fclose_
FILE *original
= NULL
, *passwd
= NULL
;
879 _cleanup_(unlink_and_freep
) char *passwd_tmp
= NULL
;
883 r
= fopen_temporary_at_label(etc_fd
, "passwd", "passwd", &passwd
, &passwd_tmp
);
887 r
= xfopenat(etc_fd
, "passwd", "re", O_NOFOLLOW
, &original
);
888 if (r
< 0 && r
!= -ENOENT
)
894 r
= copy_rights(fileno(original
), fileno(passwd
));
898 while ((r
= fgetpwent_sane(original
, &i
)) > 0) {
900 if (streq(i
->pw_name
, "root")) {
902 i
->pw_passwd
= (char *) password
;
904 i
->pw_shell
= (char *) shell
;
908 r
= putpwent_sane(i
, passwd
);
916 r
= fchmod(fileno(passwd
), 0644);
922 struct passwd root
= {
923 .pw_name
= (char *) "root",
924 .pw_passwd
= (char *) (password
?: PASSWORD_SEE_SHADOW
),
927 .pw_gecos
= (char *) "Super User",
928 .pw_dir
= (char *) "/root",
929 .pw_shell
= (char *) (shell
?: default_root_shell_at(rfd
)),
935 r
= putpwent_sane(&root
, passwd
);
940 r
= fflush_sync_and_check(passwd
);
944 r
= renameat_and_apply_smack_floor_label(etc_fd
, passwd_tmp
, etc_fd
, "passwd");
951 static int write_root_shadow(int etc_fd
, const char *hashed_password
) {
952 _cleanup_fclose_
FILE *original
= NULL
, *shadow
= NULL
;
953 _cleanup_(unlink_and_freep
) char *shadow_tmp
= NULL
;
957 r
= fopen_temporary_at_label(etc_fd
, "shadow", "shadow", &shadow
, &shadow_tmp
);
961 r
= xfopenat(etc_fd
, "shadow", "re", O_NOFOLLOW
, &original
);
962 if (r
< 0 && r
!= -ENOENT
)
968 r
= copy_rights(fileno(original
), fileno(shadow
));
972 while ((r
= fgetspent_sane(original
, &i
)) > 0) {
974 if (streq(i
->sp_namp
, "root")) {
975 if (hashed_password
) {
976 i
->sp_pwdp
= (char *) hashed_password
;
977 i
->sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
);
982 r
= putspent_sane(i
, shadow
);
990 r
= fchmod(fileno(shadow
), 0000);
997 .sp_namp
= (char*) "root",
998 .sp_pwdp
= (char *) (hashed_password
?: PASSWORD_LOCKED_AND_INVALID
),
999 .sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
),
1005 .sp_flag
= ULONG_MAX
, /* this appears to be what everybody does ... */
1008 if (errno
!= ENOENT
)
1011 r
= putspent_sane(&root
, shadow
);
1016 r
= fflush_sync_and_check(shadow
);
1020 r
= renameat_and_apply_smack_floor_label(etc_fd
, shadow_tmp
, etc_fd
, "shadow");
1027 static int process_root_account(int rfd
, sd_varlink
**mute_console_link
) {
1028 _cleanup_close_
int pfd
= -EBADF
;
1029 _cleanup_(release_lock_file
) LockFile lock
= LOCK_FILE_INIT
;
1030 _cleanup_(erase_and_freep
) char *_hashed_password
= NULL
;
1031 const char *password
, *hashed_password
;
1036 pfd
= chase_and_open_parent_at(rfd
, "/etc/passwd",
1037 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
1040 return log_error_errno(pfd
, "Failed to chase /etc/passwd: %m");
1042 /* Ensure that passwd and shadow are in the same directory and are not symlinks. */
1044 FOREACH_STRING(s
, "passwd", "shadow") {
1045 r
= verify_regular_at(pfd
, s
, /* follow = */ false);
1046 if (r
< 0 && r
!= -ENOENT
)
1047 return log_error_errno(r
, "Verification of /etc/%s being regular file failed: %m", s
);
1049 r
= should_configure(pfd
, s
);
1057 log_debug("Found /etc/passwd and /etc/shadow, assuming root account has been initialized.");
1061 r
= make_lock_file_at(pfd
, ETC_PASSWD_LOCK_FILENAME
, LOCK_EX
, &lock
);
1063 return log_error_errno(r
, "Failed to take a lock on /etc/passwd: %m");
1065 k
= dir_fd_is_root(rfd
);
1067 return log_error_errno(k
, "Failed to check if directory file descriptor is root: %m");
1069 if (arg_copy_root_shell
&& k
== 0) {
1070 _cleanup_free_
struct passwd
*p
= NULL
;
1072 r
= getpwnam_malloc("root", &p
);
1074 return log_error_errno(r
, "Failed to find passwd entry for root: %m");
1076 r
= free_and_strdup(&arg_root_shell
, p
->pw_shell
);
1081 r
= prompt_root_shell(rfd
, mute_console_link
);
1085 if (arg_copy_root_password
&& k
== 0) {
1089 p
= getspnam("root");
1091 return log_error_errno(errno_or_else(EIO
), "Failed to find shadow entry for root: %m");
1093 r
= free_and_strdup(&arg_root_password
, p
->sp_pwdp
);
1097 arg_root_password_is_hashed
= true;
1100 r
= prompt_root_password(rfd
, mute_console_link
);
1104 if (arg_root_password
&& arg_root_password_is_hashed
) {
1105 password
= PASSWORD_SEE_SHADOW
;
1106 hashed_password
= arg_root_password
;
1107 } else if (arg_root_password
) {
1108 r
= hash_password(arg_root_password
, &_hashed_password
);
1110 return log_error_errno(r
, "Failed to hash password: %m");
1112 password
= PASSWORD_SEE_SHADOW
;
1113 hashed_password
= _hashed_password
;
1115 } else if (arg_delete_root_password
) {
1116 password
= PASSWORD_SEE_SHADOW
;
1117 hashed_password
= PASSWORD_NONE
;
1118 } else if (!arg_root_password
&& arg_prompt_root_password
) {
1119 /* If the user was prompted, but no password was supplied, lock the account. */
1120 password
= PASSWORD_SEE_SHADOW
;
1121 hashed_password
= PASSWORD_LOCKED_AND_INVALID
;
1123 /* Leave the password as is. */
1124 password
= hashed_password
= NULL
;
1126 /* Don't create/modify passwd and shadow if there's nothing to do. */
1127 if (!(password
|| hashed_password
|| arg_root_shell
)) {
1128 log_debug("Initialization of root account was not requested, skipping.");
1132 r
= write_root_passwd(rfd
, pfd
, password
, arg_root_shell
);
1134 return log_error_errno(r
, "Failed to write /etc/passwd: %m");
1136 log_info("/etc/passwd written.");
1138 r
= write_root_shadow(pfd
, hashed_password
);
1140 return log_error_errno(r
, "Failed to write /etc/shadow: %m");
1142 log_info("/etc/shadow written.");
1146 static int process_kernel_cmdline(int rfd
) {
1147 _cleanup_close_
int pfd
= -EBADF
;
1148 _cleanup_free_
char *f
= NULL
;
1153 pfd
= chase_and_open_parent_at(rfd
, "/etc/kernel/cmdline",
1154 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
1157 return log_error_errno(pfd
, "Failed to chase /etc/kernel/cmdline: %m");
1159 r
= should_configure(pfd
, f
);
1161 log_debug("Found /etc/kernel/cmdline, assuming kernel command line has been configured.");
1165 if (!arg_kernel_cmdline
) {
1166 log_debug("Creation of /etc/kernel/cmdline was not requested, skipping.");
1170 r
= write_string_file_at(pfd
, "cmdline", arg_kernel_cmdline
,
1171 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
1173 return log_error_errno(r
, "Failed to write /etc/kernel/cmdline: %m");
1175 log_info("/etc/kernel/cmdline written.");
1179 static int reset_one(int rfd
, const char *path
) {
1180 _cleanup_close_
int pfd
= -EBADF
;
1181 _cleanup_free_
char *f
= NULL
;
1186 pfd
= chase_and_open_parent_at(rfd
, path
, CHASE_AT_RESOLVE_IN_ROOT
|CHASE_WARN
|CHASE_NOFOLLOW
, &f
);
1190 return log_error_errno(pfd
, "Failed to resolve %s: %m", path
);
1192 if (unlinkat(pfd
, f
, 0) < 0)
1193 return errno
== ENOENT
? 0 : log_error_errno(errno
, "Failed to remove %s: %m", path
);
1195 log_info("Removed %s", path
);
1199 static int process_reset(int rfd
) {
1209 etc_vconsole_conf(),
1212 "/etc/kernel/cmdline",
1214 r
= reset_one(rfd
, p
);
1222 static int help(void) {
1223 _cleanup_free_
char *link
= NULL
;
1226 r
= terminal_urlify_man("systemd-firstboot", "1", &link
);
1230 printf("%1$s [OPTIONS...]\n"
1231 "\n%3$sConfigures basic settings of the system.%4$s\n\n"
1232 " -h --help Show this help\n"
1233 " --version Show package version\n"
1234 " --root=PATH Operate on an alternate filesystem root\n"
1235 " --image=PATH Operate on disk image as filesystem root\n"
1236 " --image-policy=POLICY Specify disk image dissection policy\n"
1237 " --locale=LOCALE Set primary locale (LANG=)\n"
1238 " --locale-messages=LOCALE Set message locale (LC_MESSAGES=)\n"
1239 " --keymap=KEYMAP Set keymap\n"
1240 " --timezone=TIMEZONE Set timezone\n"
1241 " --hostname=NAME Set hostname\n"
1242 " --setup-machine-id Set a random machine ID\n"
1243 " --machine-id=ID Set specified machine ID\n"
1244 " --root-password=PASSWORD Set root password from plaintext password\n"
1245 " --root-password-file=FILE Set root password from file\n"
1246 " --root-password-hashed=HASH Set root password from hashed password\n"
1247 " --root-shell=SHELL Set root shell\n"
1248 " --kernel-command-line=CMDLINE\n"
1249 " Set kernel command line\n"
1250 " --prompt-locale Prompt the user for locale settings\n"
1251 " --prompt-keymap Prompt the user for keymap settings\n"
1252 " --prompt-keymap-auto Prompt the user for keymap settings if invoked\n"
1253 " on local console\n"
1254 " --prompt-timezone Prompt the user for timezone\n"
1255 " --prompt-hostname Prompt the user for hostname\n"
1256 " --prompt-root-password Prompt the user for root password\n"
1257 " --prompt-root-shell Prompt the user for root shell\n"
1258 " --prompt Prompt for all of the above\n"
1259 " --copy-locale Copy locale from host\n"
1260 " --copy-keymap Copy keymap from host\n"
1261 " --copy-timezone Copy timezone from host\n"
1262 " --copy-root-password Copy root password from host\n"
1263 " --copy-root-shell Copy root shell from host\n"
1264 " --copy Copy locale, keymap, timezone, root password\n"
1265 " --force Overwrite existing files\n"
1266 " --delete-root-password Delete root password\n"
1267 " --welcome=no Disable the welcome text\n"
1268 " --chrome=no Don't show color bar at top and bottom of\n"
1270 " --mute-console=yes Tell kernel/PID 1 to not write to the console\n"
1272 " --reset Remove existing files\n"
1273 "\nSee the %2$s for details.\n",
1274 program_invocation_short_name
,
1282 static int parse_argv(int argc
, char *argv
[]) {
1285 ARG_VERSION
= 0x100,
1290 ARG_LOCALE_MESSAGES
,
1294 ARG_SETUP_MACHINE_ID
,
1297 ARG_ROOT_PASSWORD_FILE
,
1298 ARG_ROOT_PASSWORD_HASHED
,
1300 ARG_KERNEL_COMMAND_LINE
,
1304 ARG_PROMPT_KEYMAP_AUTO
,
1305 ARG_PROMPT_TIMEZONE
,
1306 ARG_PROMPT_HOSTNAME
,
1307 ARG_PROMPT_ROOT_PASSWORD
,
1308 ARG_PROMPT_ROOT_SHELL
,
1313 ARG_COPY_ROOT_PASSWORD
,
1314 ARG_COPY_ROOT_SHELL
,
1316 ARG_DELETE_ROOT_PASSWORD
,
1323 static const struct option options
[] = {
1324 { "help", no_argument
, NULL
, 'h' },
1325 { "version", no_argument
, NULL
, ARG_VERSION
},
1326 { "root", required_argument
, NULL
, ARG_ROOT
},
1327 { "image", required_argument
, NULL
, ARG_IMAGE
},
1328 { "image-policy", required_argument
, NULL
, ARG_IMAGE_POLICY
},
1329 { "locale", required_argument
, NULL
, ARG_LOCALE
},
1330 { "locale-messages", required_argument
, NULL
, ARG_LOCALE_MESSAGES
},
1331 { "keymap", required_argument
, NULL
, ARG_KEYMAP
},
1332 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
1333 { "hostname", required_argument
, NULL
, ARG_HOSTNAME
},
1334 { "setup-machine-id", no_argument
, NULL
, ARG_SETUP_MACHINE_ID
},
1335 { "machine-id", required_argument
, NULL
, ARG_MACHINE_ID
},
1336 { "root-password", required_argument
, NULL
, ARG_ROOT_PASSWORD
},
1337 { "root-password-file", required_argument
, NULL
, ARG_ROOT_PASSWORD_FILE
},
1338 { "root-password-hashed", required_argument
, NULL
, ARG_ROOT_PASSWORD_HASHED
},
1339 { "root-shell", required_argument
, NULL
, ARG_ROOT_SHELL
},
1340 { "kernel-command-line", required_argument
, NULL
, ARG_KERNEL_COMMAND_LINE
},
1341 { "prompt", no_argument
, NULL
, ARG_PROMPT
},
1342 { "prompt-locale", no_argument
, NULL
, ARG_PROMPT_LOCALE
},
1343 { "prompt-keymap", no_argument
, NULL
, ARG_PROMPT_KEYMAP
},
1344 { "prompt-keymap-auto", no_argument
, NULL
, ARG_PROMPT_KEYMAP_AUTO
},
1345 { "prompt-timezone", no_argument
, NULL
, ARG_PROMPT_TIMEZONE
},
1346 { "prompt-hostname", no_argument
, NULL
, ARG_PROMPT_HOSTNAME
},
1347 { "prompt-root-password", no_argument
, NULL
, ARG_PROMPT_ROOT_PASSWORD
},
1348 { "prompt-root-shell", no_argument
, NULL
, ARG_PROMPT_ROOT_SHELL
},
1349 { "copy", no_argument
, NULL
, ARG_COPY
},
1350 { "copy-locale", no_argument
, NULL
, ARG_COPY_LOCALE
},
1351 { "copy-keymap", no_argument
, NULL
, ARG_COPY_KEYMAP
},
1352 { "copy-timezone", no_argument
, NULL
, ARG_COPY_TIMEZONE
},
1353 { "copy-root-password", no_argument
, NULL
, ARG_COPY_ROOT_PASSWORD
},
1354 { "copy-root-shell", no_argument
, NULL
, ARG_COPY_ROOT_SHELL
},
1355 { "force", no_argument
, NULL
, ARG_FORCE
},
1356 { "delete-root-password", no_argument
, NULL
, ARG_DELETE_ROOT_PASSWORD
},
1357 { "welcome", required_argument
, NULL
, ARG_WELCOME
},
1358 { "chrome", required_argument
, NULL
, ARG_CHROME
},
1359 { "reset", no_argument
, NULL
, ARG_RESET
},
1360 { "mute-console", required_argument
, NULL
, ARG_MUTE_CONSOLE
},
1369 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
1380 r
= parse_path_argument(optarg
, true, &arg_root
);
1386 r
= parse_path_argument(optarg
, false, &arg_image
);
1391 case ARG_IMAGE_POLICY
:
1392 r
= parse_image_policy_argument(optarg
, &arg_image_policy
);
1398 r
= free_and_strdup(&arg_locale
, optarg
);
1404 case ARG_LOCALE_MESSAGES
:
1405 r
= free_and_strdup(&arg_locale_messages
, optarg
);
1412 if (!keymap_is_valid(optarg
))
1413 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1414 "Keymap %s is not valid.", optarg
);
1416 r
= free_and_strdup(&arg_keymap
, optarg
);
1423 if (!timezone_is_valid(optarg
, LOG_ERR
))
1424 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1425 "Timezone %s is not valid.", optarg
);
1427 r
= free_and_strdup(&arg_timezone
, optarg
);
1433 case ARG_ROOT_PASSWORD
:
1434 r
= free_and_strdup(&arg_root_password
, optarg
);
1438 arg_root_password_is_hashed
= false;
1441 case ARG_ROOT_PASSWORD_FILE
:
1442 arg_root_password
= mfree(arg_root_password
);
1444 r
= read_one_line_file(optarg
, &arg_root_password
);
1446 return log_error_errno(r
, "Failed to read %s: %m", optarg
);
1448 arg_root_password_is_hashed
= false;
1451 case ARG_ROOT_PASSWORD_HASHED
:
1452 r
= free_and_strdup(&arg_root_password
, optarg
);
1456 arg_root_password_is_hashed
= true;
1459 case ARG_ROOT_SHELL
:
1460 r
= free_and_strdup(&arg_root_shell
, optarg
);
1467 if (!hostname_is_valid(optarg
, VALID_HOSTNAME_TRAILING_DOT
|VALID_HOSTNAME_QUESTION_MARK
))
1468 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1469 "Host name %s is not valid.", optarg
);
1471 r
= free_and_strdup(&arg_hostname
, optarg
);
1475 hostname_cleanup(arg_hostname
);
1478 case ARG_SETUP_MACHINE_ID
:
1479 r
= sd_id128_randomize(&arg_machine_id
);
1481 return log_error_errno(r
, "Failed to generate randomized machine ID: %m");
1485 case ARG_MACHINE_ID
:
1486 r
= sd_id128_from_string(optarg
, &arg_machine_id
);
1488 return log_error_errno(r
, "Failed to parse machine id %s.", optarg
);
1492 case ARG_KERNEL_COMMAND_LINE
:
1493 r
= free_and_strdup(&arg_kernel_cmdline
, optarg
);
1500 arg_prompt_locale
= arg_prompt_keymap
= arg_prompt_timezone
= arg_prompt_hostname
=
1501 arg_prompt_root_password
= arg_prompt_root_shell
= true;
1502 arg_prompt_keymap_auto
= false;
1505 case ARG_PROMPT_LOCALE
:
1506 arg_prompt_locale
= true;
1509 case ARG_PROMPT_KEYMAP
:
1510 arg_prompt_keymap
= true;
1511 arg_prompt_keymap_auto
= false;
1514 case ARG_PROMPT_KEYMAP_AUTO
:
1515 arg_prompt_keymap_auto
= true;
1518 case ARG_PROMPT_TIMEZONE
:
1519 arg_prompt_timezone
= true;
1522 case ARG_PROMPT_HOSTNAME
:
1523 arg_prompt_hostname
= true;
1526 case ARG_PROMPT_ROOT_PASSWORD
:
1527 arg_prompt_root_password
= true;
1530 case ARG_PROMPT_ROOT_SHELL
:
1531 arg_prompt_root_shell
= true;
1535 arg_copy_locale
= arg_copy_keymap
= arg_copy_timezone
= arg_copy_root_password
=
1536 arg_copy_root_shell
= true;
1539 case ARG_COPY_LOCALE
:
1540 arg_copy_locale
= true;
1543 case ARG_COPY_KEYMAP
:
1544 arg_copy_keymap
= true;
1547 case ARG_COPY_TIMEZONE
:
1548 arg_copy_timezone
= true;
1551 case ARG_COPY_ROOT_PASSWORD
:
1552 arg_copy_root_password
= true;
1555 case ARG_COPY_ROOT_SHELL
:
1556 arg_copy_root_shell
= true;
1563 case ARG_DELETE_ROOT_PASSWORD
:
1564 arg_delete_root_password
= true;
1568 r
= parse_boolean(optarg
);
1570 return log_error_errno(r
, "Failed to parse --welcome= argument: %s", optarg
);
1576 r
= parse_boolean_argument("--chrome=", optarg
, &arg_chrome
);
1586 case ARG_MUTE_CONSOLE
:
1587 r
= parse_boolean_argument("--mute-console=", optarg
, &arg_mute_console
);
1597 assert_not_reached();
1600 if (arg_delete_root_password
&& (arg_copy_root_password
|| arg_root_password
|| arg_prompt_root_password
))
1601 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1602 "--delete-root-password cannot be combined with other root password options.");
1604 if (arg_image
&& arg_root
)
1605 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1606 "--root= and --image= cannot be used together.");
1608 if (!sd_id128_is_null(arg_machine_id
) && !(arg_image
|| arg_root
) && !arg_force
)
1609 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1610 "--machine-id=/--setup-machine-id only works with --root= or --image=.");
1615 static int reload_system_manager(sd_bus
**bus
) {
1621 r
= bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL
, NULL
, RUNTIME_SCOPE_SYSTEM
, bus
);
1623 return bus_log_connect_error(r
, BUS_TRANSPORT_LOCAL
, RUNTIME_SCOPE_SYSTEM
);
1626 r
= bus_service_manager_reload(*bus
);
1630 log_info("Requested manager reload to apply locale configuration.");
1634 static int reload_vconsole(sd_bus
**bus
) {
1635 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1636 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1637 _cleanup_(bus_wait_for_jobs_freep
) BusWaitForJobs
*w
= NULL
;
1644 r
= bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL
, NULL
, RUNTIME_SCOPE_SYSTEM
, bus
);
1646 return bus_log_connect_error(r
, BUS_TRANSPORT_LOCAL
, RUNTIME_SCOPE_SYSTEM
);
1649 r
= bus_wait_for_jobs_new(*bus
, &w
);
1651 return log_error_errno(r
, "Could not watch jobs: %m");
1653 r
= bus_call_method(*bus
, bus_systemd_mgr
, "RestartUnit", &error
, &reply
,
1654 "ss", "systemd-vconsole-setup.service", "replace");
1656 return log_error_errno(r
, "Failed to issue method call: %s", bus_error_message(&error
, r
));
1658 r
= sd_bus_message_read(reply
, "o", &object
);
1660 return bus_log_parse_error(r
);
1662 r
= bus_wait_for_jobs_one(w
, object
, BUS_WAIT_JOBS_LOG_ERROR
, NULL
);
1664 return log_error_errno(r
, "Failed to wait for systemd-vconsole-setup.service/restart: %m");
1668 static int run(int argc
, char *argv
[]) {
1669 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1670 _cleanup_(loop_device_unrefp
) LoopDevice
*loop_device
= NULL
;
1671 _cleanup_(umount_and_freep
) char *mounted_dir
= NULL
;
1672 _cleanup_close_
int rfd
= -EBADF
;
1675 r
= parse_argv(argc
, argv
);
1683 bool offline
= arg_root
|| arg_image
;
1686 /* If we are called without --root=/--image= let's honour the systemd.firstboot kernel
1687 * command line option, because we are called to provision the host with basic settings (as
1688 * opposed to some other file system tree/image) */
1691 r
= proc_cmdline_get_bool("systemd.firstboot", /* flags = */ 0, &enabled
);
1693 return log_error_errno(r
, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
1694 if (r
> 0 && !enabled
) {
1695 log_debug("Found systemd.firstboot=no kernel command line argument, turning off all prompts.");
1696 arg_prompt_locale
= arg_prompt_keymap
= arg_prompt_keymap_auto
= arg_prompt_timezone
= arg_prompt_hostname
= arg_prompt_root_password
= arg_prompt_root_shell
= false;
1707 r
= mount_image_privately_interactively(
1710 DISSECT_IMAGE_GENERIC_ROOT
|
1711 DISSECT_IMAGE_REQUIRE_ROOT
|
1712 DISSECT_IMAGE_VALIDATE_OS
|
1713 DISSECT_IMAGE_RELAX_VAR_CHECK
|
1714 DISSECT_IMAGE_FSCK
|
1715 DISSECT_IMAGE_GROWFS
|
1716 DISSECT_IMAGE_ALLOW_USERSPACE_VERITY
,
1723 arg_root
= strdup(mounted_dir
);
1727 rfd
= open(empty_to_root(arg_root
), O_DIRECTORY
|O_CLOEXEC
);
1729 return log_error_errno(errno
, "Failed to open %s: %m", empty_to_root(arg_root
));
1732 LOG_SET_PREFIX(arg_image
?: arg_root
);
1733 DEFER_VOID_CALL(chrome_hide
);
1735 /* We check these conditions here instead of in parse_argv() so that we can take the root directory
1738 if (arg_keymap
&& !keymap_is_ok(arg_keymap
, FD_TO_PTR(rfd
)))
1739 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Keymap %s is not installed.", arg_keymap
);
1740 if (arg_locale
&& !locale_is_ok(arg_locale
, FD_TO_PTR(rfd
)))
1741 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale
);
1742 if (arg_locale_messages
&& !locale_is_ok(arg_locale_messages
, FD_TO_PTR(rfd
)))
1743 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale_messages
);
1745 if (arg_root_shell
) {
1746 r
= find_shell(rfd
, arg_root_shell
);
1751 r
= process_reset(rfd
);
1755 _cleanup_(sd_varlink_flush_close_unrefp
) sd_varlink
*mute_console_link
= NULL
;
1756 r
= process_locale(rfd
, &mute_console_link
);
1759 if (r
> 0 && !offline
)
1760 (void) reload_system_manager(&bus
);
1762 r
= process_keymap(rfd
, &mute_console_link
);
1765 if (r
> 0 && !offline
)
1766 (void) reload_vconsole(&bus
);
1768 r
= process_timezone(rfd
, &mute_console_link
);
1772 r
= process_hostname(rfd
, &mute_console_link
);
1776 r
= process_root_account(rfd
, &mute_console_link
);
1780 r
= process_kernel_cmdline(rfd
);
1784 r
= process_machine_id(rfd
);
1791 DEFINE_MAIN_FUNCTION(run
);