Skip to content

Commit b2faaee

Browse files
committed
osbuild: conditionally use bootc install
This adds raw-{,4k}-image-bootc manifests that are alternative versions of the raw-{,4k}-image manifests. This will allow to keep the legacy build path with a new path that leverages bootc install to filesystem. In this mode instead of deploying the container to the tree then copy all the contents to the disk image, use bootc to directly manage the installation to the target filesystems. We can conditionalize this until we are confident to roll this to all streams or move to image-builder. Requires: bootc-dev/bootc#1460 bootc-dev/bootc#1451 osbuild/osbuild#2149 osbuild/osbuild#2152 bootc-dev/bootc#1978 bootc-dev/bootc#1909
1 parent c49f834 commit b2faaee

12 files changed

Lines changed: 622 additions & 14 deletions

src/cmd-osbuild

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ generate_runvm_osbuild_config() {
182182
# Grab a few values from $image_json
183183
extra_kargs="$(python3 -c 'import sys, json; args = json.load(sys.stdin)["extra-kargs"]; print(" ".join(args))' < "${image_json}")"
184184

185+
# Use the bootc install to-filesystem manifest if applicable
186+
if should_use_bootc_install; then
187+
use_bootc_install="yes"
188+
else
189+
use_bootc_install="no"
190+
fi
191+
185192
# OStree container ociarchive file path
186193
ostree_container="${builddir}/$(meta_key images.ostree.path)"
187194
# If no container_imgref was set let's just set it to some professional
@@ -229,6 +236,7 @@ rootfs-size: "${rootfs_size_mb}"
229236
# "localhost/${name}:${build}" was the default name:tag used by cmd-build-with-buildah
230237
container-repo: "localhost/${name}"
231238
container-tag: "${build}"
239+
use-bootc-install: "${use_bootc_install}"
232240
EOF
233241
}
234242

