-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor early system mounting (#1866)
* Add mount command 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> * Add elemental-sysroot feature 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> * Update sysroot, setup and rootfs dracut modules 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> * Test compatibility 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> * Update to latest ele-testhelpers Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com> * Forwards compatibility for immutable-rootfs feat 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> * Update init features for green and tumbleweed Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com> * Remove oem mounts from elemental-setup-initramfs 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> --------- Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
- Loading branch information
Showing
50 changed files
with
1,198 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ iso-meta.yaml | |
.qemu/ | ||
.loop | ||
tests/**/logs | ||
tests/vmstdout | ||
serial_port1.log | ||
capture.webm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright © 2022 - 2023 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"k8s.io/mount-utils" | ||
|
||
"github.com/rancher/elemental-toolkit/cmd/config" | ||
"github.com/rancher/elemental-toolkit/pkg/action" | ||
"github.com/rancher/elemental-toolkit/pkg/constants" | ||
elementalError "github.com/rancher/elemental-toolkit/pkg/error" | ||
) | ||
|
||
func NewMountCmd(root *cobra.Command) *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "mount", | ||
Short: "Mount an elemental system into the specified sysroot", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
mounter := mount.New(constants.MountBinary) | ||
|
||
cfg, err := config.ReadConfigRun(viper.GetString("config-dir"), cmd.Flags(), mounter) | ||
if err != nil { | ||
cfg.Logger.Errorf("Error reading config: %s\n", err) | ||
return elementalError.NewFromError(err, elementalError.ReadingRunConfig) | ||
} | ||
|
||
cmd.SilenceUsage = true | ||
spec, err := config.ReadMountSpec(cfg, cmd.Flags()) | ||
if err != nil { | ||
cfg.Logger.Errorf("Error reading spec: %s\n", err) | ||
return elementalError.NewFromError(err, elementalError.ReadingSpecConfig) | ||
} | ||
|
||
if spec.Disable { | ||
cfg.Logger.Info("Mounting disabled, exiting") | ||
return nil | ||
} | ||
|
||
cfg.Logger.Info("Mounting system...") | ||
return action.RunMount(cfg, spec) | ||
}, | ||
} | ||
root.AddCommand(c) | ||
return c | ||
} | ||
|
||
var _ = NewMountCmd(rootCmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.