Skip to content

Commit b651f81

Browse files
mount: substantially rework mounting code
This represents a substantial rewrite of the mounting code. composefs-pivot-sysroot is renamed to composefs-prepare-root and now understands ostree's /usr/lib/ostree/prepare-root.conf file (supporting transient overlays for /etc and /, also adding support /var). In addition it's possible to specify that /etc and /var are one of: - none: no mount, will be readonly contents of composefs at runtime - bind: straight bind-mount from the state directory - overlay: state directory contains the upperdir of an overlay - transient: alias for transient=true (ie: overlay with tmpfs) This follows the /sysroot/state/ layout discussed in #38. The default for /etc is 'overlay' and the default for /var is 'bind'. In general the new command focuses less on absolute minimalism: we now have proper commandline parsing and our config file is parsed as toml via serde. This makes the command (which gets included in the initramfs) a fair bit bigger: it's 1.2MB now (but compresses to about half that). We can deal with that later if it's really a problem, though. We now use the system mount APIs in a more modern way: the filesystem tree is now assembled purely from file descriptors and mounted in place only after it's complete, resulting in very readable code. This depends on a very new kernel: the merge window on 6.15 isn't closed yet, but we already depend on many of the feature of the mount API that got added in this release. Fortunately, rawhide already has a pre-release version that we can test against: add a new integration test based on it. At the same time, we preserve backwards compatibility to older kernels via a compatibility layer which remains mostly isolated in a separate file. We even add compatibility with RHEL 9 (and add another integration test for that). The inclusion of the compatibility code is controlled by the feature flags `pre-6.15` and `rhel9` (which implies `pre-6.15`). Rework the examples a bit to add more explicit support for separate OSes which are now accepted as the $1 parameter to each build script: the OS parameter now controls the Containerfile used as well as the build features. Also remove the ssh-key generation at build time from all of the examples: /etc overlay support is working now and all of the images will generate their ssh keys at first boot, so we no longer need this cludge. Add the start of a new integration test which can run unprivileged on the host system inside of a fresh namespace. Signed-off-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
1 parent 0f2143b commit b651f81

File tree

37 files changed

+854
-255
lines changed

37 files changed

+854
-255
lines changed

.github/workflows/examples.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ jobs:
1616
strategy:
1717
matrix:
1818
example:
19-
- { dir: 'uki', file: 'Containerfile' }
20-
- { dir: 'uki', file: 'Containerfile.arch' }
21-
- { dir: 'bls', file: 'Containerfile' }
22-
- { dir: 'bls', file: 'Containerfile.arch' }
23-
- { dir: 'bls', file: 'Containerfile.ubuntu' }
24-
- { dir: 'unified', file: 'Containerfile' }
19+
- { dir: 'bls', os: 'arch' }
20+
- { dir: 'bls', os: 'fedora' }
21+
- { dir: 'bls', os: 'rawhide' }
22+
- { dir: 'bls', os: 'rhel9' }
23+
- { dir: 'bls', os: 'ubuntu' }
24+
- { dir: 'uki', os: 'arch' }
25+
- { dir: 'uki', os: 'fedora' }
26+
- { dir: 'unified', os: 'fedora' }
2527
fail-fast: false
2628

2729
steps:
@@ -67,4 +69,4 @@ jobs:
6769
- name: Run example tests
6870
run: |
6971
export PATH="${HOME}/bin:${PATH}"
70-
examples/test/run ${{ matrix.example.dir }} -f ${{ matrix.example.file }}
72+
examples/test/run ${{ matrix.example.dir }} ${{ matrix.example.os }}

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ readme = "README.md"
1111
default-run = "cfsctl"
1212
exclude = ["/.git*", "/examples/"]
1313

