mirror of
https://github.com/vyos/vyos-build.git
synced 2025-10-01 20:28:40 +02:00
T7453: handle dynamic partition mapping in raw image build
Enhanced the raw image creation logic to dynamically detect and assign EFI and root partitions based on the number of partitions created by kpartx. - Supports both 2-partition and 3-partition layouts - Adds debug output for mapped partitions - Avoids hardcoded assumptions about partition order - Improves resilience in cloud-init and containerized build contexts Fixes build failure when /dev/loopXp3 is missing or not mapped properly. Signed-off-by: Gabin-CC <gabin.laurent@rte-international.com>
This commit is contained in:
parent
1cda2d42bb
commit
02c2e30622
@ -232,19 +232,34 @@ def create_raw_image(build_config, iso_file, work_dir):
|
|||||||
disk_details = parttable_create(con.loop_device, (int(build_config["disk_size"]) - 1) * 1024 * 1024)
|
disk_details = parttable_create(con.loop_device, (int(build_config["disk_size"]) - 1) * 1024 * 1024)
|
||||||
|
|
||||||
# Map partitions using kpartx
|
# Map partitions using kpartx
|
||||||
|
print("I: Mapping partitions using kpartx...")
|
||||||
cmd(f"kpartx -av {con.loop_device}")
|
cmd(f"kpartx -av {con.loop_device}")
|
||||||
cmd("udevadm settle")
|
cmd("udevadm settle")
|
||||||
|
|
||||||
# Resolve mapper names (example: /dev/mapper/loop0p2)
|
cmd("ls -l /dev/mapper") # debug output
|
||||||
|
|
||||||
|
# Detect mapped partitions
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
import time
|
||||||
|
|
||||||
mapper_base = os.path.basename(con.loop_device).replace("/dev/", "")
|
mapper_base = os.path.basename(con.loop_device).replace("/dev/", "")
|
||||||
mapped_parts = sorted(glob(f"/dev/mapper/{mapper_base}p*"))
|
mapped_parts = sorted(glob(f"/dev/mapper/{mapper_base}p*"))
|
||||||
|
|
||||||
if len(mapped_parts) < 3:
|
if not mapped_parts:
|
||||||
raise RuntimeError("E: Expected at least 3 partitions created by kpartx")
|
raise RuntimeError(f"E: No partitions were found in /dev/mapper for {mapper_base}")
|
||||||
|
|
||||||
|
print(f"I: Found mapped partitions: {mapped_parts}")
|
||||||
|
|
||||||
|
if len(mapped_parts) == 2:
|
||||||
|
# Assume [0] = EFI, [1] = root
|
||||||
|
disk_details.partition['efi'] = mapped_parts[0]
|
||||||
|
disk_details.partition['root'] = mapped_parts[1]
|
||||||
|
elif len(mapped_parts) >= 3:
|
||||||
|
# Common layout: [1] = EFI, [2] = root (skip 0 if it's BIOS boot)
|
||||||
disk_details.partition['efi'] = mapped_parts[1]
|
disk_details.partition['efi'] = mapped_parts[1]
|
||||||
disk_details.partition['root'] = mapped_parts[2]
|
disk_details.partition['root'] = mapped_parts[2]
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"E: Unexpected partition layout: {mapped_parts}")
|
||||||
|
|
||||||
con.disk_details = disk_details
|
con.disk_details = disk_details
|
||||||
mount_image(con)
|
mount_image(con)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user