From 0252f42305709b0a9ca761e00d5a0d30ceeef152 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 27 Jun 2019 19:28:30 +0200 Subject: [PATCH] assemblers/loop_dev: take the size and optionally the offset as arguments By default the whole image file is attechd to the loopback device, but we want to only attach a slice, namely individual partitions. This is a noop, just adds the parameters to the helpers. Signed-off-by: Tom Gundersen --- assemblers/io.weldr.qcow2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assemblers/io.weldr.qcow2 b/assemblers/io.weldr.qcow2 index b055ae71..1645a6d9 100755 --- a/assemblers/io.weldr.qcow2 +++ b/assemblers/io.weldr.qcow2 @@ -35,8 +35,8 @@ def mount_api(dest): yield @contextlib.contextmanager -def loop_device(image): - r = subprocess.run(["losetup", "--partscan", "--show", "--find", image], stdout=subprocess.PIPE, encoding="utf-8", check=True) +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() try: yield loop @@ -63,7 +63,7 @@ def main(tree, input_dir, output_dir, options): subprocess.run(["sfdisk", "-q", image], input=partition_table, encoding='utf-8', check=True) # Mount the created image as a loopback device - with loop_device(image) as loop: + with loop_device(image, size) as loop: # Populate the first partition of the image with an ext4 fs and fill it with the contents of the # tree we are operating on. subprocess.run(["mkfs.ext4", "-d", tree, "-U", root_fs_uuid, f"{loop}p1"], check=True)