Commit Graph

443 Commits

Author SHA1 Message Date
David Cassany 03914740ba Use chroot to label previously binded mountpoints
This prevents errors with non chrooted setfiles calls
in which fail due to policy divergences between host and
target.

For that purpose a new option to chroot utility has
been included to allow chroot without setting the default
bind mounts for /dev/, /sys and /proc.

Signed-off-by: David Cassany <dcassany@suse.com>
(cherry picked from commit a8982b16ce)
2025-10-01 11:10:15 +02:00
Fredrik Lönnegren 48651071c9 Add snapshotter.type flag to build-disk command
When building a disk image we do not specify the snapshotter, which
configures the expansion mechanism to set COS_STATE partition filesystem
to ext4.

The green flavor uses the btrfs snapshotter, which means when it boots
and tries to mount the COS_STATE partition it expects a btrfs
filesystem, but finds an ext4 one, which errors.

In this commit we add the --snapshotter.type flag to the build-disk
command and set the snapshotter in the Makefile accordingly.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2025-09-30 10:58:50 +02:00
Fredrik Lönnegren 968784c6b2 Adapt tests to new build error
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2025-08-07 13:26:12 +02:00
David Cassany ce35ae6c7d Adapt code and unit tests
Co-authored-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
Signed-off-by: David Cassany <dcassany@suse.com>
2025-08-06 13:53:10 +02:00
Gaurav Mehta cb15d32d90 Minor change to lookup devices using blkid
Minor change to lookup devices using blkid and updating the upgradeSpec
if needed. This may be needed when running elemental upgrade in
multipathd systems

Signed-off-by: Gaurav Mehta <gaurav.mehta@suse.com>
2025-08-06 13:53:10 +02:00
Fredrik Lönnegren d8450e01b9 Avoid panic when MaxSnaps is set to 0
When the MaxSnaps configuration option is set to 0 the following panic
occurs during installation:

```
[PANICKED] Test Panicked
  In [It] at: /usr/lib64/go/1.24/src/runtime/panic.go:115 @ 07/01/25 10:04:57.47

  runtime error: index out of range [0] with length 0

  Full Stack Trace
    github.com/rancher/elemental-toolkit/v2/pkg/snapshotter.(*LoopDevice).cleanOldSnapshots(0xc00025a300)
        /home/frelon/src/elemental-toolkit/pkg/snapshotter/loopdevice.go:468 +0x3e7
    github.com/rancher/elemental-toolkit/v2/pkg/snapshotter.(*LoopDevice).CloseTransaction(0xc00025a300, 0xc000234a00)
        /home/frelon/src/elemental-toolkit/pkg/snapshotter/loopdevice.go:271 +0x11d5
    github.com/rancher/elemental-toolkit/v2/pkg/snapshotter_test.init.func3.12()
        /home/frelon/src/elemental-toolkit/pkg/snapshotter/loopdevice_test.go:204 +0x38e
```

This commit checks that we don't try to delete old snapshots in case
there are none.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2025-07-09 14:23:19 +02:00
Fredrik Lönnegren f132230beb Update copyright year (2025)
Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2025-01-07 16:43:28 +01:00
Loic Devulder 7f707ca021 Add missing Autologin feature
Still not enabled by default, but could be added like any other
features.

Signed-off-by: Loic Devulder <ldevulder@suse.com>
2024-12-03 12:44:21 +01:00
Loic Devulder 692c63331b Fix architecture platform value
Without this we always have the host architecture instead of the
platform one in cross-compilation.

