Skip to content

Commit 344a187

Browse files
committed
WIP: FCOS
1 parent 1da8413 commit 344a187

26 files changed

+1333
-1
lines changed

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ bootc-bls/extra-fcos/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
55
bootc-bls/extra/usr/bin/bootc
66
bootc-bls/extra/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
77
bootc-uki/VARS_CUSTOM.secboot.qcow2.template
8+
bootc-uki/bootc
89
bootc-uki/extra-fcos/usr/bin/bootc
910
bootc-uki/extra-fcos/usr/lib/dracut/modules.d/37bootc/bootc-initramfs-setup
1011
bootc-uki/extra/usr/bin/bootc

examples/bootc-uki/build.base-fcos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
export FROM="quay.io/fedora/fedora-coreos:stable"
4-
export TAG="$quay.io/fedora/fedora-coreos-base-uki:stable"
4+
export TAG="quay.io/fedora/fedora-coreos-base-uki:stable"
55
export EXTRA="extra-fcos"
66
exec ./build.base
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[@]}"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Ignition OSTree: Check Root Filesystem Size
3+
Documentation=https://docs.fedoraproject.org/en-US/fedora-coreos/storage/
4+
DefaultDependencies=false
5+
ConditionKernelCommandLine=composefs
6+
ConditionPathExists=!/run/ostree-live
7+
After=ignition-ostree-growfs.service
8+
After=ostree-prepare-root.service
9+
Requires=ostree-prepare-root.service
10+
# Allow Ignition config to blank out the warning
11+
Before=ignition-files.service
12+
13+
[Service]
14+
Type=oneshot
15+
ExecStart=/usr/libexec/coreos-check-rootfs-size
16+
RemainAfterExit=yes
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+
# https://github.com/coreos/fedora-coreos-tracker/issues/465
4+
# coreos-assembler generates disk images which are installed bit-for-bit
5+
# or booted directly in the cloud.
6+
# Generate new UUID on firstboot; this is general best practice, but in the future
7+
# we may use this for mounting by e.g. adding a boot=<uuid> and root=<uuid> kernel args.
8+
9+
label=$1
10+
11+
# Keep this in sync with https://github.com/coreos/coreos-assembler/blob/e3905fd2e138de04184c1cd86b99b0fd83cbe5cf/src/create_disk.sh#L17
12+
bootfs_uuid="96d15588-3596-4b3c-adca-a2ff7279ea63"
13+
rootfs_uuid="910678ff-f77e-4a7d-8d53-86f2ac47a823"
14+
15+
target=/dev/disk/by-label/${label}
16+
if ! [ -b "${target}" ]; then
17+
echo "$0: Failed to find block device ${target}" 1>&2
18+
exit 1
19+
fi
20+
21+
eval $(blkid -p -o export ${target})
22+
case "${label}" in
23+
root) orig_uuid="${rootfs_uuid}"; orig_type=xfs ;;
24+
boot) orig_uuid="${bootfs_uuid}"; orig_type=ext4 ;;
25+
*) echo "unexpected ${label}"; exit 1 ;;
26+
esac
27+
28+
if [ "${TYPE}" == "${orig_type}" ] && [ "${UUID}" == "${orig_uuid}" ]; then
29+
case "${TYPE}" in
30+
ext4) tune2fs -U random "${target}" ;;
31+
xfs) xfs_admin -U generate "${target}" ;;
32+
*) echo "unexpected filesystem type ${TYPE}" 1>&2; exit 1 ;;
33+
esac
34+
udevadm settle || :
35+
echo "Regenerated UUID for ${target}"
36+
else
37+
echo "No changes required for ${target} TYPE=${TYPE} UUID=${UUID}"
38+
fi

0 commit comments

Comments
 (0)