partitions_mount: fix finding the partition (MR 2178)
Instead of trying both "${dev}1" and "${dev}p1" as partition paths, only try one of them depending on if "${dev}" ends in a number or not. This fixes getting a wrong /dev/loop11 partition by accident if there are many loop devices, instead of only looking for the correct path /dev/loop1p1. People reported this happening with snaps on ubuntu.
This commit is contained in:
parent
faf523911a
commit
7abb281296
|
@ -19,23 +19,27 @@ def partitions_mount(args, layout, sdcard):
|
||||||
img_path = "/home/pmos/rootfs/" + args.device + ".img"
|
img_path = "/home/pmos/rootfs/" + args.device + ".img"
|
||||||
prefix = pmb.install.losetup.device_by_back_file(args, img_path)
|
prefix = pmb.install.losetup.device_by_back_file(args, img_path)
|
||||||
|
|
||||||
partition_prefix = None
|
|
||||||
tries = 20
|
tries = 20
|
||||||
|
|
||||||
|
# Devices ending with a number have a "p" before the partition number,
|
||||||
|
# /dev/sda1 has no "p", but /dev/mmcblk0p1 has. See add_partition() in
|
||||||
|
# block/partitions/core.c of linux.git.
|
||||||
|
partition_prefix = prefix
|
||||||
|
if str.isdigit(prefix[-1:]):
|
||||||
|
partition_prefix = f"{prefix}p"
|
||||||
|
|
||||||
|
found = False
|
||||||
for i in range(tries):
|
for i in range(tries):
|
||||||
for symbol in ["p", ""]:
|
if os.path.exists(f"{partition_prefix}1"):
|
||||||
if os.path.exists(prefix + symbol + "1"):
|
found = True
|
||||||
partition_prefix = symbol
|
|
||||||
if partition_prefix is not None:
|
|
||||||
break
|
break
|
||||||
logging.debug(f"NOTE: ({i + 1}/{tries}) failed to find the install "
|
logging.debug(f"NOTE: ({i + 1}/{tries}) failed to find the install "
|
||||||
"partition. Retrying...")
|
"partition. Retrying...")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
if partition_prefix is None:
|
if not found:
|
||||||
raise RuntimeError("Unable to find the partition prefix,"
|
raise RuntimeError(f"Unable to find the first partition of {prefix}, "
|
||||||
" expected the first partition of " +
|
f"expected it to be at {partition_prefix}1!")
|
||||||
prefix + " to be located at " + prefix +
|
|
||||||
"1 or " + prefix + "p1!")
|
|
||||||
|
|
||||||
partitions = [layout["boot"], layout["root"]]
|
partitions = [layout["boot"], layout["root"]]
|
||||||
|
|
||||||
|
@ -43,7 +47,7 @@ def partitions_mount(args, layout, sdcard):
|
||||||
partitions += [layout["kernel"]]
|
partitions += [layout["kernel"]]
|
||||||
|
|
||||||
for i in partitions:
|
for i in partitions:
|
||||||
source = prefix + partition_prefix + str(i)
|
source = f"{partition_prefix}{i}"
|
||||||
target = args.work + "/chroot_native/dev/installp" + str(i)
|
target = args.work + "/chroot_native/dev/installp" + str(i)
|
||||||
pmb.helpers.mount.bind_file(args, source, target)
|
pmb.helpers.mount.bind_file(args, source, target)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue