Skip to content

Commit 1da8413

Browse files
committed
WIP: scripts to build FCOS images
1 parent b679fa5 commit 1da8413

34 files changed

+1386
-23
lines changed

examples/.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
test.img
22
backups
3-
bootc-bls/bootc
3+
bootc-bls/extra-fcos/usr/bin/bootc
4+
bootc-bls/extra-fcos/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
5+
bootc-bls/extra/usr/bin/bootc
46
bootc-bls/extra/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
57
bootc-uki/VARS_CUSTOM.secboot.qcow2.template
6-
bootc-uki/bootc
8+
bootc-uki/extra-fcos/usr/bin/bootc
9+
bootc-uki/extra-fcos/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
10+
bootc-uki/extra/usr/bin/bootc
711
bootc-uki/extra/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
812
bootc-uki/secureboot/
913
systemd-bootx64.efi

examples/bootc-bls/Containerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM quay.io/fedora/fedora-bootc:42
2-
COPY extra /
3-
COPY bootc /usr/bin
2+
COPY . /
43

54
RUN passwd -d root
65

examples/bootc-bls/build

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ set -eux
44

55
cd "${0%/*}"
66

7+
FROM="${FROM:-quay.io/fedora/fedora-bootc:42}"
8+
TAG="${TAG:-quay.io/fedora/fedora-bootc-bls:42}"
9+
EXTRA="${EXTRA:-extra}"
10+
711
# cargo build --release --features=composefs-backend
812

9-
cp ../../target/release/bootc .
10-
cp ../../target/release/bootc-initramfs-setup extra/usr/lib/dracut/modules.d/37bootc/
13+
mkdir -p "${EXTRA}/usr/bin/"
14+
cp ../../target/release/bootc "${EXTRA}/usr/bin/"
15+
cp ../../target/release/bootc-initramfs-setup "${EXTRA}/usr/lib/dracut/modules.d/37bootc/"
1116

1217
podman build \
13-
-t quay.io/fedora/fedora-bootc-bls:42 \
18+
--from "${FROM}" \
19+
-t "${TAG}" \
1420
-f Containerfile \
15-
.
21+
"${EXTRA}"

