From 38f6b9b3ab36f7d828cccf1a57baf19ce07bba2b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 12 Apr 2024 08:56:13 -0400 Subject: [PATCH] init-fs: Add --epoch I want to add another variant here, and `--modern` is now old. Let's acknowledge that we may want to make even more changes in the future. So `--modern == --epoch=1` but I will add `--epoch=2` after this. --- man/ostree-admin-init-fs.xml | 37 ++++++++++++++++++++++++--- src/ostree/ot-admin-builtin-init-fs.c | 13 +++++++++- tests/admin-test.sh | 16 +++++++----- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/man/ostree-admin-init-fs.xml b/man/ostree-admin-init-fs.xml index 50e6d44e18..ead3d325d4 100644 --- a/man/ostree-admin-init-fs.xml +++ b/man/ostree-admin-init-fs.xml @@ -57,17 +57,48 @@ License along with this library. If not, see . Description - Initialize an empty physical root filesystem in the designated PATH, with normal toplevels and correct permissions for each directory. Primarily useful for operating system installers. + Initialize an empty physical root filesystem in the designated PATH, with normal toplevels and correct permissions for each directory. + Primarily useful for operating system installers. + + + Options + + + + + + Equivalent to --epoch=1. + + + + + + + This accepts an integer value in the range [0-1], inclusive. The default is zero + for compatibility. + + + When set to 1, the command will skip adding a number of toplevel "API filesystems" + such as /proc + to the toplevel of the physical root. These should be unnecessary, as they + should only be mounted in the final deployment root. The main exception + is /boot, which may need to be mounted in some setups + before the target root. + + + + + Example $ mkdir /example - $ ostree admin init-fs /example + $ ostree admin init-fs --epoch=1 /example $ ls /example - boot   dev   home   ostree   proc   root   run   sys   tmp + boot   diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c index 9cda9afcfa..7662f47954 100644 --- a/src/ostree/ot-admin-builtin-init-fs.c +++ b/src/ostree/ot-admin-builtin-init-fs.c @@ -28,9 +28,13 @@ #include static gboolean opt_modern; +static gint opt_epoch; static GOptionEntry options[] = { { "modern", 0, 0, G_OPTION_ARG_NONE, &opt_modern, "Only create /boot and /ostree", NULL }, + { "epoch", 'E', 0, G_OPTION_ARG_INT, &opt_epoch, + "An integer value, defines initial state. Must be in the range [0-1], inclusive.", + NULL }, { NULL } }; gboolean @@ -62,12 +66,19 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invoca if (!glnx_shutil_mkdir_p_at (root_dfd, "boot", 0755, cancellable, error)) return FALSE; + if (opt_epoch < 0) + return glnx_throw (error, "Invalid epoch: %d", opt_epoch); + + /* --modern is equivalent to --epoch=1 */ + if (opt_modern && opt_epoch == 0) + opt_epoch = 1; + /* See https://github.com/coreos/coreos-assembler/pull/688 * For Fedora CoreOS at least, we have this now to the point where we don't * need this stuff in the physical sysroot. I'm not sure we ever really did, * but to be conservative, make it opt-in to the new model of just boot/ and ostree/. */ - if (!opt_modern) + if (opt_epoch == 0) { const char *traditional_toplevels[] = { "boot", "dev", "home", "proc", "run", "sys" }; for (guint i = 0; i < G_N_ELEMENTS (traditional_toplevels); i++) diff --git a/tests/admin-test.sh b/tests/admin-test.sh index 3417d01adb..2cd8473270 100644 --- a/tests/admin-test.sh +++ b/tests/admin-test.sh @@ -21,13 +21,15 @@ set -euo pipefail echo "1..$((31 + ${extra_admin_tests:-0}))" -mkdir sysrootmin -${CMD_PREFIX} ostree admin init-fs --modern sysrootmin -assert_has_dir sysrootmin/boot -assert_has_dir sysrootmin/ostree/repo -assert_not_has_dir sysrootmin/home -rm sysrootmin -rf -echo "ok init-fs --modern" +for flag in --modern --epoch=1; do + mkdir sysrootmin + ${CMD_PREFIX} ostree admin init-fs --modern sysrootmin + assert_has_dir sysrootmin/boot + assert_has_dir sysrootmin/ostree/repo + assert_not_has_dir sysrootmin/home + rm sysrootmin -rf +done +echo "ok init-fs" function validate_bootloader() { cd ${test_tmpdir};