14+
[features]
15+
rhel9 = ['pre-6.15']
16+
'pre-6.15' = []
17+
1418
[dependencies]
1519
anyhow = { version = "1.0.97", default-features = false }
1620
async-compression = { version = "0.4.22", default-features = false, features = ["tokio", "gzip"] }
@@ -23,11 +27,13 @@ log = "0.4.27"
2327
oci-spec = "0.7.1"
2428
regex-automata = { version = "0.4.9", default-features = false }
2529
rustix = { version = "1.0.3", features = ["fs", "mount", "process"] }
30+
serde = "1.0.219"
2631
sha2 = "0.10.8"
2732
tar = { version = "0.4.44", default-features = false }
2833
tempfile = "3.19.1"
2934
thiserror = "2.0.12"
3035
tokio = "1.44.1"
36+
toml = "0.8.20"
3137
xxhash-rust = { version = "0.8.15", features = ["xxh32"] }
3238
zerocopy = { version = "0.8.24", features = ["derive"] }
3339
zstd = "0.13.3"

examples/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*/VARS_CUSTOM.secboot.fd*
22
/*/cfsctl
3-
/*/extra/usr/lib/dracut/modules.d/37composefs/composefs-pivot-sysroot
3+
/*/extra/usr/lib/dracut/modules.d/37composefs/composefs-setup-root
44
/*/*.qcow2
55
/*/secureboot
66
/*/tmp/

examples/bls/Containerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
55
set -eux
66
dnf --setopt keepcache=1 install --allowerasing -y systemd util-linux skopeo composefs strace dosfstools kernel openssh-server
77
systemctl enable systemd-networkd
8-
/usr/libexec/openssh/sshd-keygen ed25519
9-
/usr/libexec/openssh/sshd-keygen rsa
10-
/usr/libexec/openssh/sshd-keygen ecdsa
118
passwd -d root
129
mkdir /sysroot
1310
mkdir /composefs-meta

examples/bls/Containerfile.arch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ RUN <<EOF
88
pacman -Syu --noconfirm
99
pacman -Sy --noconfirm skopeo composefs strace dosfstools linux mkinitcpio btrfs-progs openssh
1010
systemctl enable systemd-networkd systemd-resolved sshd
11-
ssh-keygen -A
1211
passwd -d root
1312
mkdir /sysroot
1413
kernel-install add "$(ls /usr/lib/modules)" /usr/lib/modules/"$(ls /usr/lib/modules)"/vmlinuz

examples/bls/Containerfile.rawhide

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM fedora:rawhide
2+
COPY extra /
3+
COPY cfsctl /usr/bin
4+
RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
5+
set -eux
6+
dnf --setopt keepcache=1 install --allowerasing -y systemd util-linux skopeo composefs strace dosfstools kernel openssh-server
7+
systemctl enable systemd-networkd
8+
passwd -d root
9+
mkdir /sysroot
10+
mkdir /composefs-meta
11+
mv /boot /composefs-meta
12+
mkdir /boot
13+
EOF
14+
RUN true # hack to get an extra layer

