-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osbuild: Add Live ISO/PXE build support
This backports and takes advantage of the new org.osbuild.coreos.live-artifacts.mono stage. Signed-off-by: Renata Ravanelli <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/0001-osbuild-remoteloop-add-more-loop-device-options.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
From 036250ee54d7dc56b8bbf8be271f64395c907277 Mon Sep 17 00:00:00 2001 | ||
From: Dusty Mabe <[email protected]> | ||
Date: Fri, 22 Nov 2024 19:02:57 -0500 | ||
Subject: [PATCH 1/5] osbuild/remoteloop: add more loop device options | ||
|
||
This adds lock, partscan, read_only, sector_size to _create_device() | ||
similar to make_loop() from devices/org.osbuild.loopback. | ||
--- | ||
osbuild/remoteloop.py | 42 +++++++++++++++++++++++++++++++++++++----- | ||
1 file changed, 37 insertions(+), 5 deletions(-) | ||
|
||
diff --git a/osbuild/remoteloop.py b/osbuild/remoteloop.py | ||
index 0544e0be..cfede03f 100644 | ||
--- a/osbuild/remoteloop.py | ||
+++ b/osbuild/remoteloop.py | ||
@@ -41,8 +41,23 @@ class LoopServer(api.BaseAPI): | ||
self.devs = [] | ||
self.ctl = loop.LoopControl() | ||
|
||
- def _create_device(self, fd, dir_fd, offset=None, sizelimit=None): | ||
- lo = self.ctl.loop_for_fd(fd, offset=offset, sizelimit=sizelimit, autoclear=True) | ||
+ def _create_device( | ||
+ self, | ||
+ fd, | ||
+ dir_fd, | ||
+ offset=None, | ||
+ sizelimit=None, | ||
+ lock=False, | ||
+ partscan=False, | ||
+ read_only=False, | ||
+ sector_size=512): | ||
+ lo = self.ctl.loop_for_fd(fd, lock=lock, | ||
+ offset=offset, | ||
+ sizelimit=sizelimit, | ||
+ blocksize=sector_size, | ||
+ partscan=partscan, | ||
+ read_only=read_only, | ||
+ autoclear=True) | ||
lo.mknod(dir_fd) | ||
# Pin the Loop objects so they are only released when the LoopServer | ||
# is destroyed. | ||
@@ -54,8 +69,12 @@ class LoopServer(api.BaseAPI): | ||
dir_fd = fds[msg["dir_fd"]] | ||
offset = msg.get("offset") | ||
sizelimit = msg.get("sizelimit") | ||
+ lock = msg.get("lock") | ||
+ partscan = msg.get("partscan") | ||
+ read_only = msg.get("read_only") | ||
+ sector_size = msg.get("sector_size") | ||
|
||
- devname = self._create_device(fd, dir_fd, offset, sizelimit) | ||
+ devname = self._create_device(fd, dir_fd, offset, sizelimit, lock, partscan, read_only, sector_size) | ||
sock.send({"devname": devname}) | ||
|
||
def _cleanup(self): | ||
@@ -75,11 +94,20 @@ class LoopClient: | ||
self.client.close() | ||
|
||
@contextlib.contextmanager | ||
- def device(self, filename, offset=None, sizelimit=None): | ||
+ def device( | ||
+ self, | ||
+ filename, | ||
+ offset=None, | ||
+ sizelimit=None, | ||
+ lock=False, | ||
+ partscan=False, | ||
+ read_only=False, | ||
+ sector_size=512): | ||
req = {} | ||
fds = [] | ||
|
||
- fd = os.open(filename, os.O_RDWR) | ||
+ flags = os.O_RDONLY if read_only else os.O_RDWR | ||
+ fd = os.open(filename, flags) | ||
dir_fd = os.open("/dev", os.O_DIRECTORY) | ||
|
||
fds.append(fd) | ||
@@ -91,6 +119,10 @@ class LoopClient: | ||
req["offset"] = offset | ||
if sizelimit: | ||
req["sizelimit"] = sizelimit | ||
+ req["lock"] = lock | ||
+ req["partscan"] = partscan | ||
+ req["read_only"] = read_only | ||
+ req["sector_size"] = sector_size | ||
|
||
self.client.send(req, fds=fds) | ||
os.close(dir_fd) | ||
-- | ||
2.47.0 | ||
|
30 changes: 30 additions & 0 deletions
30
src/0002-osbuild-loop-make-the-loop-device-if-missing.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
From 2b02f2e266ecdcc2ec5697e9f8b2e7f5ffa62850 Mon Sep 17 00:00:00 2001 | ||
From: Dusty Mabe <[email protected]> | ||
Date: Mon, 25 Nov 2024 16:29:10 -0500 | ||
Subject: [PATCH 2/5] osbuild/loop: make the loop device if missing | ||
|
||
A few times during development I saw an error where the loop | ||
device wasn't getting created. Maybe it was some weird state | ||
issue with my system (i.e. loopback devices are global), or | ||
maybe not. Either way maybe it won't hurt to create it if | ||
it doesn't exist. | ||
--- | ||
osbuild/loop.py | 2 ++ | ||
1 file changed, 2 insertions(+) | ||
|
||
diff --git a/osbuild/loop.py b/osbuild/loop.py | ||
index ec6d3619..97a45988 100644 | ||
--- a/osbuild/loop.py | ||
+++ b/osbuild/loop.py | ||
@@ -126,6 +126,8 @@ class Loop: | ||
if not dir_fd: | ||
dir_fd = os.open("/dev", os.O_DIRECTORY) | ||
stack.callback(lambda: os.close(dir_fd)) | ||
+ if not os.path.exists(os.path.join("/dev", self.devname)): | ||
+ self.mknod(dir_fd) | ||
self.fd = os.open(self.devname, os.O_RDWR, dir_fd=dir_fd) | ||
|
||
info = os.stat(self.fd) | ||
-- | ||
2.47.0 | ||
|
32 changes: 32 additions & 0 deletions
32
src/0003-util-osrelease.py-improve-whitespace-and-quote-strip.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
From bbfb2e222c3056859acd2aee4e9fb5a2e02f3899 Mon Sep 17 00:00:00 2001 | ||
From: Renata Ravanelli <[email protected]> | ||
Date: Tue, 12 Nov 2024 15:12:52 -0300 | ||
Subject: [PATCH 3/5] util/osrelease.py: improve whitespace and quote stripping | ||
|
||
- Enhanced the value stripping logic in osrelease parsing | ||
to handle leading and trailing spaces, newlines, tabs, | ||
and both single and double quotes. | ||
- This ensures cleaner and more accurate key-value assignments. | ||
|
||
Signed-off-by: Renata Ravanelli <[email protected]> | ||
(cherry picked from commit 066f1ea89fbda6e886a5d88119586c0f09b0a234) | ||
--- | ||
osbuild/util/osrelease.py | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/osbuild/util/osrelease.py b/osbuild/util/osrelease.py | ||
index b8d56e73..a2b61d26 100644 | ||
--- a/osbuild/util/osrelease.py | ||
+++ b/osbuild/util/osrelease.py | ||
@@ -33,7 +33,7 @@ def parse_files(*paths): | ||
if line[0] == "#": | ||
continue | ||
key, value = line.split("=", 1) | ||
- osrelease[key] = value.strip('"') | ||
+ osrelease[key] = value.strip(" \n\t'\"") | ||
|
||
return osrelease | ||
|
||
-- | ||
2.47.0 | ||
|
59 changes: 59 additions & 0 deletions
59
src/0004-util-chroot-Add-support-for-custom-directory-bind-mo.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
From adb7f71d78b78c043dc2e2d0c7d2c59a0c2a08df Mon Sep 17 00:00:00 2001 | ||
From: Renata Ravanelli <[email protected]> | ||
Date: Thu, 31 Oct 2024 14:13:50 -0300 | ||
Subject: [PATCH 4/5] util/chroot: Add support for custom directory bind mounts | ||
|
||
- Add optional bind_mounts parameter to __init__ method; | ||
- Enhanced methods to accept an optional `bind_mounts`. | ||
This allows for more flexible for configurations when setting | ||
up bind mounts. | ||
|
||
Signed-off-by: Renata Ravanelli <[email protected]> | ||
(cherry picked from commit 9b5fbadee6b170455d62c57eb315e20d57173110) | ||
--- | ||
osbuild/util/chroot.py | 14 +++++++++++++- | ||
1 file changed, 13 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/osbuild/util/chroot.py b/osbuild/util/chroot.py | ||
index da14bf44..4090456b 100644 | ||
--- a/osbuild/util/chroot.py | ||
+++ b/osbuild/util/chroot.py | ||
@@ -12,8 +12,9 @@ class Chroot: | ||
This mounts /proc, /dev, and /sys. | ||
""" | ||
|
||
- def __init__(self, root: str): | ||
+ def __init__(self, root: str, bind_mounts=None): | ||
self.root = root | ||
+ self._bind_mounts = bind_mounts or [] | ||
|
||
def __enter__(self): | ||
for d in ["/proc", "/dev", "/sys"]: | ||
@@ -33,6 +34,13 @@ class Chroot: | ||
"sysfs", f"{self.root}/sys"], | ||
check=True) | ||
|
||
+ for d in self._bind_mounts: | ||
+ target_path = os.path.join(self.root, d.lstrip("/")) | ||
+ if not os.path.exists(target_path): | ||
+ print(f"Making missing chroot directory: {d}") | ||
+ os.makedirs(target_path) | ||
+ subprocess.run(["mount", "--rbind", d, target_path], check=True) | ||
+ | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, tracebk): | ||
@@ -43,6 +51,10 @@ class Chroot: | ||
if failed_umounts: | ||
print(f"Error unmounting paths from chroot: {failed_umounts}") | ||
|
||
+ for d in self._bind_mounts[::-1]: | ||
+ target_path = os.path.join(self.root, d.lstrip("/")) | ||
+ if subprocess.run(["umount", "--lazy", target_path], check=False).returncode != 0: | ||
+ print(f"Error unmounting paths from chroot: {d}") | ||
def run(self, cmd, **kwargs): | ||
cmd = ["chroot", self.root] + cmd | ||
# pylint: disable=subprocess-run-check | ||
-- | ||
2.47.0 | ||
|
Oops, something went wrong.