Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor early system mounting #1866

Merged
merged 8 commits into from
Dec 12, 2023
Merged

Conversation

frelon
Copy link
Contributor

@frelon frelon commented Nov 29, 2023

An updated mount command (from #1837).

Adds a new feature/dracut-module elemental-sysroot responsible for mounting the correct image as a base.
The elemental-rootfs feature actually mounts the elemental overlays.

This also reworks the kernel parameters used by elemental.

  • elemental.image=active|passive|recovery
  • elemental.disable

And also starts to move the active|passive|recovery_mode files to /run/elemental with all the overlay and other mounts.

Fixes #1781, #1830

@frelon frelon linked an issue Nov 29, 2023 that may be closed by this pull request
@frelon frelon mentioned this pull request Nov 29, 2023
@frelon frelon force-pushed the updated-mount-cmd branch 2 times, most recently from d67b798 to 6938616 Compare November 29, 2023 14:45
@codecov-commenter
Copy link

codecov-commenter commented Nov 29, 2023

Codecov Report

Attention: 348 lines in your changes are missing coverage. Please review.

Comparison is base (840c80c) 75.96% compared to head (6664c06) 72.39%.

Files Patch % Lines
pkg/action/mount.go 5.94% 169 Missing and 5 partials ⚠️
cmd/config/config.go 0.00% 55 Missing ⚠️
pkg/config/config.go 12.72% 48 Missing ⚠️
pkg/types/v1/config.go 0.00% 28 Missing ⚠️
cmd/mount.go 23.07% 19 Missing and 1 partial ⚠️
pkg/features/features.go 18.75% 12 Missing and 1 partial ⚠️
pkg/constants/constants.go 0.00% 7 Missing ⚠️
pkg/systemd/unit.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1866      +/-   ##
==========================================
- Coverage   75.96%   72.39%   -3.58%     
==========================================
  Files          66       68       +2     
  Lines        6912     7277     +365     
==========================================
+ Hits         5251     5268      +17     
- Misses       1290     1631     +341     
- Partials      371      378       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@frelon frelon force-pushed the updated-mount-cmd branch 5 times, most recently from c7b5bcc to 1804b1f Compare December 6, 2023 14:31
@frelon frelon changed the title [WIP] Updated mount cmd Updated mount cmd Dec 6, 2023
@frelon frelon changed the title Updated mount cmd Refactor early system mounting Dec 6, 2023
@frelon frelon marked this pull request as ready for review December 6, 2023 16:28
@frelon frelon requested a review from a team as a code owner December 6, 2023 16:28
@frelon frelon force-pushed the updated-mount-cmd branch 2 times, most recently from 42243d2 to 43ecf6c Compare December 7, 2023 08:24
Copy link
Contributor

@kkaempf kkaempf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nearly impossible to review. 😞

Approving anyways - if it fails, you're the one to fix it 😉

@frelon frelon force-pushed the updated-mount-cmd branch 2 times, most recently from 6fb5af6 to 6cd4bd6 Compare December 8, 2023 14:22
The mount command mounts the system and is meant to run in an initrd to
actually mount the root filesystem and use systemd to switch-root into
it.

It also optionally writes an /etc/fstab file to the newly mounted
system so that systemd will mount the system after switching root.

The command is used in the new dracut module elemental-rootfs, which
will coexist with immutable-rootfs (they are functionally the same)
until immutable-rootfs can be deprecated.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add tmpfs overlay mount

Mounts a tmpfs to /run/elemental/overlay with size= flag set

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Examples use the new elemental-rootfs

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add persistent overlay mounts

Persistent mounts use the /run/elemental/persistent/.state directory to
store upper and work dirs.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add sentinel files

Write sentinel file (active_mode, passive_mode, recovery_mode) to
/run/cos or /run/elemental based on which kernel cmdline is used
(cos-img/filename or elemental.image)

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Read kernel cmdline for mount

This commit adds capabilities to the mount command to read configuration
from the kernel cmdline. The supported parameters are:

* elemental.disable + rd.cos.disable
* elemental.image + cos-img/filename
* elemental.oemlabel + rd.cos.oemlabel

In the new elemental.image parameter we can specify
active|passive|recovery instead of the path to the image.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Enable recovery booting and reset

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Load env vars

Currently supported:
* OVERLAY
* RW_PATHS
* PERSISTENT_STATE_PATHS
* PERSISTENT_STATE_BIND

Loaded from files (if they exist):
* /run/elemental/layout.env
* /run/cos/cos-layout.env

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Run rootfs stage inside mount command

Since the rootfs stage should be run between mounting the image and
mounting the rest of the system I added a call to RunStage that takes
care of this and then uses godotenv dependency to actually load
/run/elemental/layout.env and /run/cos/cos-layout.env.

This means the old way of generating layout files will still work with
the new mount-command.

The caveat here is that in the current implementation the rootfs stage
will run twice, once from the elemental-setup-rootfs service and once
from this command. I would say the easiest way forward is to remove the
elemental-setup-rootfs when switching to elemental-rootfs as the default
mounting module.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add persistent bind mounts

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add block overlay

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Use registry.opensuse.org for example images

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Minor changes to get tests working

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Fsck partitions before mounting

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Fix for fsck

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

More mount tests

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Comment mount example configuration

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Add elemental-setup services to elemental-rootfs

The elemental-setup and rootfs features are heavily dependent on each
other.

This commit copies the elemental-setup feature into elemental-rootfs,
and changes the mount-command to actually start the
elemental-setup-rootfs service during mount to not run the yip rootfs
stage twice.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>

Fix lint goconst

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
@frelon frelon force-pushed the updated-mount-cmd branch 2 times, most recently from 58f1a8b to 314938d Compare December 12, 2023 08:42
The features elemental-sysroot, elemental-rootfs and elemental-setup are
used for mounting the root filesystem and all overlays.

elemental-sysroot is used for mounting state/recovery partition to
/run/elemental/state, and then mounting the image from the partition
based on kernel parameters.

elemental-setup actually runs the different stages of boot using
elemental run-stage command.

elemental-rootfs runs the 'elemental mount' command to mount tmpfs
overlays, persistent overlays and then writes the /etc/fstab to actually
mount when pivoting to the new root.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
This commit goes through the early systemd services run in dracut and
adds Wants,Before,Requires to each step to make them run during the
correct stage of the bootup (man dracut.bootup).

We also change all the /run/cos and /run/initramfs/cos-state to the new
/run/elemental and /run/initramfs/elemental-state directories.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Tests still use /run/cos, this commit adds back
/run/cos/active|passive|recovery_mode files

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
This commit makes the immutable-rootfs module forwards compatible with
the other changes in mount, elemental-sysroot and elemental-setup.

It uses the new elemental.image and elemental.oemlabel cmdline paramters
if found, otherwise falls back to the old parameters and also sets the
/run/elemental/active|passive|recovery_mode files.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Just some minor comments here and there. Little things I am also fine to address them in follow up PRs, so we make further changes more manageable and reviewable.

examples/green/Dockerfile Outdated Show resolved Hide resolved
examples/tumbleweed/Dockerfile Outdated Show resolved Hide resolved
ActiveImgFile = "active.img"
PassiveImgFile = "passive.img"
RecoveryImgFile = "recovery.img"
TransitionImgFile = "transition.img"
ActiveImgPath = "/cOS/active.img"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think we should rewrite those as

ActiveImgPath = "/cOS/" + ActiveImgFile

Or even consider having only another constant as ImagesPath = "/cOS" and simple unify both when needed.

- /var
- /etc
- /srv
persistent:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the persistent block device defined? I think this should be configurable and probably default to our persistent partition so it can be omitted from the config file, but still configurable.

mount:
sysroot: /sysroot # Path to mount system to
write-fstab: true # Write fstab into sysroot/etc/fstab
overlay:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this is the right name. I mean if we have persistent then probably we should have something like transient or ephemeral. Otherwise one could think this overlay device setting is for the persistent data.


# Include utilities required for elemental-setup services,
# probably a devoted dracut module makes sense
inst_multiple -o \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this list needs to be revisited, most of this tools are not needed at all. It should only include the tools required for the elemental-rootfs.service, probably none.

declare systemdsystemunitdir=${systemdsystemunitdir}

inst_multiple \
mount mountpoint sort rmdir findmnt rsync cut realpath basename lsblk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below, this list feels outdated. Be aware that these might be required to be included to some other module then.

@frelon frelon enabled auto-merge (squash) December 12, 2023 11:34
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
@frelon frelon disabled auto-merge December 12, 2023 12:54
This should fix installer-tests in CI since the /oem might not exist
when booting from ISO.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
@frelon frelon enabled auto-merge (squash) December 12, 2023 13:29
@frelon frelon merged commit 9676ec9 into rancher:main Dec 12, 2023
14 checks passed
@frelon frelon deleted the updated-mount-cmd branch December 12, 2023 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use non-FHS path as default for persistent state storage Implement immutable-rootfs module in elemental-cli
4 participants