examples/bls/Containerfile.rhel9

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# FROM docker.io/redhat/ubi9 missing: dosfstools, kernel
2+
FROM quay.io/centos/centos:9
3+
COPY extra /
4+
COPY cfsctl /usr/bin
5+
RUN --mount=type=cache,target=/var/cache/libdnf5 <<EOF
6+
set -eux
7+
dnf --setopt keepcache=1 install --allowerasing -y \
8+
systemd util-linux skopeo composefs strace dosfstools kernel openssh-server passwd NetworkManager
9+
systemctl enable NetworkManager
10+
kver="$(ls /usr/lib/modules)"
11+
cp /usr/lib/modules/*/vmlinuz /boot # ???
12+
mkdir -p /boot/loader/entries
13+
tee /boot/loader/entries/example.conf <<EOE
14+
title composefs example
15+
options root=/dev/vda2
16+
linux /vmlinuz
17+
initrd /initramfs-${kver}.img
18+
EOE
19+
rm -r /tmp
20+
ln -sf var/tmp /tmp
21+
passwd -d root
22+
mkdir /sysroot
23+
mkdir /composefs-meta
24+
mv /boot /composefs-meta
25+
mkdir /boot
26+
EOF
27+
RUN true # hack to get an extra layer

examples/bls/Containerfile.ubuntu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ RUN <<EOF
1717
-I "/usr/lib/systemd/systemd-sysroot-fstab-check" \
1818
--kver $(ls /usr/lib/modules) --force
1919
systemctl enable systemd-networkd systemd-resolved
20-
ssh-keygen -A
2120
passwd -d root
2221
kernel-install add $(cd /usr/lib/modules && echo *) /boot/vmlinuz-$(cd /usr/lib/modules && echo *)
2322
apt clean

examples/bls/build

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,53 @@
22

33
set -eux
44

5+
os="${1:-fedora}"
56
cd "${0%/*}"
67

78
../common/check-config
89

10+
case "${os}" in
11+
fedora)
12+
containerfile='Containerfile'
13+
features='--features=pre-6.15'
14+
;;
15+
arch)
16+
containerfile='Containerfile.arch'
17+
features='--features=pre-6.15'
18+
;;
19+
rhel9)
20+
containerfile='Containerfile.rhel9'
21+
features='--features=rhel9'
22+
;;
23+
ubuntu)
24+
containerfile='Containerfile.ubuntu'
25+
features='--features=pre-6.15'
26+
;;
27+
rawhide)
28+
containerfile='Containerfile.rawhide'
29+
features='--no-default-features'
30+
;;
31+
*)
32+
echo "*** unknown variant ${os}"
33+
false
34+
;;
35+
esac
36+
937
# https://github.com/containers/buildah/issues/5656
1038
PODMAN_BUILD="podman build --no-cache"
1139

12-
cargo build --release
40+
cargo build --release "${features}"
1341

1442
cp ../../target/release/cfsctl .
15-
cp ../../target/release/composefs-pivot-sysroot extra/usr/lib/dracut/modules.d/37composefs/
43+
cp ../../target/release/composefs-setup-root extra/usr/lib/dracut/modules.d/37composefs/
1644
CFSCTL='./cfsctl --repo tmp/sysroot/composefs'
1745

1846
rm -rf tmp
19-
mkdir -p tmp/sysroot/composefs tmp/sysroot/var
47+
mkdir -p tmp/sysroot/composefs
2048

2149
${PODMAN_BUILD} \
2250
--iidfile=tmp/base.iid \
23-
"$@" \
51+
-f "${containerfile}" \
2452
.
2553

2654
BASE_ID="$(sed s/sha256:// tmp/base.iid)"
@@ -29,6 +57,10 @@ ${CFSCTL} oci pull oci-archive:tmp/base.tar
2957
BASE_IMAGE_FSVERITY="$(${CFSCTL} oci create-image "${BASE_ID}")"
3058
fsck.erofs "tmp/sysroot/composefs/images/${BASE_IMAGE_FSVERITY}"
3159

60+
mkdir -p "tmp/sysroot/state/${BASE_IMAGE_FSVERITY}/etc/work"
61+
mkdir -p "tmp/sysroot/state/${BASE_IMAGE_FSVERITY}/etc/upper"
62+
mkdir -p "tmp/sysroot/state/${BASE_IMAGE_FSVERITY}/var"
63+
3264
mkdir -p tmp/efi/loader
3365
echo 'timeout 3' > tmp/efi/loader/loader.conf
3466
mkdir -p tmp/efi/EFI/BOOT tmp/efi/EFI/systemd
@@ -39,11 +71,12 @@ ${CFSCTL} oci prepare-boot "${BASE_ID}" tmp/efi
3971
OPTIONS="console=ttyS0,115200 composefs=${BASE_IMAGE_FSVERITY} rw"
4072
BLE="$(echo tmp/efi/loader/entries/*.conf)"
4173
test -f "${BLE}"
74+
4275
if grep '^options ' "${BLE}"; then
4376
sed -i "s|^options .*$|\0 ${OPTIONS}|" "${BLE}"
4477
else
4578
echo "options ${OPTIONS}" >> "${BLE}"
4679
fi
4780
sed -i 's@ /boot/@ /@' "${BLE}"
4881

49-
../common/make-image composefs-bls-efi.qcow2
82+
../common/make-image "${os}-bls-efi.qcow2"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OnFailureJobMode=isolate
2727

2828
[Service]
2929
Type=oneshot
30-
ExecStart=/usr/bin/composefs-pivot-sysroot
30+
ExecStart=/usr/bin/composefs-setup-root
3131
StandardInput=null
3232
StandardOutput=journal
3333
StandardError=journal+console

0 commit comments

Comments
 (0)