examples/bootc-bls/build-fcos

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
export FROM="${IMAGE:-quay.io/fedora/fedora-coreos:stable}"
4+
export TAG="${IMAGE:-quay.io/fedora/fedora-coreos-bls:stable}"
5+
export EXTRA="extra-fcos"
6+
exec ./build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# we need to force these in via the initramfs because we don't have modules in
2+
# the base image
3+
force_drivers+=" virtio_net vfat "
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3+
# ex: ts=8 sw=4 sts=4 et filetype=sh
4+
5+
check() {
6+
if [[ $IN_KDUMP == 1 ]]; then
7+
return 1
8+
fi
9+
}
10+
11+
depends() {
12+
echo systemd network ignition coreos-live
13+
}
14+
15+
install_ignition_unit() {
16+
local unit="$1"; shift
17+
local target="${1:-ignition-complete.target}"; shift
18+
local instantiated="${1:-$unit}"; shift
19+
inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit"
20+
# note we `|| exit 1` here so we error out if e.g. the units are missing
21+
# see https://github.com/coreos/fedora-coreos-config/issues/799
22+
systemctl -q --root="$initdir" add-requires "$target" "$instantiated" || exit 1
23+
}
24+
25+
install() {
26+
inst_multiple \
27+
basename \
28+
diff \
29+
lsblk \
30+
sed \
31+
grep \
32+
uname
33+
34+
35+
# In some cases we had to vendor gdisk in Ignition.
36+
# If this is the case here use that one.
37+
# See https://issues.redhat.com/browse/RHEL-56080
38+
if [ -f /usr/libexec/ignition-sgdisk ]; then
39+
inst /usr/libexec/ignition-sgdisk /usr/sbin/sgdisk
40+
else
41+
inst sgdisk
42+
fi
43+
44+
# For IBM SecureExecution
45+
if [[ $(uname -m) = s390x ]]; then
46+
inst_multiple \
47+
gpg \
48+
gpg-agent
49+
fi
50+
51+
inst_simple "$moddir/coreos-diskful-generator" \
52+
"$systemdutildir/system-generators/coreos-diskful-generator"
53+
54+
inst_script "$moddir/coreos-gpt-setup.sh" \
55+
"/usr/sbin/coreos-gpt-setup"
56+
57+
# This has to work only on diskful systems during firstboot.
58+
# coreos-diskful-generator will create a symlink
59+
inst_simple "$moddir/80-coreos-boot-disk.rules" \
60+
"/usr/lib/coreos/80-coreos-boot-disk.rules"
61+
62+
inst_script "$moddir/coreos-disk-contains-fs.sh" \
63+
"/usr/lib/udev/coreos-disk-contains-fs"
64+
65+
inst_script "$moddir/coreos-ignition-setup-user.sh" \
66+
"/usr/sbin/coreos-ignition-setup-user"
67+
68+
inst_script "$moddir/coreos-post-ignition-checks.sh" \
69+
"/usr/sbin/coreos-post-ignition-checks"
70+
71+
install_ignition_unit coreos-post-ignition-checks.service
72+
73+
# For consistency tear down the network and persist multipath between the initramfs and
74+
# real root. See https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599721763
75+
inst_script "$moddir/coreos-teardown-initramfs.sh" \
76+
"/usr/sbin/coreos-teardown-initramfs"
77+
install_ignition_unit coreos-teardown-initramfs.service
78+
79+
# units only started when we have a boot disk
80+
# path generated by systemd-escape --path /dev/disk/by-label/root
81+
install_ignition_unit coreos-gpt-setup.service ignition-diskful.target
82+
83+
# dracut inst_script doesn't allow overwrites and we are replacing
84+
# the default script placed by Ignition
85+
binpath="/usr/sbin/ignition-kargs-helper"
86+
cp "$moddir/coreos-kargs.sh" "$initdir$binpath"
87+
install_ignition_unit coreos-kargs-reboot.service
88+
89+
install_ignition_unit coreos-ignition-unique-boot.service ignition-diskful.target
90+
install_ignition_unit coreos-unique-boot.service ignition-diskful.target
91+
install_ignition_unit coreos-ignition-setup-user.service
92+
93+
# IBM Secure Execution. Ignition config for reencryption of / and /boot
94+
inst_simple "$moddir/01-secex.ign" /usr/lib/coreos/01-secex.ign
95+
inst_simple "$moddir/coreos-secex-ignition-prepare.service" \
96+
"$systemdsystemunitdir/coreos-secex-ignition-prepare.service"
97+
inst_script "$moddir/coreos-secex-ignition-prepare.sh" \
98+
"/usr/sbin/coreos-secex-ignition-prepare"
99+
100+
inst_multiple jq blkid
101+
inst_script "$moddir/coreos-rootflags.sh" \
102+
"/usr/sbin/coreos-rootflags"
103+
# Install unit, but don't enable it. Will be pulled in by diskful generator.
104+
inst_simple "$moddir/coreos-rootflags.service" "$systemdsystemunitdir/coreos-rootflags.service"
105+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (C) 2013 Colin Walters <[email protected]>
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library. If not, see <https://www.gnu.org/licenses/>.
15+
16+
[Unit]
17+
DefaultDependencies=no
18+
ConditionKernelCommandLine=composefs
19+
ConditionPathExists=/etc/initrd-release
20+
After=sysroot.mount
21+
Requires=sysroot.mount
22+
Before=initrd-root-fs.target
23+
Before=initrd-switch-root.target
24+
25+
OnFailure=emergency.target
26+
OnFailureJobMode=isolate
27+
28+
[Service]
29+
Type=oneshot
30+
ExecStart=/usr/bin/bootc-initramfs-setup
31+
StandardInput=null
32+
StandardOutput=journal
33+
StandardError=journal+console
34+
RemainAfterExit=yes
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/bash
2+
3+
check() {
4+
return 0
5+
}
6+
7+
depends() {
8+
return 0
9+
}
10+
11+
install() {
12+
inst \
13+
"${moddir}/bootc-initramfs-setup" /usr/bin/bootc-initramfs-setup
14+
inst \
15+
"${moddir}/bootc-initramfs-setup.service" \
16+
"${systemdsystemunitdir}/bootc-initramfs-setup.service"
17+
18+
$SYSTEMCTL -q --root "${initdir}" add-wants \
19+
'initrd-root-fs.target' 'bootc-initramfs-setup.service'
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# See also ignition-ostree-check-rootfs-size.service
5+
# https://github.com/coreos/fedora-coreos-tracker/issues/586#issuecomment-777220000
6+
7+
# /sysroot is the mounted deploy root, /sysroot/sysroot is the physical root filesystem
8+
srcdev=$(findmnt -nvr -o SOURCE /sysroot/sysroot | tail -n1)
9+
size=$(lsblk --nodeps --noheadings --bytes -o SIZE "${srcdev}")
10+
11+
MINIMUM_GB=8
12+
MINIMUM_BYTES=$((1024 * 1024 * 1024 * MINIMUM_GB))
13+
14+
MOTD_DROPIN=/etc/motd.d/60-coreos-rootfs-size.motd
15+
16+
YELLOW=$(echo -e '\033[0;33m')
17+
RESET=$(echo -e '\033[0m')
18+
19+
if [ "${size}" -lt "${MINIMUM_BYTES}" ]; then
20+
mkdir -p "/sysroot/$(dirname "${MOTD_DROPIN}")"
21+
cat > "/sysroot/${MOTD_DROPIN}" <<EOF
22+
${YELLOW}
23+
############################################################################
24+
WARNING: The root filesystem is too small. It is strongly recommended to
25+
allocate at least ${MINIMUM_GB} GiB of space to allow for upgrades. From June 2021, this
26+
condition will trigger a failure in some cases. For more information, see:
27+
https://docs.fedoraproject.org/en-US/fedora-coreos/storage/
28+
29+
You may delete this warning using:
30+
sudo rm ${MOTD_DROPIN}
31+
############################################################################
32+
${RESET}
33+
EOF
34+
35+
# And also write it on stdout for the journal and console
36+
cat "/sysroot/${MOTD_DROPIN}"
37+
coreos-relabel "${MOTD_DROPIN}"
38+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
err() {
5+
echo "$@" >&2
6+
}
7+
8+
fatal() {
9+
err "$@"
10+
exit 1
11+
}
12+
13+
if [ $# -eq 0 ]; then
14+
err "Usage: $0 [PATTERN...]"
15+
err " e.g.: $0 /etc/passwd '/etc/group*'"
16+
fi
17+
18+
if [ ! -f /sysroot/etc/selinux/config ]; then
19+
exit 0
20+
fi
21+
22+
source /sysroot/etc/selinux/config
23+
24+
if [ -z "${SELINUXTYPE:-}" ]; then
25+
fatal "Couldn't find SELINUXTYPE in /sysroot/etc/selinux/config"
26+
fi
27+
28+
file_contexts="/sysroot/etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts"
29+
30+
prefixed_patterns=()
31+
while [ $# -ne 0 ]; do
32+
pattern=$1; shift
33+
prefixed_patterns+=("/sysroot/$pattern")
34+
done
35+
setfiles -vFi0 -r /sysroot "$file_contexts" "${prefixed_patterns[@]}"

0 commit comments

Comments
 (0)