@@ -415,10 +423,10 @@ main() {
415423
# osbuild can then be started with `bash tmp/build.<artifact>/cmd.sh`
416424
# See comment about checkpoints in runvm-osbuild
417425
# RUNVM_SHELL=1 \
418-
$cmd -- /usr/lib/coreos-assembler/runvm-osbuild \
419-
--config "${runvm_osbuild_config_json}" \
420-
--mpp "/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${basearch}.mpp.yaml" \
421-
--outdir "${outdir}" \
426+
$cmd -- /usr/lib/coreos-assembler/runvm-osbuild \
427+
--config "${runvm_osbuild_config_json}" \
428+
--mpp "/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${basearch}.mpp.yaml" \
429+
--outdir "${outdir}" \
422430
--platforms "$(IFS=,; echo "${platforms[*]}")"
423431

424432
for platform in "${platforms[@]}"; do

src/cmdlib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ should_build_with_buildah() {
194194
_should_enable_feature "COSA_BUILD_WITH_BUILDAH" "build_with_buildah"
195195
}
196196

197+
should_use_bootc_install() {
198+
_should_enable_feature "COSA_OSBUILD_USE_BOOTC_INSTALL" "use_bootc_install"
199+
}
200+
197201
# Only used by legacy (not via container tools) path. Delete when we
198202
# have moved away from legacy building (i.e. delete or overwrite cmd-build
199203
# and delete cmd-fetch)
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# This file defines the raw-4k-image pipeline that leverages bootc install.
2+
version: '2'
3+
pipelines:
4+
- name: raw-4k-image
5+
build:
6+
mpp-format-string: '{buildroot}'
7+
stages:
8+
- type: org.osbuild.truncate
9+
options:
10+
filename: disk.img
11+
size:
12+
mpp-format-string: '{image4k.size}'
13+
- type: org.osbuild.sfdisk
14+
devices:
15+
device:
16+
type: org.osbuild.loopback
17+
options:
18+
filename: disk.img
19+
sector-size:
20+
mpp-format-int: "{four_k_sector_size}"
21+
options:
22+
mpp-format-json: '{image4k.layout}'
23+
# Create EFI filesystem on EFI architectures
24+
- mpp-if: arch in ['x86_64', 'aarch64', 'riscv64']
25+
then:
26+
type: org.osbuild.mkfs.fat
27+
devices:
28+
device:
29+
type: org.osbuild.loopback
30+
options:
31+
filename: disk.img
32+
start:
33+
mpp-format-int: '{image4k.layout[''EFI-SYSTEM''].start}'
34+
size:
35+
mpp-format-int: '{image4k.layout[''EFI-SYSTEM''].size}'
36+
lock: true
37+
sector-size:
38+
mpp-format-int: "{four_k_sector_size}"
39+
options:
40+
label: EFI-SYSTEM
41+
volid: 7B7795E7
42+
- type: org.osbuild.mkfs.ext4
43+
devices:
44+
device:
45+
type: org.osbuild.loopback
46+
options:
47+
filename: disk.img
48+
start:
49+
mpp-format-int: '{image4k.layout[''boot''].start}'
50+
size:
51+
mpp-format-int: '{image4k.layout[''boot''].size}'
52+
lock: true
53+
sector-size:
54+
mpp-format-int: "{four_k_sector_size}"
55+
options:
56+
uuid:
57+
mpp-format-string: '{boot_fs_uuid}'
58+
label:
59+
mpp-format-string: '{boot_fs_label}'
60+
# Set manually the metadata_csum_seed ext4 option otherwise changing the
61+
# filesystem UUID while it's mounted doesn't work. Can remove this when
62+
# metadata_csum_seed is default in RHEL, which can be checked by looking
63+
# in /etc/mke2fs.conf.
64+
metadata_csum_seed: true
65+
- type: org.osbuild.mkfs.xfs
66+
devices:
67+
device:
68+
type: org.osbuild.loopback
69+
options:
70+
filename: disk.img
71+
start:
72+
mpp-format-int: '{image4k.layout[''root''].start}'
73+
size:
74+
mpp-format-int: '{image4k.layout[''root''].size}'
75+
lock: true
76+
sector-size:
77+
mpp-format-int: "{four_k_sector_size}"
78+
options:
79+
agcount:
80+
mpp-format-int: '{root_fs_agcount}'
81+
uuid:
82+
mpp-format-string: '{root_fs_uuid}'
83+
label:
84+
mpp-format-string: '{root_fs_label}'
85+
# We've created the filesystems. Now let's create the mountpoints (directories)
86+
# on the filesystems and label them with appropriate SELinux labels. This also
87+
# covers things like filesystem autogenerated files like 'lost+found'. The labeling
88+
# will happen once with just the root filesystem mounted and once with the boot
89+
# filesystem mounted too (to make sure we get all potentially hidden mountpoints).
90+
# https://github.com/coreos/fedora-coreos-tracker/issues/1771
91+
- type: org.osbuild.mkdir
92+
options:
93+
paths:
94+
- path: mount://root/boot
95+
mode: 493
96+
# Create /boot/efi mountpoint on EFI architectures
97+
- mpp-if: arch in ['x86_64', 'aarch64', 'riscv64']
98+
then:
99+
path: mount://boot/efi
100+
mode: 493
101+
devices:
102+
disk:
103+
type: org.osbuild.loopback
104+
options:
105+
filename: disk.img
106+
partscan: true
107+
sector-size:
108+
mpp-format-int: "{four_k_sector_size}"
109+
mounts:
110+
- name: root
111+
type: org.osbuild.xfs
112+
source: disk
113+
partition:
114+
mpp-format-int: '{image4k.layout[''root''].partnum}'
115+
target: /root-mount-point
116+
# Mount boot partition on EFI architectures for /boot/efi creation
117+
- mpp-if: arch in ['x86_64', 'aarch64', 'riscv64']
118+
then:
119+
name: boot
120+
type: org.osbuild.ext4
121+
source: disk
122+
partition:
123+
mpp-format-int: '{image4k.layout[''boot''].partnum}'
124+
target: /boot-mount-point
125+
# Set the context of the root of disk so that we avoid unlabeled_t files.
126+
# Here we make sure to not mount the boot partition because we want to label
127+
# the directory mount point
128+
# https://github.com/coreos/fedora-coreos-tracker/issues/1772
129+
- type: org.osbuild.selinux
130+
options:
131+
file_contexts: input://tree/etc/selinux/targeted/contexts/files/file_contexts
132+
target: mount://root/
133+
inputs:
134+
tree:
135+
type: org.osbuild.tree
136+
origin: org.osbuild.pipeline
137+
references:
138+
- name:deployed-tree
139+
devices:
140+
disk:
141+
type: org.osbuild.loopback
142+
options:
143+
filename: disk.img
144+
partscan: true
145+
sector-size:
146+
mpp-format-int: "{four_k_sector_size}"
147+
mounts:
148+
- name: root
149+
type: org.osbuild.xfs
150+
source: disk
151+
partition:
152+
mpp-format-int: '{image4k.layout[''root''].partnum}'
153+
target: /
154+
# Then we mount the boot parition and label again so the /boot/efi
155+
# mount point is labeled properly
156+
- type: org.osbuild.selinux
157+
options:
158+
file_contexts: input://tree/etc/selinux/targeted/contexts/files/file_contexts
159+
target: mount://root/boot/
160+
inputs:
161+
tree:
162+
type: org.osbuild.tree
163+
origin: org.osbuild.pipeline
164+
references:
165+
- name:deployed-tree
166+
devices:
167+
disk:
168+
type: org.osbuild.loopback
169+
options:
170+
filename: disk.img
171+
partscan: true
172+
sector-size:
173+
mpp-format-int: "{four_k_sector_size}"
174+
mounts:
175+
- name: root
176+
type: org.osbuild.xfs
177+
source: disk
178+
partition:
179+
mpp-format-int: '{image4k.layout[''root''].partnum}'
180+
target: /
181+
- name: boot
182+
type: org.osbuild.ext4
183+
source: disk
184+
partition:
185+
mpp-format-int: '{image4k.layout[''boot''].partnum}'
186+
target: /boot
187+
# Use bootc install to-filesystem to install the ostree content from the container image
188+
# inside our disc image
189+
- type: org.osbuild.bootc.install-to-filesystem
190+
inputs:
191+
images:
192+
mpp-if: ociarchive != ''
193+
then:
194+
type: org.osbuild.containers
195+
origin: org.osbuild.pipeline
196+
references:
197+
name:oci-archive:
198+
name: coreos.ociarchive
199+
else:
200+
type: org.osbuild.containers-storage
201+
origin: org.osbuild.source
202+
mpp-resolve-images:
203+
images:
204+
- source: $container_repo
205+
tag: $container_tag
206+
options:
207+
kernel-args:
208+
# '$ignition_firstboot' only works with GRUB, not available on s390x
209+
- mpp-if: arch != 's390x'
210+
then: '$ignition_firstboot'
211+
- mpp-format-string: '{extra_kargs}'
212+
target-imgref:
213+
mpp-format-string: '{container_imgref}'
214+
stateroot:
215+
mpp-format-string: '{osname}'
216+
# Empty strings mean mount spec kargs are ommited entirely.
217+
# See github.com/bootc-dev/bootc/issues/1441
218+
boot-mount-spec: ""
219+
root-mount-spec: ""
220+
devices:
221+
disk:
222+
type: org.osbuild.loopback
223+
options:
224+
filename: disk.img
225+
partscan: true
226+
sector-size:
227+
mpp-format-int: "{four_k_sector_size}"
228+
mounts:
229+
- name: root
230+
type: org.osbuild.xfs
231+
source: disk
232+
partition:
233+
mpp-format-int: '{image4k.layout[''root''].partnum}'
234+
target: /
235+
- name: boot
236+
type: org.osbuild.ext4
237+
source: disk
238+
partition:
239+
mpp-format-int: '{image4k.layout[''boot''].partnum}'
240+
target: /boot
241+
# Mount EFI partition on EFI architectures
242+
- mpp-if: arch in ['x86_64', 'aarch64', 'riscv64']
243+
then:
244+
name: efi
245+
type: org.osbuild.fat
246+
source: disk
247+
partition:
248+
mpp-format-int: '{image4k.layout[''EFI-SYSTEM''].partnum}'
249+
target: /boot/efi
250+
# set up the `ignition.firstboot` stamp at the end because
251+
# bootc want empty filesystems
252+
- type: org.osbuild.ignition
253+
options:
254+
target: mount://boot/
255+
devices:
256+
disk:
257+
type: org.osbuild.loopback
258+
options:
259+
filename: disk.img
260+
partscan: true
261+
sector-size:
262+
mpp-format-int: "{four_k_sector_size}"
263+
mounts:
264+
- name: root
265+
type: org.osbuild.xfs
266+
source: disk
267+
partition:
268+
mpp-format-int: '{image4k.layout[''root''].partnum}'
269+
target: /
270+
- name: boot
271+
type: org.osbuild.ext4
272+
source: disk
273+
partition:
274+
mpp-format-int: '{image4k.layout[''boot''].partnum}'
275+
target: /boot

src/osbuild-manifests/build.raw-4k-image.ipp.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pipelines:
122122
partition:
123123
mpp-format-int: '{image4k.layout[''boot''].partnum}'
124124
target: /boot-mount-point
125+
# Set the context of the root of disk so that we avoid unlabeled_t files.
126+
# Here we make sure to not mount the boot partition because we want to label
127+
# the directory mount point
128+
# https://github.com/coreos/fedora-coreos-tracker/issues/1772
125129
- type: org.osbuild.selinux
126130
options:
127131
file_contexts: input://tree/etc/selinux/targeted/contexts/files/file_contexts
@@ -147,6 +151,8 @@ pipelines:
147151
partition:
148152
mpp-format-int: '{image4k.layout[''root''].partnum}'
149153
target: /
154+
# Then we mount the boot parition and label again so the /boot/efi
155+
# mount point is labeled properly
150156
- type: org.osbuild.selinux
151157
options:
152158
file_contexts: input://tree/etc/selinux/targeted/contexts/files/file_contexts

0 commit comments

Comments
 (0)