assemblers: add org.osbuild.rawfs
This assembler outputs an image file which only contains the file system.
This commit is contained in:
parent
7375e4f5dd
commit
9fbe80722b
6 changed files with 239 additions and 2 deletions
48
assemblers/org.osbuild.rawfs
Executable file
48
assemblers/org.osbuild.rawfs
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import osbuild.remoteloop as remoteloop
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mount(source, dest, *options):
|
||||
os.makedirs(dest, 0o755, True)
|
||||
subprocess.run(["mount", *options, source, dest], check=True)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
subprocess.run(["umount", "-R", dest], check=True)
|
||||
|
||||
|
||||
def main(tree, output_dir, options, loop_client):
|
||||
filename = options["filename"]
|
||||
root_fs_uuid = options["root_fs_uuid"]
|
||||
size = options["size"]
|
||||
|
||||
image = f"/var/tmp/osbuild-image.raw"
|
||||
mountpoint = f"/tmp/osbuild-mnt"
|
||||
|
||||
subprocess.run(["truncate", "--size", str(size), image], check=True)
|
||||
subprocess.run(["mkfs.ext4", "-U", root_fs_uuid, image], input="y", encoding='utf-8', check=True)
|
||||
|
||||
# Copy the tree into the target image
|
||||
with loop_client.device(image) as loop, mount(loop, mountpoint):
|
||||
subprocess.run(["cp", "-a", f"{tree}/.", mountpoint], check=True)
|
||||
|
||||
subprocess.run(["mv", image, f"{output_dir}/{filename}"], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = json.load(sys.stdin)
|
||||
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) as sock:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_PASSCRED, 1)
|
||||
sock.connect("/run/osbuild/api/remoteloop")
|
||||
r = main(args["tree"], args["output_dir"], args["options"], remoteloop.LoopClient(sock))
|
||||
|
||||
sys.exit(r)
|
||||
Loading…
Add table
Add a link
Reference in a new issue