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

Add mount command #1837

Closed
wants to merge 19 commits into from
Closed

Add mount command #1837

wants to merge 19 commits into from

Conversation

frelon
Copy link
Contributor

@frelon frelon commented Sep 26, 2023

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.

Fixes #1781, #1830

@frelon
Copy link
Contributor Author

frelon commented Sep 26, 2023

Pushing this as a rough draft for now, still missing the following pieces:

  • Mount persistent overlays
  • Persistent bind mounts
  • Restrict overlay size
  • Reading kernel cmdline
  • Configuration from env-vars (/run/cos/cos-layout.env)
  • run rootfs stage inside mount command
  • Block overlay device
  • Running fsck
  • Write sentinel files (recovery_mode, active_mode, passive_mode)
  • Recovery booting
  • Tests

@frelon frelon force-pushed the mount-cmd branch 2 times, most recently from 73ea150 to cff705a Compare September 26, 2023 13:48
@codecov-commenter
Copy link

codecov-commenter commented Sep 26, 2023

Codecov Report

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

Comparison is base (4c84315) 75.78% compared to head (01616ce) 71.34%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1837      +/-   ##
==========================================
- Coverage   75.78%   71.34%   -4.44%     
==========================================
  Files          63       65       +2     
  Lines        5789     6251     +462     
==========================================
+ Hits         4387     4460      +73     
- Misses       1092     1459     +367     
- Partials      310      332      +22     
Files Coverage Δ
pkg/action/upgrade.go 61.96% <100.00%> (ø)
pkg/utils/common.go 80.05% <100.00%> (ø)
pkg/systemd/unit.go 70.00% <0.00%> (-30.00%) ⬇️
pkg/constants/constants.go 73.91% <0.00%> (-8.35%) ⬇️
pkg/elemental/elemental.go 82.00% <35.29%> (-1.69%) ⬇️
pkg/features/features.go 59.00% <0.00%> (-12.09%) ⬇️
cmd/mount.go 23.07% <23.07%> (ø)
pkg/types/v1/config.go 77.96% <0.00%> (-8.59%) ⬇️
pkg/config/config.go 83.41% <11.47%> (-12.05%) ⬇️
cmd/config/config.go 61.16% <0.00%> (-13.19%) ⬇️
... and 1 more

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

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 so promising 😉

@frelon frelon force-pushed the mount-cmd branch 2 times, most recently from cbecf85 to e907c00 Compare September 27, 2023 07:11
@frelon frelon linked an issue Sep 27, 2023 that may be closed by this pull request
@frelon frelon force-pushed the mount-cmd branch 2 times, most recently from 8fd30fc to 648a0c9 Compare September 28, 2023 08:46
pkg/action/mount.go Outdated Show resolved Hide resolved
@frelon frelon marked this pull request as ready for review September 29, 2023 14:17
@frelon frelon requested a review from a team as a code owner September 29, 2023 14:17
@frelon frelon force-pushed the mount-cmd branch 9 times, most recently from a95411a to 96d38b4 Compare October 3, 2023 14:43
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.

Very nice! LGTM

@frelon frelon force-pushed the mount-cmd branch 2 times, most recently from 66bd2a8 to 01616ce Compare October 11, 2023 14:46
@frelon
Copy link
Contributor Author

frelon commented Oct 11, 2023

@davidcassany I ended up bumping go to 1.21 as well since I needed it for the slices module, let me know if you want to stay on 1.20!

return err
}

for _, path := range overlay.Paths {
Copy link
Contributor

Choose a reason for hiding this comment

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

a small issue we encountered was bind paths not being ordered, so something like this mistake in the layout file:

        /usr/share/pki/trust/anchors
	/usr/share/pki/trust

would shadow the first bind with the second! Just a heads up as we encountered this :) Patch looks awesome 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Itxaka thanks for the heads up! I will add a commit to sort these in correct order! 👍

frelon added 19 commits November 2, 2023 14:07
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>
Mounts a tmpfs to /run/elemental/overlay with size= flag set

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
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>
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>
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>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
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>
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>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
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>
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
@frelon
Copy link
Contributor Author

frelon commented Nov 29, 2023

Closing in favor of #1866

@frelon frelon closed this Nov 29, 2023
@frelon frelon deleted the mount-cmd branch December 12, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
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