Assembler: no longer mount devtmpfs in the container

Move the only assembler that relied on this to use LoopClient instead.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-07-18 19:55:54 +02:00 committed by Lars Karlitski
parent d855c6c35e
commit 7274847711
2 changed files with 19 additions and 13 deletions

View file

@ -4,9 +4,11 @@ import contextlib
import json
import math
import os
import socket
import subprocess
import sys
import tempfile
import osbuild.remoteloop as remoteloop
def tree_size(tree):
size = 0
@ -34,16 +36,17 @@ def mount_api(dest):
yield
@contextlib.contextmanager
def loop_device(image, size, offset=0):
r = subprocess.run(["losetup", "--partscan", "--show", "--find", "--sizelimit", str(size), "--offset", str(offset),
image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
loop = r.stdout.strip()
def loop_device(loop_client, image, size, offset=0):
fd = os.open(image, os.O_RDWR)
devname = loop_client.create_device(fd, offset=offset, sizelimit=size)
os.close(fd)
path = f"/dev/{devname}"
try:
yield loop
yield path
finally:
subprocess.run(["losetup", "-d", loop], check=True)
os.unlink(path)
def main(tree, output_dir, options):
def main(tree, output_dir, options, loop_client):
filename = options["filename"]
root_fs_uuid = options["root_fs_uuid"]
@ -72,17 +75,20 @@ def main(tree, output_dir, options):
f"{int(partition_size / 1024)}k"], input="y", encoding='utf-8', check=True)
# Mount the created image as a loopback device
with loop_device(image, partition_offset) as loop_block, \
loop_device(image, partition_size, partition_offset) as loop_part, \
with loop_device(loop_client, image, partition_offset) as loop_block, \
loop_device(loop_client, image, partition_size, partition_offset) as loop_part, \
mount(loop_part, mountpoint):
# Install grub2 into the boot sector of the image, and copy the grub2 imagise into /boot/grub2
with mount_api(mountpoint):
subprocess.run(["chroot", mountpoint, "grub2-install", "--no-floppy", "--modules=part_msdos", "--target=i386-pc", loop_block],
check=True)
subprocess.run(["chroot", mountpoint, "grub2-install", "--no-floppy",
"--modules=part_msdos", "--target=i386-pc", loop_block], check=True)
subprocess.run(["qemu-img", "convert", "-O", "qcow2", "-c", image, f"{output_dir}/{filename}"], check=True)
if __name__ == '__main__':
args = json.load(sys.stdin)
ret = main(args["tree"], args["output_dir"], args["options"])
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_PASSCRED, 1)
sock.connect("/run/osbuild/api/remoteloop")
ret = main(args["tree"], args["output_dir"], args["options"], remoteloop.LoopClient(sock))
sys.exit(ret)

View file

@ -228,7 +228,7 @@ class Assembler:
"options": self.options,
}
binds = ["/dev:/dev"]
binds = []
if output_dir:
os.makedirs(output_dir, exist_ok=True)
binds.append(f"{output_dir}:/run/osbuild/output")