1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 #include "alloc-util.h"
11 #include "ask-password-api.h"
13 #include "bus-error.h"
14 #include "bus-locator.h"
15 #include "bus-unit-util.h"
17 #include "bus-wait-for-jobs.h"
20 #include "creds-util.h"
21 #include "dissect-image.h"
23 #include "errno-util.h"
27 #include "glyph-util.h"
28 #include "hostname-util.h"
29 #include "image-policy.h"
32 #include "label-util.h"
33 #include "libcrypt-util.h"
34 #include "locale-setup.h"
35 #include "locale-util.h"
36 #include "lock-util.h"
37 #include "loop-util.h"
38 #include "main-func.h"
39 #include "memory-util.h"
40 #include "mount-util.h"
42 #include "parse-argument.h"
43 #include "parse-util.h"
44 #include "password-quality-util.h"
45 #include "path-util.h"
46 #include "pretty-print.h"
47 #include "proc-cmdline.h"
48 #include "runtime-scope.h"
49 #include "smack-util.h"
50 #include "stat-util.h"
51 #include "string-util.h"
53 #include "terminal-util.h"
54 #include "time-util.h"
55 #include "tmpfile-util-label.h"
56 #include "user-util.h"
57 #include "vconsole-util.h"
59 static char *arg_root
= NULL
;
60 static char *arg_image
= NULL
;
61 static char *arg_locale
= NULL
; /* $LANG */
62 static char *arg_locale_messages
= NULL
; /* $LC_MESSAGES */
63 static char *arg_keymap
= NULL
;
64 static char *arg_timezone
= NULL
;
65 static char *arg_hostname
= NULL
;
66 static sd_id128_t arg_machine_id
= {};
67 static char *arg_root_password
= NULL
;
68 static char *arg_root_shell
= NULL
;
69 static char *arg_kernel_cmdline
= NULL
;
70 static bool arg_prompt_locale
= false;
71 static bool arg_prompt_keymap
= false;
72 static bool arg_prompt_timezone
= false;
73 static bool arg_prompt_hostname
= false;
74 static bool arg_prompt_root_password
= false;
75 static bool arg_prompt_root_shell
= false;
76 static bool arg_copy_locale
= false;
77 static bool arg_copy_keymap
= false;
78 static bool arg_copy_timezone
= false;
79 static bool arg_copy_root_password
= false;
80 static bool arg_copy_root_shell
= false;
81 static bool arg_force
= false;
82 static bool arg_delete_root_password
= false;
83 static bool arg_root_password_is_hashed
= false;
84 static bool arg_welcome
= true;
85 static bool arg_reset
= false;
86 static ImagePolicy
*arg_image_policy
= NULL
;
88 STATIC_DESTRUCTOR_REGISTER(arg_root
, freep
);
89 STATIC_DESTRUCTOR_REGISTER(arg_image
, freep
);
90 STATIC_DESTRUCTOR_REGISTER(arg_locale
, freep
);
91 STATIC_DESTRUCTOR_REGISTER(arg_locale_messages
, freep
);
92 STATIC_DESTRUCTOR_REGISTER(arg_keymap
, freep
);
93 STATIC_DESTRUCTOR_REGISTER(arg_timezone
, freep
);
94 STATIC_DESTRUCTOR_REGISTER(arg_hostname
, freep
);
95 STATIC_DESTRUCTOR_REGISTER(arg_root_password
, erase_and_freep
);
96 STATIC_DESTRUCTOR_REGISTER(arg_root_shell
, freep
);
97 STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline
, freep
);
98 STATIC_DESTRUCTOR_REGISTER(arg_image_policy
, image_policy_freep
);
100 static void print_welcome(int rfd
) {
101 _cleanup_free_
char *pretty_name
= NULL
, *os_name
= NULL
, *ansi_color
= NULL
;
102 static bool done
= false;
112 putchar('\n'); /* Add some breathing room between multiple prompts */
116 r
= parse_os_release_at(rfd
,
117 "PRETTY_NAME", &pretty_name
,
119 "ANSI_COLOR", &ansi_color
);
121 log_full_errno(r
== -ENOENT
? LOG_DEBUG
: LOG_WARNING
, r
,
122 "Failed to read os-release file, ignoring: %m");
124 pn
= os_release_pretty_name(pretty_name
, os_name
);
125 ac
= isempty(ansi_color
) ? "0" : ansi_color
;
127 (void) terminal_reset_defensive_locked(STDOUT_FILENO
, /* flags= */ 0);
129 if (colors_enabled())
131 ANSI_HIGHLIGHT
"Welcome to your new installation of " ANSI_NORMAL
"\x1B[%sm%s" ANSI_HIGHLIGHT
"!" ANSI_NORMAL
"\n", ac
, pn
);
133 printf("\nWelcome to your new installation of %s!\n", pn
);
136 if (emoji_enabled()) {
137 fputs(glyph(GLYPH_SPARKLES
), stdout
);
140 printf("Please configure your new system!\n");
142 any_key_to_proceed();
147 static int get_completions(
159 _cleanup_strv_free_
char **copy
= strv_copy(userdata
);
163 r
= strv_extend(©
, "list");
167 *ret_list
= TAKE_PTR(copy
);
171 static int prompt_loop(
175 unsigned ellipsize_percentage
,
176 bool (*is_valid
)(int rfd
, const char *name
),
186 _cleanup_free_
char *p
= NULL
;
192 strv_isempty(l
) ? "%s %s (empty to skip): "
193 : "%s %s (empty to skip, \"list\" to list options): ",
194 glyph(GLYPH_TRIANGULAR_BULLET
), text
);
196 return log_error_errno(r
, "Failed to query user: %m");
199 log_info("No data entered, skipping.");
203 if (!strv_isempty(l
)) {
204 if (streq(p
, "list")) {
207 /* column_width= */ 20,
208 ellipsize_percentage
,
209 /* grey_prefix= */ NULL
,
210 /* with_numbers= */ true);
212 return log_error_errno(r
, "Failed to show menu: %m");
219 r
= safe_atou(p
, &u
);
221 if (u
<= 0 || u
> strv_length(l
)) {
222 log_error("Specified entry number out of range.");
226 log_info("Selected '%s'.", l
[u
-1]);
227 return free_and_strdup_warn(ret
, l
[u
-1]);
231 if (is_valid(rfd
, p
))
232 return free_and_replace(*ret
, p
);
234 /* Be more helpful to the user, and give a hint what the user might have wanted to type. */
235 const char *best_match
= strv_find_closest(l
, p
);
237 log_error("Invalid data '%s', did you mean '%s'?", p
, best_match
);
239 log_error("Invalid data '%s'.", p
);
243 static int should_configure(int dir_fd
, const char *filename
) {
244 _cleanup_fclose_
FILE *passwd
= NULL
, *shadow
= NULL
;
250 if (streq(filename
, "passwd") && !arg_force
)
251 /* We may need to do additional checks, so open the file. */
252 r
= xfopenat(dir_fd
, filename
, "re", O_NOFOLLOW
, &passwd
);
254 r
= RET_NERRNO(faccessat(dir_fd
, filename
, F_OK
, AT_SYMLINK_NOFOLLOW
));
257 return true; /* missing */
259 return log_error_errno(r
, "Failed to access %s: %m", filename
);
261 return true; /* exists, but if --force was given we should still configure the file. */
266 /* In case of /etc/passwd, do an additional check for the root password field.
267 * We first check that passwd redirects to shadow, and then we check shadow.
270 while ((r
= fgetpwent_sane(passwd
, &i
)) > 0) {
271 if (!streq(i
->pw_name
, "root"))
274 if (streq_ptr(i
->pw_passwd
, PASSWORD_SEE_SHADOW
))
276 log_debug("passwd: root account with non-shadow password found, treating root as configured");
280 return log_error_errno(r
, "Failed to read %s: %m", filename
);
282 log_debug("No root account found in %s, assuming root is not configured.", filename
);
286 r
= xfopenat(dir_fd
, "shadow", "re", O_NOFOLLOW
, &shadow
);
288 log_debug("No shadow file found, assuming root is not configured.");
289 return true; /* missing */
292 return log_error_errno(r
, "Failed to access shadow: %m");
295 while ((r
= fgetspent_sane(shadow
, &j
)) > 0) {
296 if (!streq(j
->sp_namp
, "root"))
299 bool unprovisioned
= streq_ptr(j
->sp_pwdp
, PASSWORD_UNPROVISIONED
);
300 log_debug("Root account found, %s.",
301 unprovisioned
? "with unprovisioned password, treating root as not configured" :
302 "treating root as configured");
303 return unprovisioned
;
306 return log_error_errno(r
, "Failed to read shadow: %m");
308 log_debug("No root account found in shadow, assuming root is not configured.");
312 static bool locale_is_installed_bool(const char *name
) {
313 return locale_is_installed(name
) > 0;
316 static bool locale_is_ok(int rfd
, const char *name
) {
321 r
= dir_fd_is_root(rfd
);
323 log_debug_errno(r
, "Unable to determine if operating on host root directory, assuming we are: %m");
325 return r
!= 0 ? locale_is_installed_bool(name
) : locale_is_valid(name
);
328 static int prompt_locale(int rfd
) {
329 _cleanup_strv_free_
char **locales
= NULL
;
330 bool acquired_from_creds
= false;
335 if (arg_locale
|| arg_locale_messages
)
338 r
= read_credential("firstboot.locale", (void**) &arg_locale
, NULL
);
340 log_debug_errno(r
, "Failed to read credential firstboot.locale, ignoring: %m");
342 acquired_from_creds
= true;
344 r
= read_credential("firstboot.locale-messages", (void**) &arg_locale_messages
, NULL
);
346 log_debug_errno(r
, "Failed to read credential firstboot.locale-messages, ignoring: %m");
348 acquired_from_creds
= true;
350 if (acquired_from_creds
) {
351 log_debug("Acquired locale from credentials.");
355 if (!arg_prompt_locale
) {
356 log_debug("Prompting for locale was not requested.");
360 r
= get_locales(&locales
);
362 return log_error_errno(r
, "Cannot query locales list: %m");
364 if (strv_isempty(locales
))
365 log_debug("No locales found, skipping locale selection.");
366 else if (strv_length(locales
) == 1) {
368 if (streq(locales
[0], SYSTEMD_DEFAULT_LOCALE
))
369 log_debug("Only installed locale is default locale anyway, not setting locale explicitly.");
371 log_debug("Only a single locale available (%s), selecting it as default.", locales
[0]);
373 arg_locale
= strdup(locales
[0]);
377 /* Not setting arg_locale_message here, since it defaults to LANG anyway */
382 r
= prompt_loop(rfd
, "Please enter the new system locale name or number",
383 locales
, 60, locale_is_ok
, &arg_locale
);
387 if (isempty(arg_locale
))
390 r
= prompt_loop(rfd
, "Please enter the new system message locale name or number",
391 locales
, 60, locale_is_ok
, &arg_locale_messages
);
395 /* Suppress the messages setting if it's the same as the main locale anyway */
396 if (streq_ptr(arg_locale
, arg_locale_messages
))
397 arg_locale_messages
= mfree(arg_locale_messages
);
403 static int process_locale(int rfd
) {
404 _cleanup_close_
int pfd
= -EBADF
;
405 _cleanup_free_
char *f
= NULL
;
412 pfd
= chase_and_open_parent_at(rfd
, etc_locale_conf(),
413 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
416 return log_error_errno(pfd
, "Failed to chase /etc/locale.conf: %m");
418 r
= should_configure(pfd
, f
);
420 log_debug("Found /etc/locale.conf, assuming locale information has been configured.");
424 r
= dir_fd_is_root(rfd
);
426 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
428 if (arg_copy_locale
&& r
== 0) {
429 r
= copy_file_atomic_at(AT_FDCWD
, etc_locale_conf(), pfd
, f
, 0644, COPY_REFLINK
);
432 return log_error_errno(r
, "Failed to copy host's /etc/locale.conf: %m");
434 log_info("Copied host's /etc/locale.conf.");
439 r
= prompt_locale(rfd
);
443 if (!isempty(arg_locale
))
444 locales
[i
++] = strjoina("LANG=", arg_locale
);
445 if (!isempty(arg_locale_messages
) && !streq_ptr(arg_locale_messages
, arg_locale
))
446 locales
[i
++] = strjoina("LC_MESSAGES=", arg_locale_messages
);
458 WRITE_ENV_FILE_LABEL
);
460 return log_error_errno(r
, "Failed to write /etc/locale.conf: %m");
462 log_info("/etc/locale.conf written.");
466 static bool keymap_exists_bool(const char *name
) {
467 return keymap_exists(name
) > 0;
470 static bool keymap_is_ok(int rfd
, const char* name
) {
475 r
= dir_fd_is_root(rfd
);
477 log_debug_errno(r
, "Unable to determine if operating on host root directory, assuming we are: %m");
479 return r
!= 0 ? keymap_exists_bool(name
) : keymap_is_valid(name
);
482 static int prompt_keymap(int rfd
) {
483 _cleanup_strv_free_
char **kmaps
= NULL
;
491 r
= read_credential("firstboot.keymap", (void**) &arg_keymap
, NULL
);
493 log_debug_errno(r
, "Failed to read credential firstboot.keymap, ignoring: %m");
495 log_debug("Acquired keymap from credential.");
499 if (!arg_prompt_keymap
) {
500 log_debug("Prompting for keymap was not requested.");
504 r
= get_keymaps(&kmaps
);
505 if (r
== -ENOENT
) /* no keymaps installed */
506 return log_debug_errno(r
, "No keymaps are installed.");
508 return log_error_errno(r
, "Failed to read keymaps: %m");
512 return prompt_loop(rfd
, "Please enter the new keymap name or number",
513 kmaps
, 60, keymap_is_ok
, &arg_keymap
);
516 static int process_keymap(int rfd
) {
517 _cleanup_close_
int pfd
= -EBADF
;
518 _cleanup_free_
char *f
= NULL
;
519 _cleanup_strv_free_
char **keymap
= NULL
;
524 pfd
= chase_and_open_parent_at(rfd
, etc_vconsole_conf(),
525 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
528 return log_error_errno(pfd
, "Failed to chase /etc/vconsole.conf: %m");
530 r
= should_configure(pfd
, f
);
532 log_debug("Found /etc/vconsole.conf, assuming console has been configured.");
536 r
= dir_fd_is_root(rfd
);
538 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
540 if (arg_copy_keymap
&& r
== 0) {
541 r
= copy_file_atomic_at(AT_FDCWD
, etc_vconsole_conf(), pfd
, f
, 0644, COPY_REFLINK
);
544 return log_error_errno(r
, "Failed to copy host's /etc/vconsole.conf: %m");
546 log_info("Copied host's /etc/vconsole.conf.");
551 r
= prompt_keymap(rfd
);
553 return 0; /* don't fail if no keymaps are installed */
557 if (isempty(arg_keymap
))
561 .keymap
= arg_keymap
,
563 _cleanup_(x11_context_clear
) X11Context xc
= {};
565 r
= vconsole_convert_to_x11(&vc
, /* verify= */ NULL
, &xc
);
567 return log_error_errno(r
, "Failed to convert keymap data: %m");
569 r
= vconsole_serialize(&vc
, &xc
, &keymap
);
571 return log_error_errno(r
, "Failed to serialize keymap data: %m");
573 r
= write_vconsole_conf(pfd
, f
, keymap
);
575 return log_error_errno(r
, "Failed to write /etc/vconsole.conf: %m");
577 log_info("/etc/vconsole.conf written.");
581 static bool timezone_is_ok(int rfd
, const char *name
) {
584 return timezone_is_valid(name
, LOG_DEBUG
);
587 static int prompt_timezone(int rfd
) {
588 _cleanup_strv_free_
char **zones
= NULL
;
596 r
= read_credential("firstboot.timezone", (void**) &arg_timezone
, NULL
);
598 log_debug_errno(r
, "Failed to read credential firstboot.timezone, ignoring: %m");
600 log_debug("Acquired timezone from credential.");
604 if (!arg_prompt_timezone
) {
605 log_debug("Prompting for timezone was not requested.");
609 r
= get_timezones(&zones
);
611 return log_error_errno(r
, "Cannot query timezone list: %m");
615 return prompt_loop(rfd
, "Please enter the new timezone name or number",
616 zones
, 30, timezone_is_ok
, &arg_timezone
);
619 static int process_timezone(int rfd
) {
620 _cleanup_close_
int pfd
= -EBADF
;
621 _cleanup_free_
char *f
= NULL
, *relpath
= NULL
;
627 pfd
= chase_and_open_parent_at(rfd
, etc_localtime(),
628 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
631 return log_error_errno(pfd
, "Failed to chase /etc/localtime: %m");
633 r
= should_configure(pfd
, f
);
635 log_debug("Found /etc/localtime, assuming timezone has been configured.");
639 r
= dir_fd_is_root(rfd
);
641 return log_error_errno(r
, "Failed to check if directory file descriptor is root: %m");
643 if (arg_copy_timezone
&& r
== 0) {
644 _cleanup_free_
char *s
= NULL
;
646 r
= readlink_malloc(etc_localtime(), &s
);
649 return log_error_errno(r
, "Failed to read host's /etc/localtime: %m");
651 r
= symlinkat_atomic_full(s
, pfd
, f
, SYMLINK_LABEL
);
653 return log_error_errno(r
, "Failed to create /etc/localtime symlink: %m");
655 log_info("Copied host's /etc/localtime.");
660 r
= prompt_timezone(rfd
);
664 if (isempty(arg_timezone
))
667 e
= strjoina("/usr/share/zoneinfo/", arg_timezone
);
668 r
= path_make_relative_parent(etc_localtime(), e
, &relpath
);
672 r
= symlinkat_atomic_full(relpath
, pfd
, f
, SYMLINK_LABEL
);
674 return log_error_errno(r
, "Failed to create /etc/localtime symlink: %m");
676 log_info("/etc/localtime written");
680 static bool hostname_is_ok(int rfd
, const char *name
) {
683 return hostname_is_valid(name
, VALID_HOSTNAME_TRAILING_DOT
);
686 static int prompt_hostname(int rfd
) {
694 if (!arg_prompt_hostname
) {
695 log_debug("Prompting for hostname was not requested.");
701 r
= prompt_loop(rfd
, "Please enter the new hostname",
702 NULL
, 0, hostname_is_ok
, &arg_hostname
);
707 hostname_cleanup(arg_hostname
);
712 static int process_hostname(int rfd
) {
713 _cleanup_close_
int pfd
= -EBADF
;
714 _cleanup_free_
char *f
= NULL
;
719 pfd
= chase_and_open_parent_at(rfd
, etc_hostname(),
720 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
,
723 return log_error_errno(pfd
, "Failed to chase /etc/hostname: %m");
725 r
= should_configure(pfd
, f
);
727 log_debug("Found /etc/hostname, assuming hostname has been configured.");
731 r
= prompt_hostname(rfd
);
735 if (isempty(arg_hostname
))
738 r
= write_string_file_at(pfd
, f
, arg_hostname
,
739 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
741 return log_error_errno(r
, "Failed to write /etc/hostname: %m");
743 log_info("/etc/hostname written.");
747 static int process_machine_id(int rfd
) {
748 _cleanup_close_
int pfd
= -EBADF
;
749 _cleanup_free_
char *f
= NULL
;
754 pfd
= chase_and_open_parent_at(rfd
, "/etc/machine-id",
755 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
758 return log_error_errno(pfd
, "Failed to chase /etc/machine-id: %m");
760 r
= should_configure(pfd
, f
);
762 log_debug("Found /etc/machine-id, assuming machine-id has been configured.");
766 if (sd_id128_is_null(arg_machine_id
)) {
767 log_debug("Initialization of machine-id was not requested, skipping.");
771 r
= write_string_file_at(pfd
, "machine-id", SD_ID128_TO_STRING(arg_machine_id
),
772 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
774 return log_error_errno(r
, "Failed to write /etc/machine-id: %m");
776 log_info("/etc/machine-id written.");
780 static int prompt_root_password(int rfd
) {
781 const char *msg1
, *msg2
;
786 if (arg_root_password
)
789 if (get_credential_user_password("root", &arg_root_password
, &arg_root_password_is_hashed
) >= 0)
792 if (!arg_prompt_root_password
) {
793 log_debug("Prompting for root password was not requested.");
799 msg1
= strjoina(glyph(GLYPH_TRIANGULAR_BULLET
), " Please enter the new root password (empty to skip):");
800 msg2
= strjoina(glyph(GLYPH_TRIANGULAR_BULLET
), " Please enter the new root password again:");
805 _cleanup_strv_free_erase_
char **a
= NULL
, **b
= NULL
;
806 _cleanup_free_
char *error
= NULL
;
808 AskPasswordRequest req
= {
811 .until
= USEC_INFINITY
,
815 r
= ask_password_tty(&req
, /* flags= */ 0, &a
);
817 return log_error_errno(r
, "Failed to query root password: %m");
818 if (strv_length(a
) != 1)
819 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
820 "Received multiple passwords, where we expected one.");
823 log_info("No password entered, skipping.");
827 r
= check_password_quality(*a
, /* old */ NULL
, "root", &error
);
828 if (ERRNO_IS_NEG_NOT_SUPPORTED(r
))
829 log_warning("Password quality check is not supported, proceeding anyway.");
831 return log_error_errno(r
, "Failed to check password quality: %m");
833 log_warning("Password is weak, accepting anyway: %s", error
);
837 r
= ask_password_tty(&req
, /* flags= */ 0, &b
);
839 return log_error_errno(r
, "Failed to query root password: %m");
840 if (strv_length(b
) != 1)
841 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
842 "Received multiple passwords, where we expected one.");
844 if (!streq(*a
, *b
)) {
845 log_error("Entered passwords did not match, please try again.");
849 arg_root_password
= TAKE_PTR(*a
);
856 static int find_shell(int rfd
, const char *path
) {
861 if (!valid_shell(path
))
862 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "%s is not a valid shell", path
);
864 r
= chaseat(rfd
, path
, CHASE_AT_RESOLVE_IN_ROOT
, NULL
, NULL
);
866 return log_error_errno(r
, "Failed to resolve shell %s: %m", path
);
871 static bool shell_is_ok(int rfd
, const char *path
) {
874 return find_shell(rfd
, path
) >= 0;
877 static int prompt_root_shell(int rfd
) {
885 r
= read_credential("passwd.shell.root", (void**) &arg_root_shell
, NULL
);
887 log_debug_errno(r
, "Failed to read credential passwd.shell.root, ignoring: %m");
889 log_debug("Acquired root shell from credential.");
893 if (!arg_prompt_root_shell
) {
894 log_debug("Prompting for root shell was not requested.");
900 return prompt_loop(rfd
, "Please enter the new root shell",
901 NULL
, 0, shell_is_ok
, &arg_root_shell
);
904 static int write_root_passwd(int rfd
, int etc_fd
, const char *password
, const char *shell
) {
905 _cleanup_fclose_
FILE *original
= NULL
, *passwd
= NULL
;
906 _cleanup_(unlink_and_freep
) char *passwd_tmp
= NULL
;
910 r
= fopen_temporary_at_label(etc_fd
, "passwd", "passwd", &passwd
, &passwd_tmp
);
914 r
= xfopenat(etc_fd
, "passwd", "re", O_NOFOLLOW
, &original
);
915 if (r
< 0 && r
!= -ENOENT
)
921 r
= copy_rights(fileno(original
), fileno(passwd
));
925 while ((r
= fgetpwent_sane(original
, &i
)) > 0) {
927 if (streq(i
->pw_name
, "root")) {
929 i
->pw_passwd
= (char *) password
;
931 i
->pw_shell
= (char *) shell
;
935 r
= putpwent_sane(i
, passwd
);
943 r
= fchmod(fileno(passwd
), 0644);
949 struct passwd root
= {
950 .pw_name
= (char *) "root",
951 .pw_passwd
= (char *) (password
?: PASSWORD_SEE_SHADOW
),
954 .pw_gecos
= (char *) "Super User",
955 .pw_dir
= (char *) "/root",
956 .pw_shell
= (char *) (shell
?: default_root_shell_at(rfd
)),
962 r
= putpwent_sane(&root
, passwd
);
967 r
= fflush_sync_and_check(passwd
);
971 r
= renameat_and_apply_smack_floor_label(etc_fd
, passwd_tmp
, etc_fd
, "passwd");
978 static int write_root_shadow(int etc_fd
, const char *hashed_password
) {
979 _cleanup_fclose_
FILE *original
= NULL
, *shadow
= NULL
;
980 _cleanup_(unlink_and_freep
) char *shadow_tmp
= NULL
;
984 r
= fopen_temporary_at_label(etc_fd
, "shadow", "shadow", &shadow
, &shadow_tmp
);
988 r
= xfopenat(etc_fd
, "shadow", "re", O_NOFOLLOW
, &original
);
989 if (r
< 0 && r
!= -ENOENT
)
995 r
= copy_rights(fileno(original
), fileno(shadow
));
999 while ((r
= fgetspent_sane(original
, &i
)) > 0) {
1001 if (streq(i
->sp_namp
, "root")) {
1002 if (hashed_password
) {
1003 i
->sp_pwdp
= (char *) hashed_password
;
1004 i
->sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
);
1009 r
= putspent_sane(i
, shadow
);
1017 r
= fchmod(fileno(shadow
), 0000);
1023 struct spwd root
= {
1024 .sp_namp
= (char*) "root",
1025 .sp_pwdp
= (char *) (hashed_password
?: PASSWORD_LOCKED_AND_INVALID
),
1026 .sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
),
1032 .sp_flag
= ULONG_MAX
, /* this appears to be what everybody does ... */
1035 if (errno
!= ENOENT
)
1038 r
= putspent_sane(&root
, shadow
);
1043 r
= fflush_sync_and_check(shadow
);
1047 r
= renameat_and_apply_smack_floor_label(etc_fd
, shadow_tmp
, etc_fd
, "shadow");
1054 static int process_root_account(int rfd
) {
1055 _cleanup_close_
int pfd
= -EBADF
;
1056 _cleanup_(release_lock_file
) LockFile lock
= LOCK_FILE_INIT
;
1057 _cleanup_(erase_and_freep
) char *_hashed_password
= NULL
;
1058 const char *password
, *hashed_password
;
1063 pfd
= chase_and_open_parent_at(rfd
, "/etc/passwd",
1064 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
1067 return log_error_errno(pfd
, "Failed to chase /etc/passwd: %m");
1069 /* Ensure that passwd and shadow are in the same directory and are not symlinks. */
1071 FOREACH_STRING(s
, "passwd", "shadow") {
1072 r
= verify_regular_at(pfd
, s
, /* follow = */ false);
1073 if (r
< 0 && r
!= -ENOENT
)
1074 return log_error_errno(r
, "Verification of /etc/%s being regular file failed: %m", s
);
1076 r
= should_configure(pfd
, s
);
1084 log_debug("Found /etc/passwd and /etc/shadow, assuming root account has been initialized.");
1088 r
= make_lock_file_at(pfd
, ETC_PASSWD_LOCK_FILENAME
, LOCK_EX
, &lock
);
1090 return log_error_errno(r
, "Failed to take a lock on /etc/passwd: %m");
1092 k
= dir_fd_is_root(rfd
);
1094 return log_error_errno(k
, "Failed to check if directory file descriptor is root: %m");
1096 if (arg_copy_root_shell
&& k
== 0) {
1097 _cleanup_free_
struct passwd
*p
= NULL
;
1099 r
= getpwnam_malloc("root", &p
);
1101 return log_error_errno(r
, "Failed to find passwd entry for root: %m");
1103 r
= free_and_strdup(&arg_root_shell
, p
->pw_shell
);
1108 r
= prompt_root_shell(rfd
);
1112 if (arg_copy_root_password
&& k
== 0) {
1116 p
= getspnam("root");
1118 return log_error_errno(errno_or_else(EIO
), "Failed to find shadow entry for root: %m");
1120 r
= free_and_strdup(&arg_root_password
, p
->sp_pwdp
);
1124 arg_root_password_is_hashed
= true;
1127 r
= prompt_root_password(rfd
);
1131 if (arg_root_password
&& arg_root_password_is_hashed
) {
1132 password
= PASSWORD_SEE_SHADOW
;
1133 hashed_password
= arg_root_password
;
1134 } else if (arg_root_password
) {
1135 r
= hash_password(arg_root_password
, &_hashed_password
);
1137 return log_error_errno(r
, "Failed to hash password: %m");
1139 password
= PASSWORD_SEE_SHADOW
;
1140 hashed_password
= _hashed_password
;
1142 } else if (arg_delete_root_password
) {
1143 password
= PASSWORD_SEE_SHADOW
;
1144 hashed_password
= PASSWORD_NONE
;
1145 } else if (!arg_root_password
&& arg_prompt_root_password
) {
1146 /* If the user was prompted, but no password was supplied, lock the account. */
1147 password
= PASSWORD_SEE_SHADOW
;
1148 hashed_password
= PASSWORD_LOCKED_AND_INVALID
;
1150 /* Leave the password as is. */
1151 password
= hashed_password
= NULL
;
1153 /* Don't create/modify passwd and shadow if there's nothing to do. */
1154 if (!(password
|| hashed_password
|| arg_root_shell
)) {
1155 log_debug("Initialization of root account was not requested, skipping.");
1159 r
= write_root_passwd(rfd
, pfd
, password
, arg_root_shell
);
1161 return log_error_errno(r
, "Failed to write /etc/passwd: %m");
1163 log_info("/etc/passwd written.");
1165 r
= write_root_shadow(pfd
, hashed_password
);
1167 return log_error_errno(r
, "Failed to write /etc/shadow: %m");
1169 log_info("/etc/shadow written.");
1173 static int process_kernel_cmdline(int rfd
) {
1174 _cleanup_close_
int pfd
= -EBADF
;
1175 _cleanup_free_
char *f
= NULL
;
1180 pfd
= chase_and_open_parent_at(rfd
, "/etc/kernel/cmdline",
1181 CHASE_AT_RESOLVE_IN_ROOT
|CHASE_MKDIR_0755
|CHASE_WARN
|CHASE_NOFOLLOW
,
1184 return log_error_errno(pfd
, "Failed to chase /etc/kernel/cmdline: %m");
1186 r
= should_configure(pfd
, f
);
1188 log_debug("Found /etc/kernel/cmdline, assuming kernel command line has been configured.");
1192 if (!arg_kernel_cmdline
) {
1193 log_debug("Creation of /etc/kernel/cmdline was not requested, skipping.");
1197 r
= write_string_file_at(pfd
, "cmdline", arg_kernel_cmdline
,
1198 WRITE_STRING_FILE_CREATE
|WRITE_STRING_FILE_SYNC
|WRITE_STRING_FILE_ATOMIC
|WRITE_STRING_FILE_LABEL
);
1200 return log_error_errno(r
, "Failed to write /etc/kernel/cmdline: %m");
1202 log_info("/etc/kernel/cmdline written.");
1206 static int reset_one(int rfd
, const char *path
) {
1207 _cleanup_close_
int pfd
= -EBADF
;
1208 _cleanup_free_
char *f
= NULL
;
1213 pfd
= chase_and_open_parent_at(rfd
, path
, CHASE_AT_RESOLVE_IN_ROOT
|CHASE_WARN
|CHASE_NOFOLLOW
, &f
);
1217 return log_error_errno(pfd
, "Failed to resolve %s: %m", path
);
1219 if (unlinkat(pfd
, f
, 0) < 0)
1220 return errno
== ENOENT
? 0 : log_error_errno(errno
, "Failed to remove %s: %m", path
);
1222 log_info("Removed %s", path
);
1226 static int process_reset(int rfd
) {
1236 etc_vconsole_conf(),
1239 "/etc/kernel/cmdline",
1241 r
= reset_one(rfd
, p
);
1249 static int help(void) {
1250 _cleanup_free_
char *link
= NULL
;
1253 r
= terminal_urlify_man("systemd-firstboot", "1", &link
);
1257 printf("%s [OPTIONS...]\n\n"
1258 "Configures basic settings of the system.\n\n"
1259 " -h --help Show this help\n"
1260 " --version Show package version\n"
1261 " --root=PATH Operate on an alternate filesystem root\n"
1262 " --image=PATH Operate on disk image as filesystem root\n"
1263 " --image-policy=POLICY Specify disk image dissection policy\n"
1264 " --locale=LOCALE Set primary locale (LANG=)\n"
1265 " --locale-messages=LOCALE Set message locale (LC_MESSAGES=)\n"
1266 " --keymap=KEYMAP Set keymap\n"
1267 " --timezone=TIMEZONE Set timezone\n"
1268 " --hostname=NAME Set hostname\n"
1269 " --setup-machine-id Set a random machine ID\n"
1270 " --machine-id=ID Set specified machine ID\n"
1271 " --root-password=PASSWORD Set root password from plaintext password\n"
1272 " --root-password-file=FILE Set root password from file\n"
1273 " --root-password-hashed=HASH Set root password from hashed password\n"
1274 " --root-shell=SHELL Set root shell\n"
1275 " --kernel-command-line=CMDLINE\n"
1276 " Set kernel command line\n"
1277 " --prompt-locale Prompt the user for locale settings\n"
1278 " --prompt-keymap Prompt the user for keymap settings\n"
1279 " --prompt-timezone Prompt the user for timezone\n"
1280 " --prompt-hostname Prompt the user for hostname\n"
1281 " --prompt-root-password Prompt the user for root password\n"
1282 " --prompt-root-shell Prompt the user for root shell\n"
1283 " --prompt Prompt for all of the above\n"
1284 " --copy-locale Copy locale from host\n"
1285 " --copy-keymap Copy keymap from host\n"
1286 " --copy-timezone Copy timezone from host\n"
1287 " --copy-root-password Copy root password from host\n"
1288 " --copy-root-shell Copy root shell from host\n"
1289 " --copy Copy locale, keymap, timezone, root password\n"
1290 " --force Overwrite existing files\n"
1291 " --delete-root-password Delete root password\n"
1292 " --welcome=no Disable the welcome text\n"
1293 " --reset Remove existing files\n"
1294 "\nSee the %s for details.\n",
1295 program_invocation_short_name
,
1301 static int parse_argv(int argc
, char *argv
[]) {
1304 ARG_VERSION
= 0x100,
1309 ARG_LOCALE_MESSAGES
,
1313 ARG_SETUP_MACHINE_ID
,
1316 ARG_ROOT_PASSWORD_FILE
,
1317 ARG_ROOT_PASSWORD_HASHED
,
1319 ARG_KERNEL_COMMAND_LINE
,
1323 ARG_PROMPT_TIMEZONE
,
1324 ARG_PROMPT_HOSTNAME
,
1325 ARG_PROMPT_ROOT_PASSWORD
,
1326 ARG_PROMPT_ROOT_SHELL
,
1331 ARG_COPY_ROOT_PASSWORD
,
1332 ARG_COPY_ROOT_SHELL
,
1334 ARG_DELETE_ROOT_PASSWORD
,
1339 static const struct option options
[] = {
1340 { "help", no_argument
, NULL
, 'h' },
1341 { "version", no_argument
, NULL
, ARG_VERSION
},
1342 { "root", required_argument
, NULL
, ARG_ROOT
},
1343 { "image", required_argument
, NULL
, ARG_IMAGE
},
1344 { "image-policy", required_argument
, NULL
, ARG_IMAGE_POLICY
},
1345 { "locale", required_argument
, NULL
, ARG_LOCALE
},
1346 { "locale-messages", required_argument
, NULL
, ARG_LOCALE_MESSAGES
},
1347 { "keymap", required_argument
, NULL
, ARG_KEYMAP
},
1348 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
1349 { "hostname", required_argument
, NULL
, ARG_HOSTNAME
},
1350 { "setup-machine-id", no_argument
, NULL
, ARG_SETUP_MACHINE_ID
},
1351 { "machine-id", required_argument
, NULL
, ARG_MACHINE_ID
},
1352 { "root-password", required_argument
, NULL
, ARG_ROOT_PASSWORD
},
1353 { "root-password-file", required_argument
, NULL
, ARG_ROOT_PASSWORD_FILE
},
1354 { "root-password-hashed", required_argument
, NULL
, ARG_ROOT_PASSWORD_HASHED
},
1355 { "root-shell", required_argument
, NULL
, ARG_ROOT_SHELL
},
1356 { "kernel-command-line", required_argument
, NULL
, ARG_KERNEL_COMMAND_LINE
},
1357 { "prompt", no_argument
, NULL
, ARG_PROMPT
},
1358 { "prompt-locale", no_argument
, NULL
, ARG_PROMPT_LOCALE
},
1359 { "prompt-keymap", no_argument
, NULL
, ARG_PROMPT_KEYMAP
},
1360 { "prompt-timezone", no_argument
, NULL
, ARG_PROMPT_TIMEZONE
},
1361 { "prompt-hostname", no_argument
, NULL
, ARG_PROMPT_HOSTNAME
},
1362 { "prompt-root-password", no_argument
, NULL
, ARG_PROMPT_ROOT_PASSWORD
},
1363 { "prompt-root-shell", no_argument
, NULL
, ARG_PROMPT_ROOT_SHELL
},
1364 { "copy", no_argument
, NULL
, ARG_COPY
},
1365 { "copy-locale", no_argument
, NULL
, ARG_COPY_LOCALE
},
1366 { "copy-keymap", no_argument
, NULL
, ARG_COPY_KEYMAP
},
1367 { "copy-timezone", no_argument
, NULL
, ARG_COPY_TIMEZONE
},
1368 { "copy-root-password", no_argument
, NULL
, ARG_COPY_ROOT_PASSWORD
},
1369 { "copy-root-shell", no_argument
, NULL
, ARG_COPY_ROOT_SHELL
},
1370 { "force", no_argument
, NULL
, ARG_FORCE
},
1371 { "delete-root-password", no_argument
, NULL
, ARG_DELETE_ROOT_PASSWORD
},
1372 { "welcome", required_argument
, NULL
, ARG_WELCOME
},
1373 { "reset", no_argument
, NULL
, ARG_RESET
},
1382 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
1393 r
= parse_path_argument(optarg
, true, &arg_root
);
1399 r
= parse_path_argument(optarg
, false, &arg_image
);
1404 case ARG_IMAGE_POLICY
:
1405 r
= parse_image_policy_argument(optarg
, &arg_image_policy
);
1411 r
= free_and_strdup(&arg_locale
, optarg
);
1417 case ARG_LOCALE_MESSAGES
:
1418 r
= free_and_strdup(&arg_locale_messages
, optarg
);
1425 if (!keymap_is_valid(optarg
))
1426 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1427 "Keymap %s is not valid.", optarg
);
1429 r
= free_and_strdup(&arg_keymap
, optarg
);
1436 if (!timezone_is_valid(optarg
, LOG_ERR
))
1437 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1438 "Timezone %s is not valid.", optarg
);
1440 r
= free_and_strdup(&arg_timezone
, optarg
);
1446 case ARG_ROOT_PASSWORD
:
1447 r
= free_and_strdup(&arg_root_password
, optarg
);
1451 arg_root_password_is_hashed
= false;
1454 case ARG_ROOT_PASSWORD_FILE
:
1455 arg_root_password
= mfree(arg_root_password
);
1457 r
= read_one_line_file(optarg
, &arg_root_password
);
1459 return log_error_errno(r
, "Failed to read %s: %m", optarg
);
1461 arg_root_password_is_hashed
= false;
1464 case ARG_ROOT_PASSWORD_HASHED
:
1465 r
= free_and_strdup(&arg_root_password
, optarg
);
1469 arg_root_password_is_hashed
= true;
1472 case ARG_ROOT_SHELL
:
1473 r
= free_and_strdup(&arg_root_shell
, optarg
);
1480 if (!hostname_is_valid(optarg
, VALID_HOSTNAME_TRAILING_DOT
|VALID_HOSTNAME_QUESTION_MARK
))
1481 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1482 "Host name %s is not valid.", optarg
);
1484 r
= free_and_strdup(&arg_hostname
, optarg
);
1488 hostname_cleanup(arg_hostname
);
1491 case ARG_SETUP_MACHINE_ID
:
1492 r
= sd_id128_randomize(&arg_machine_id
);
1494 return log_error_errno(r
, "Failed to generate randomized machine ID: %m");
1498 case ARG_MACHINE_ID
:
1499 r
= sd_id128_from_string(optarg
, &arg_machine_id
);
1501 return log_error_errno(r
, "Failed to parse machine id %s.", optarg
);
1505 case ARG_KERNEL_COMMAND_LINE
:
1506 r
= free_and_strdup(&arg_kernel_cmdline
, optarg
);
1513 arg_prompt_locale
= arg_prompt_keymap
= arg_prompt_timezone
= arg_prompt_hostname
=
1514 arg_prompt_root_password
= arg_prompt_root_shell
= true;
1517 case ARG_PROMPT_LOCALE
:
1518 arg_prompt_locale
= true;
1521 case ARG_PROMPT_KEYMAP
:
1522 arg_prompt_keymap
= true;
1525 case ARG_PROMPT_TIMEZONE
:
1526 arg_prompt_timezone
= true;
1529 case ARG_PROMPT_HOSTNAME
:
1530 arg_prompt_hostname
= true;
1533 case ARG_PROMPT_ROOT_PASSWORD
:
1534 arg_prompt_root_password
= true;
1537 case ARG_PROMPT_ROOT_SHELL
:
1538 arg_prompt_root_shell
= true;
1542 arg_copy_locale
= arg_copy_keymap
= arg_copy_timezone
= arg_copy_root_password
=
1543 arg_copy_root_shell
= true;
1546 case ARG_COPY_LOCALE
:
1547 arg_copy_locale
= true;
1550 case ARG_COPY_KEYMAP
:
1551 arg_copy_keymap
= true;
1554 case ARG_COPY_TIMEZONE
:
1555 arg_copy_timezone
= true;
1558 case ARG_COPY_ROOT_PASSWORD
:
1559 arg_copy_root_password
= true;
1562 case ARG_COPY_ROOT_SHELL
:
1563 arg_copy_root_shell
= true;
1570 case ARG_DELETE_ROOT_PASSWORD
:
1571 arg_delete_root_password
= true;
1575 r
= parse_boolean(optarg
);
1577 return log_error_errno(r
, "Failed to parse --welcome= argument: %s", optarg
);
1590 assert_not_reached();
1593 if (arg_delete_root_password
&& (arg_copy_root_password
|| arg_root_password
|| arg_prompt_root_password
))
1594 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1595 "--delete-root-password cannot be combined with other root password options.");
1597 if (arg_image
&& arg_root
)
1598 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1599 "--root= and --image= cannot be used together.");
1601 if (!sd_id128_is_null(arg_machine_id
) && !(arg_image
|| arg_root
) && !arg_force
)
1602 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1603 "--machine-id=/--setup-machine-id only works with --root= or --image=.");
1608 static int reload_system_manager(sd_bus
**bus
) {
1614 r
= bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL
, NULL
, RUNTIME_SCOPE_SYSTEM
, bus
);
1616 return bus_log_connect_error(r
, BUS_TRANSPORT_LOCAL
, RUNTIME_SCOPE_SYSTEM
);
1619 r
= bus_service_manager_reload(*bus
);
1623 log_info("Requested manager reload to apply locale configuration.");
1627 static int reload_vconsole(sd_bus
**bus
) {
1628 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1629 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1630 _cleanup_(bus_wait_for_jobs_freep
) BusWaitForJobs
*w
= NULL
;
1637 r
= bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL
, NULL
, RUNTIME_SCOPE_SYSTEM
, bus
);
1639 return bus_log_connect_error(r
, BUS_TRANSPORT_LOCAL
, RUNTIME_SCOPE_SYSTEM
);
1642 r
= bus_wait_for_jobs_new(*bus
, &w
);
1644 return log_error_errno(r
, "Could not watch jobs: %m");
1646 r
= bus_call_method(*bus
, bus_systemd_mgr
, "RestartUnit", &error
, &reply
,
1647 "ss", "systemd-vconsole-setup.service", "replace");
1649 return log_error_errno(r
, "Failed to issue method call: %s", bus_error_message(&error
, r
));
1651 r
= sd_bus_message_read(reply
, "o", &object
);
1653 return bus_log_parse_error(r
);
1655 r
= bus_wait_for_jobs_one(w
, object
, BUS_WAIT_JOBS_LOG_ERROR
, NULL
);
1657 return log_error_errno(r
, "Failed to wait for systemd-vconsole-setup.service/restart: %m");
1661 static int run(int argc
, char *argv
[]) {
1662 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1663 _cleanup_(loop_device_unrefp
) LoopDevice
*loop_device
= NULL
;
1664 _cleanup_(umount_and_freep
) char *mounted_dir
= NULL
;
1665 _cleanup_close_
int rfd
= -EBADF
;
1668 r
= parse_argv(argc
, argv
);
1676 bool offline
= arg_root
|| arg_image
;
1679 /* If we are called without --root=/--image= let's honour the systemd.firstboot kernel
1680 * command line option, because we are called to provision the host with basic settings (as
1681 * opposed to some other file system tree/image) */
1684 r
= proc_cmdline_get_bool("systemd.firstboot", /* flags = */ 0, &enabled
);
1686 return log_error_errno(r
, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
1687 if (r
> 0 && !enabled
) {
1688 log_debug("Found systemd.firstboot=no kernel command line argument, turning off all prompts.");
1689 arg_prompt_locale
= arg_prompt_keymap
= arg_prompt_timezone
= arg_prompt_hostname
= arg_prompt_root_password
= arg_prompt_root_shell
= false;
1700 r
= mount_image_privately_interactively(
1703 DISSECT_IMAGE_GENERIC_ROOT
|
1704 DISSECT_IMAGE_REQUIRE_ROOT
|
1705 DISSECT_IMAGE_VALIDATE_OS
|
1706 DISSECT_IMAGE_RELAX_VAR_CHECK
|
1707 DISSECT_IMAGE_FSCK
|
1708 DISSECT_IMAGE_GROWFS
|
1709 DISSECT_IMAGE_ALLOW_USERSPACE_VERITY
,
1716 arg_root
= strdup(mounted_dir
);
1720 rfd
= open(empty_to_root(arg_root
), O_DIRECTORY
|O_CLOEXEC
);
1722 return log_error_errno(errno
, "Failed to open %s: %m", empty_to_root(arg_root
));
1725 LOG_SET_PREFIX(arg_image
?: arg_root
);
1727 /* We check these conditions here instead of in parse_argv() so that we can take the root directory
1730 if (arg_keymap
&& !keymap_is_ok(rfd
, arg_keymap
))
1731 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Keymap %s is not installed.", arg_keymap
);
1732 if (arg_locale
&& !locale_is_ok(rfd
, arg_locale
))
1733 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale
);
1734 if (arg_locale_messages
&& !locale_is_ok(rfd
, arg_locale_messages
))
1735 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale_messages
);
1737 if (arg_root_shell
) {
1738 r
= find_shell(rfd
, arg_root_shell
);
1743 r
= process_reset(rfd
);
1747 r
= process_locale(rfd
);
1750 if (r
> 0 && !offline
)
1751 (void) reload_system_manager(&bus
);
1753 r
= process_keymap(rfd
);
1756 if (r
> 0 && !offline
)
1757 (void) reload_vconsole(&bus
);
1759 r
= process_timezone(rfd
);
1763 r
= process_hostname(rfd
);
1767 r
= process_root_account(rfd
);
1771 r
= process_kernel_cmdline(rfd
);
1775 r
= process_machine_id(rfd
);
1782 DEFINE_MAIN_FUNCTION(run
);