Signed-off-by: Loic Devulder <ldevulder@suse.com>
2024-12-03 12:44:21 +01:00
Bernhard M. Wiedemann d9873c8404 Make tar creation deterministic
for that, we sort entries, override owner+group+mtime
and omit ctime+atime
2024-12-02 16:46:09 +01:00
David Cassany Viladomat 527c12d007
Fixes squashfs images creation (#2230)
* Fixes squashfs images creation (bsc#1233289)

If upgrading from a container including the root of the host
mounted in /host the upgrade process does not exclude the /host
path and other stateful paths such as /run.

This commit sets the default excludes used in rsync calls
to also apply for mksquashfs.

Signed-off-by: David Cassany <dcassany@suse.com>

* Define static method for default exclude relative paths

This commit defines static methods for excluded paths in
sync operations. One method for relative paths and
another one with the same result rooted to a given path.
It also uses wildcards to only exclude certain directories
content while keeping the directory itself.

Signed-off-by: David Cassany <dcassany@suse.com>

* Add some additional unit tests for rsync wrappers

Signed-off-by: David Cassany <dcassany@suse.com>

---------

Signed-off-by: David Cassany <dcassany@suse.com>
2024-11-13 11:03:25 +01:00
David Cassany 19606359c3 Fix dracut modules dependencies
Signed-off-by: David Cassany <dcassany@suse.com>
2024-11-11 14:58:41 +01:00
Rodolphe de Saint Léger 5020753976 Change btrfs state volumes detection
btrfs volume IDs are not accurate with newer btrfs formated volumes. They are now matched using their names.

Changes:
- added '-a' to subvolume list to encure that full subvolume path is available
- changed btrfs probe from ID match to name match
- changed state volume match in findStateMount from target mount point to source subvolume
2024-11-07 19:03:24 +01:00
Rodolphe de Saint Léger 5b2bb7ab14 Add orange btrfs snapshotter support
Changes:
- ensure that kernel and initrd are relative links
- add 'active_snap' variable to grub (managed by snapshotter)
- add 'root_subpath' variable to grub
- snapper can now be used on orange flavor (see notes)

Notes:
- 'active_snap' and 'root_subpath' allows grub to build a relative path to the kernel and initrd when btrfs_relative_path is not available.
- Snapper works on orange flavor, however it can take several minutes before the daemon initialize in active or passive mode. If elemental upgrade is invoked during this time it will fail.
2024-11-07 19:03:24 +01:00
Fredrik Lönnegren 1898d5db2e Use --strict flag in elemental-setup services
The default behavior has been to hide any errors and only log warnings.
Using the --strict flag will ensure any yip errors are actually
reported.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-11-06 15:01:00 +01:00
David Cassany eb77a4ca92 Update spec dependecies and dracut module dependencies
Signed-off-by: David Cassany <dcassany@suse.com>
2024-11-06 09:59:36 +01:00
David Cassany 733f2b4428 Remove few leftovers from snapshotter tests
Signed-off-by: David Cassany <dcassany@suse.com>
2024-11-06 09:59:36 +01:00
David Cassany Viladomat ca0ac59258
Btrfs snapshotter without snapper (#2220)
* Isolating btrfs and snapper specific logic

Signed-off-by: David Cassany <dcassany@suse.com>

* Define a backend interface for btrfs snapshotter

This commit adds a backend interface in btrfs snapshotter. The interface
essentially wraps snapper and btrfs utilities.

The idea is make a pure btrfs implementation of the interface and
also a snapper based implementation.

The functions that snapper can't provide are simply managed by the btrfs
implementation.

Signed-off-by: David Cassany <dcassany@suse.com>

* Move snapper configuration to snapper backend

Signed-off-by: David Cassany <dcassany@suse.com>

* Implement btrfs backend

This commit implements the btrfs backend for the btrfs snapshotter
and moves all the logic of specific btrfs client calls there.

The backend interface is also refined for that purpose.

Signed-off-by: David Cassany <dcassany@suse.com>

* Make the btrfs snapshotter backend configurable

Signed-off-by: David Cassany <dcassany@suse.com>

* Add some method comment headers

Signed-off-by: David Cassany <dcassany@suse.com>

* Few small changes to facilitate testing

Signed-off-by: David Cassany <dcassany@suse.com>

* Add btrfs-backend unit tests

Signed-off-by: David Cassany <dcassany@suse.com>

* Add snapper backend unit tests

Signed-off-by: David Cassany <dcassany@suse.com>

* revert back to snapper for green example

Signed-off-by: David Cassany <dcassany@suse.com>

---------

Signed-off-by: David Cassany <dcassany@suse.com>
2024-11-05 13:47:03 +00:00
David Cassany Viladomat 30a64d70be
Add cloud-init paths of the new root in 'after-*' hooks (#2192)
* Add cloud-init paths of the new root in 'after-*' hooks

This commit enables to run the non chrooted 'after-*' hooks
included in the newly deployed image root. This specially applies to the
install, reset, upgrade and build-disk commands.

Moreover, 'after-disk' command now includes static reference paths to
the new root and working directory, so that those can be used within
the hooks regardless of the choosen output directory.


* Include arm-firwmare feature

This commit introduces an arm-firmware feature adding
the required after-* hooks to ensure the RPi firmware is
copied to the EFI partition.

It could be, eventually, extended to support other boards
and it does not harm systems which are not including RPi
firmware.


* Allow features to be passed as arguments

Signed-off-by: David Cassany <dcassany@suse.com>
2024-09-25 09:47:12 +02:00
Andrea Mazzotti 98ade87d7b
Expose max snapshots environment variable (#2193)
* Expose SNAPSHOTTER_MAX_SNAPS run variable

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-09-25 09:39:52 +02:00
David Cassany Viladomat 064546f18b
Improve state file testing (#2190)
* Include 'build-disk' action traces in initial state yaml
* Include integration tests for the 'state' subcommand
* Add state check for installer tests

Signed-off-by: David Cassany <dcassany@suse.com>
2024-09-18 10:45:17 +02:00
Andrea Mazzotti fa2306d632
Implement state subcommand (#2182)
* Implement state subcommand

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-09-13 08:59:30 +02:00
Andrea Mazzotti dc52491a14
Add user defined labels to snapshot info (#2175)
* Add user defined labels to snapshot info

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-09-12 14:43:00 +02:00
Fredrik Lönnegren 1a529527ae Bump yip to v1.9.3
This removes the Git plugin and alot of go dependencies.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-09-05 14:47:12 +02:00
David Cassany 5e0a28c63c Do not require network in initrd by default
Signed-off-by: David Cassany <dcassany@suse.com>
2024-09-05 13:20:53 +02:00
David Cassany 75e17df1c5 Bump to v2.1.1 for tests and fix recovery test
Signed-off-by: David Cassany <dcassany@suse.com>
2024-09-05 13:20:53 +02:00
Andrea Mazzotti b1bac09cb7
Expose ELEMENTAL_CLOUD_INIT_PATHS option (#2163)
* Expose ELEMENTAL_CLOUD_INIT_PATHS option

Signed-off-by: Andrea Mazzotti <andrea.mazzotti@suse.com>
2024-08-20 13:37:27 +02:00
David Cassany Viladomat b1cc863b10
Make RAW disks recovery partition expandable (#2159)
Signed-off-by: David Cassany <dcassany@suse.com>
2024-08-08 10:38:52 +02:00
David Cassany Viladomat 44b2e7b563
Bump efi library (#2158)
* Bump go-efilib

Signed-off-by: David Cassany <dcassany@suse.com>

* Adapt to new efilib library

Signed-off-by: David Cassany <dcassany@suse.com>

---------

Signed-off-by: David Cassany <dcassany@suse.com>
2024-08-07 10:38:44 +02:00
David Cassany 76caad5f6e Add test for auto disabled boot entry in Grub
Signed-off-by: David Cassany <dcassany@suse.com>
2024-07-22 15:59:15 +02:00
David Cassany Viladomat 22996ef70b
Allow insecure registries (#2131)
* Allow skipping TLS verification on registries

Signed-off-by: David Cassany <dcassany@suse.com>

* Improve error logging

Signed-off-by: David Cassany <dcassany@suse.com>

* Fix flag default value

Signed-off-by: David Cassany <dcassany@suse.com>

* Fix image extractor mock and use default TLS verification for tests

Signed-off-by: David Cassany <dcassany@suse.com>

---------

Signed-off-by: David Cassany <dcassany@suse.com>
2024-07-09 12:01:39 +00:00
David Cassany b41f7d20ad Bump tp yip 1.6.2
Signed-off-by: David Cassany <dcassany@suse.com>
2024-07-04 16:05:47 +02:00
David Cassany Viladomat 2b23133c08
Bump mount utils (#2099)
* Update k8s.io/mount-utils to latest version
* Mounter without systemd integration
* Update go.mod

Signed-off-by: David Cassany <dcassany@suse.com>
Signed-off-by: David Cassany Viladomat <dcassany@suse.com>
Co-authored-by: Francesco Giudici <francesco.giudici@gmail.com>
2024-06-21 13:16:53 +00:00
David Cassany Viladomat 15a10cc4f5
Make EFI partition size configurable at install time (#2105)
* Make EFI partition size configurable at install time
* Add a custom EFI size test
* Rename efi to bootloader partition in config.yaml
* Rename EFI variable to Boot
* Rename constants

Signed-off-by: David Cassany <dcassany@suse.com>
2024-06-19 06:23:33 +02:00
David Cassany 28c4e4735e Use fake mounter in tests
Signed-off-by: David Cassany <dcassany@suse.com>
2024-06-11 14:46:12 +02:00
David Cassany 897d872acc Ensure subvolume snapshots is mounted to list snapshots
Signed-off-by: David Cassany <dcassany@suse.com>
2024-06-10 13:48:03 +02:00
David Cassany 9f2f2368a8 Remove pre-existing Elemental initrds
Signed-off-by: David Cassany <dcassany@suse.com>
2024-06-07 11:55:27 +02:00
David Cassany fbe9042125 Fix overlaydir setup
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-31 11:58:49 +02:00
Fredrik Lönnegren 48d6ca488b Refactor and test efi manager
This commit refactors the efi mocks out of pkg/efi/types.go and adds a
ReadLoadOptions method the the efivars interface.

We also add some tests for creating a new BootManager and verify that
the ReadLoadOptions error does not bubble up from NewBootManager method.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-23 08:59:17 +02:00
Fredrik Lönnegren 2e56a099b3 Do not return error for efi.ReadLoadOption
When encountering a boot-entry for a device-path that go-efilib is
unable to parse we should just skip that entry instead of erroring out.

This same behavior is used earlier in the same loop so this should fix
an edge-case where the boot entry is parseable but the device-path is
not.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-23 08:59:17 +02:00
Fredrik Lönnegren fa82c1b1c6
Fix recovery test (#2086)
During recovery test when writing the upgraded install state yaml file
snapper fails trying to list snapshots because of trying to selinux
relabel a .snapshots dir that is read-only.

This error does not impact functionality and should be discarded.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-22 13:13:34 +02:00
David Cassany 54664f8cf5 Solve few linter warnings
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-15 16:44:49 +02:00
David Cassany f0d9cb30b3 Remove the work around for bsc#1210690 and simplify code
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-15 15:00:41 +02:00
Fredrik Lönnegren 5a84014519
Bootloader-in-rootfs=true (#2071)
* Bootloader-in-rootfs=true

Change the default value of bootloader-in-rootfs flag for build-iso
command to true.

* Change default bootloader-in-rootfs

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-15 11:16:50 +02:00
David Cassany Viladomat 3f96b5e7a5
Relabel presistent paths only at first boot (#2080)
* Relabel presistent paths only at first boot
* Check relabelled flag file in unit tests

Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-15 11:14:33 +02:00
David Cassany f3d4cfd62c Ensure SELinux relabelling can be disabled in configfile
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-14 15:45:44 +02:00
David Cassany 7686d121a6 Refine relabel step
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-14 09:30:20 +02:00
David Cassany 6c301f2e98 Move mount config file to /run/elemental
Signed-off-by: David Cassany <dcassany@suse.com>
2024-05-10 15:09:08 +02:00
Fredrik Lönnegren a4c414f55b
Add extra-cmdline flag to build-iso command (#2072)
* Add extra-cmdline flag to build-iso command

The extra-cmdline can be used to customize the kernel commandline used
for the ISO.

Some arbitrary flags were moved to the extra-cmdline in order to support
overriding security and consoles.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-10 14:30:13 +02:00
Fredrik Lönnegren 1c89db027a
SELinux relabel on boot (#2074)
In this commit we add selinux support to the mount command.

During mount we put a list of persistent+ephemeral directories in
/run/systemd/extra-relabel.d/elemental.layout in order to make systemd
relabel the directories before loading the policy.

We also try to chroot into the new sysroot and run setfiles using a find
wrapper to set on deepest files first.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
2024-05-10 13:43:49 +02:00