tools/osbuild-mpp: add sector size support for image layouts
Now you can specify a sector_size in `mpp-define-images` to support creating a 4k native disk image (sector_size=4096). This does use a loopback device, which means osbuild-mpp also needs to run as root, when previously that wasn't necessary.
This commit is contained in:
parent
2e1f6e2553
commit
28c2772d42
1 changed files with 9 additions and 3 deletions
|
|
@ -974,13 +974,19 @@ class Image:
|
|||
def from_dict(cls, js):
|
||||
size = js["size"]
|
||||
data = js["table"]
|
||||
sector_size = js.get('sector_size', 512)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
image = os.path.join(tmp, "disk.img")
|
||||
subprocess.run(["truncate", "--size", size, image], check=True)
|
||||
|
||||
table = PartitionTable.from_dict(data)
|
||||
table.write_to(image)
|
||||
cp = subprocess.run(["losetup", "--find", "--show", f"--sector-size={sector_size}", image],
|
||||
stdout=subprocess.PIPE, check=True)
|
||||
loopimage = cp.stdout.rstrip()
|
||||
try:
|
||||
table = PartitionTable.from_dict(data)
|
||||
table.write_to(loopimage)
|
||||
finally:
|
||||
subprocess.run(["losetup", "-d", loopimage])
|
||||
|
||||
return cls(size, table)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue