Skip to content

Commit

Permalink
init-fs: Add --epoch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgwalters committed Apr 12, 2024
1 parent 3c2e9d0 commit 38f6b9b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
37 changes: 34 additions & 3 deletions man/ostree-admin-init-fs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,48 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
<title>Description</title>

<para>
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.
</para>
</refsect1>


<refsect1>
<title>Options</title>

<variablelist>
<varlistentry>
<term><option>--modern</option></term>
<listitem><para>
Equivalent to <literal>--epoch=1</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--epoch</option></term>
<listitem><para>
This accepts an integer value in the range [0-1], inclusive. The default is zero
for compatibility.
</para>
<para>
When set to 1, the command will skip adding a number of toplevel "API filesystems"
such as <literal>/proc</literal>
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 <literal>/boot</literal>, which may need to be mounted in some setups
before the target root.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1>
<title>Example</title>
<para><command>$ mkdir /example</command></para>
<para><command>$ ostree admin init-fs /example</command></para>
<para><command>$ ostree admin init-fs --epoch=1 /example</command></para>
<para><command>$ ls /example </command></para>
<para>
<emphasis>boot</emphasis>&nbsp;&nbsp; <emphasis>dev</emphasis>&nbsp;&nbsp; <emphasis>home</emphasis>&nbsp;&nbsp; <emphasis>ostree</emphasis>&nbsp;&nbsp; <emphasis>proc</emphasis>&nbsp;&nbsp; <emphasis>root</emphasis>&nbsp;&nbsp; <emphasis>run</emphasis>&nbsp;&nbsp; <emphasis>sys</emphasis>&nbsp;&nbsp; <emphasis>tmp</emphasis>
<emphasis>boot</emphasis>&nbsp;&nbsp;
</para>
</refsect1>
</refentry>
13 changes: 12 additions & 1 deletion src/ostree/ot-admin-builtin-init-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
#include <glib/gi18n.h>

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
Expand Down Expand Up @@ -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++)
Expand Down
16 changes: 9 additions & 7 deletions tests/admin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 38f6b9b

Please sign in to comment.