nspawn: allow disabling os-release check

Introduce a new env variable $SYSTEMD_NSPAWN_CHECK_OS_RELEASE, that can
be used to disable the os-release check for bootable OS trees. Useful
when trying to boot a container with empty /etc/ and bind-mounted /usr/.

Resolves: #29185
This commit is contained in:
Frantisek Sumsal
2023-11-03 16:05:14 +00:00
committed by Luca Boccassi
parent 1af46aecf5
commit d4317fe172
3 changed files with 46 additions and 2 deletions
+11 -1
View File
@@ -5574,6 +5574,7 @@ static int run(int argc, char *argv[]) {
if (arg_start_mode == START_BOOT) {
_cleanup_free_ char *b = NULL;
const char *p;
int check_os_release, is_os_tree;
if (arg_pivot_root_new) {
b = path_join(arg_directory, arg_pivot_root_new);
@@ -5586,7 +5587,16 @@ static int run(int argc, char *argv[]) {
} else
p = arg_directory;
if (path_is_os_tree(p) <= 0) {
check_os_release = getenv_bool("SYSTEMD_NSPAWN_CHECK_OS_RELEASE");
if (check_os_release < 0 && check_os_release != -ENXIO) {
r = log_error_errno(check_os_release, "Failed to parse $SYSTEMD_NSPAWN_CHECK_OS_RELEASE: %m");
goto finish;
}
is_os_tree = path_is_os_tree(p);
if (is_os_tree == 0 && check_os_release == 0)
log_debug("Directory %s is missing an os-release file, continuing anyway.", p);
else if (is_os_tree <= 0) {
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Directory %s doesn't look like an OS root directory (os-release file is missing). Refusing.", p);
goto finish;