Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osbuild: add support for metal platform #3654

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ write_archive_info() {
patch_osbuild() {
# A few patches that either haven't made it into a release or
# that will be obsoleted with other work that will be done soon.
cat /usr/lib/coreos-assembler/*.patch | patch -p1 -d /usr/lib/python3.12/site-packages/
cat /usr/lib/coreos-assembler/0001-Mount-boot-from-host-in-host-builder-case.patch \
/usr/lib/coreos-assembler/0001-osbuild-util-fscache-calculate-actual-size-of-files.patch \
| patch -p1 -d /usr/lib/python3.12/site-packages/
# shellcheck disable=SC2002
cat /usr/lib/coreos-assembler/0001-stages-add-kernel-cmdline.bls-append-stage.patch \
| patch -p1 -d /usr/lib/osbuild/
}

if [ $# -ne 0 ]; then
Expand Down

This file was deleted.

33 changes: 33 additions & 0 deletions src/0001-osbuild-util-fscache-calculate-actual-size-of-files.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 178f2a859a0ec068e38a82639cabf764f6264863 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Wed, 15 Nov 2023 16:48:24 -0500
Subject: [PATCH] osbuild/util/fscache: calculate actual size of files

In OSBuild we'll often be operating on sparse files. Let's make the
tabulation of the size of files on disk used when determining cache
size for pruning consider the actual size of the file usage on disk
rather than the size the file reports to be.

This means using os.lstat().st_blocks * 512 versus os.lstat().st_size.

See https://stackoverflow.com/a/55203604
---
osbuild/util/fscache.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/osbuild/util/fscache.py b/osbuild/util/fscache.py
index 29b3ce9..95860da 100644
--- a/osbuild/util/fscache.py
+++ b/osbuild/util/fscache.py
@@ -288,7 +288,7 @@ class FsCache(contextlib.AbstractContextManager, os.PathLike):
return sum(
os.lstat(
os.path.join(path, f)
- ).st_size for path, dirs, files in os.walk(
+ ).st_blocks * 512 for path, dirs, files in os.walk(
path_target
) for f in files
)
--
2.41.0

111 changes: 111 additions & 0 deletions src/0001-stages-add-kernel-cmdline.bls-append-stage.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
From 38e4e719b7378055465e42873194823138422dde Mon Sep 17 00:00:00 2001
From: Dusty Mabe <[email protected]>
Date: Mon, 6 Nov 2023 20:01:39 -0500
Subject: [PATCH] stages: add kernel-cmdline.bls-append stage

This adds a stage to be able to add kernel arguments on a system by
appending to the BLS [1] config directly either in the tree or in
a mount. This is useful on say systems that don't use `grubby` and
thus can't use the org.osbuild.kernel-cmdline stage.

[1] https://freedesktop.org/wiki/Specifications/BootLoaderSpec/
---
stages/org.osbuild.kernel-cmdline.bls-append | 86 ++++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100755 stages/org.osbuild.kernel-cmdline.bls-append

diff --git a/stages/org.osbuild.kernel-cmdline.bls-append b/stages/org.osbuild.kernel-cmdline.bls-append
new file mode 100755
index 0000000..dd16662
--- /dev/null
+++ b/stages/org.osbuild.kernel-cmdline.bls-append
@@ -0,0 +1,86 @@
+#!/usr/bin/python3
+"""
+Add kernel command line parameters to a BLS [1] config either in
+the tree or in a mount.
+
+[1] https://freedesktop.org/wiki/Specifications/BootLoaderSpec/
+"""
+
+
+import glob
+import sys
+from urllib.parse import urlparse
+
+import osbuild.api
+
+SCHEMA_2 = r"""
+"options": {
+ "additionalProperties": false,
+ "required": ["kernel_opts"],
+ "properties": {
+ "kernel_opts": {
+ "description": "Additional kernel command line options",
+ "type": "array",
+ "items": {
+ "description": "A single kernel command line option",
+ "type": "string"
+ }
+ },
+ "bootpath": {
+ "type": "string",
+ "description": "The mounted location of the boot filesystem tree where the BLS entries will be under ./loader/entries/*.conf",
+ "pattern": "^(mount|tree):\/\/\/",
+ "examples": ["tree:///boot", "mount:///", "mount:///boot"],
+ "default": "tree:///boot"
+ }
+ }
+},
+"devices": {
+ "type": "object",
+ "additionalProperties": true
+},
+"mounts": {
+ "type": "array"
+}
+"""
+
+
+def main(paths, tree, options):
+ kopts = options.get("kernel_opts", [])
+ bootpath = options.get("bootpath", "tree:///boot")
+
+ url = urlparse(bootpath)
+ scheme = url.scheme
+ if scheme == "tree":
+ root = tree
+ elif scheme == "mount":
+ root = paths["mounts"]
+ else:
+ raise ValueError(f"Unsupported scheme '{scheme}'")
+
+ assert url.path.startswith("/")
+ bootroot = root + url.path
+
+ # There is unlikely to be more than one bls config, but just
+ # in case we'll iterate over them.
+ entries = []
+ for entry in glob.glob(f"{bootroot}/loader/entries/*.conf"):
+ entries.append(entry)
+ # Read in the file and then append to the options line.
+ with open(entry, encoding="utf8") as f:
+ lines = f.read().splitlines()
+ with open(entry, "w", encoding="utf8") as f:
+ for line in lines:
+ if line.startswith('options '):
+ f.write(f"{line} {' '.join(kopts)}\n")
+ else:
+ f.write(f"{line}\n")
+ assert len(entries) != 0
+ print(f"Added {','.join(kopts)} to: {','.join(entries)}")
+ return 0
+
+
+if __name__ == '__main__':
+ args = osbuild.api.arguments()
+ r = main(args["paths"], args["tree"], args["options"])
+ sys.exit(r)
--
2.41.0

12 changes: 9 additions & 3 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,15 @@ cat "${image_json}" image-dynamic.json | jq -s add > image-for-disk.json
platforms_json="${workdir}/tmp/platforms.json"
yaml2json "${configdir}/platforms.yaml" "${platforms_json}"

if [ "${image_type}" == "qemu" ] && [ "${COSA_USE_OSBUILD:-}" != "" ]; then
runvm -- /usr/lib/coreos-assembler/runvm-osbuild \
"${ostree_repo}" "${ref}" \
# Currently we only support OSBuild for qemu and metal disk images
if [ "${image_type}" == "qemu" ] || [ "${image_type}" == "metal" ]; then
OSBUILD_SUPPORTED=1
fi

# Run with OSBuild if it's supported and requested, otherwise use create_disk
if [ "${OSBUILD_SUPPORTED:-}" != "" ] && [ "${COSA_USE_OSBUILD:-}" != "" ]; then
runvm_with_cache -- /usr/lib/coreos-assembler/runvm-osbuild \
"${ostree_repo}" "${ref}" ${image_type} \
/usr/lib/coreos-assembler/coreos.osbuild.mpp.yaml \
"${path}.tmp"
else
Expand Down
5 changes: 5 additions & 0 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ runvm() {
# include COSA in the image
find /usr/lib/coreos-assembler/ -type f > "${vmpreparedir}/hostfiles"

# include new patched in osbuild stage in the image.
# can drop this once osbuild v100 is out.
# https://github.com/osbuild/osbuild/pull/1429
echo /usr/lib/osbuild/stages/org.osbuild.kernel-cmdline.bls-append >> "${vmpreparedir}/hostfiles"

# and include all GPG keys
find /etc/pki/rpm-gpg/ -type f >> "${vmpreparedir}/hostfiles"

Expand Down
Loading
Loading