pmb.install: add get_partition_layout() (MR 2163)

"Keeping track of which partition number is what is hard to understand now.
 I think this should be refactored, so we have it defined only in one
 place, and easy to read. Since this merge request increases the complexity
 of the partitions again, let's do it here before merging." - Oliver

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
This commit is contained in:
Anton Bambura 2022-02-04 03:28:07 +02:00 committed by Oliver Smith
parent 0d5ff8f520
commit 2363732645
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
3 changed files with 30 additions and 12 deletions

View File

@ -607,6 +607,23 @@ def sanity_check_ondev_version(args):
f" / in the binary packages has version {ver_pkg}.")
def get_partition_layout(reserve):
"""
:param reserve: create an empty partition between root and boot (pma#463)
:returns: the partition layout, e.g. without reserve and kernel:
{"boot": 1, "reserve": None, "root": 2}
"""
ret = {}
ret["boot"] = 1
ret["reserve"] = None
ret["root"] = 2
if reserve:
ret["reserve"] = ret["root"]
ret["root"] += 1
return ret
def install_system_image(args, size_reserve, suffix, step, steps,
boot_label="pmOS_boot", root_label="pmOS_root",
split=False, sdcard=None):
@ -625,16 +642,16 @@ def install_system_image(args, size_reserve, suffix, step, steps,
logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***")
pmb.chroot.shutdown(args, True)
(size_boot, size_root) = get_subpartitions_size(args, suffix)
layout = get_partition_layout(size_reserve)
if not args.rsync:
pmb.install.blockdevice.create(args, size_boot, size_root,
size_reserve, split, sdcard)
if not split:
pmb.install.partition(args, size_boot, size_reserve)
pmb.install.partition(args, layout, size_boot, size_reserve)
if not split:
root_id = 3 if size_reserve else 2
pmb.install.partitions_mount(args, root_id, sdcard)
pmb.install.partitions_mount(args, layout, sdcard)
pmb.install.format(args, size_reserve, boot_label, root_label, sdcard)
pmb.install.format(args, layout, boot_label, root_label, sdcard)
# Just copy all the files
logging.info(f"*** ({step + 1}/{steps}) FILL INSTALL BLOCKDEVICE ***")

View File

@ -125,14 +125,14 @@ def format_and_mount_root(args, device, root_label, sdcard):
pmb.chroot.root(args, ["mount", device, mountpoint])
def format(args, size_reserve, boot_label, root_label, sdcard):
def format(args, layout, boot_label, root_label, sdcard):
"""
:param size_reserve: empty partition between root and boot in MiB (pma#463)
:param layout: partition layout from get_partition_layout()
:param boot_label: label of the boot partition (e.g. "pmOS_boot")
:param root_label: label of the root partition (e.g. "pmOS_root")
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
root_dev = "/dev/installp3" if size_reserve else "/dev/installp2"
root_dev = f"/dev/installp{layout['root']}"
if args.full_disk_encryption:
format_luks_root(args, root_dev)

View File

@ -8,10 +8,10 @@ import pmb.config
import pmb.install.losetup
def partitions_mount(args, root_id, sdcard):
def partitions_mount(args, layout, sdcard):
"""
Mount blockdevices of partitions inside native chroot
:param root_id: root partition id
:param layout: partition layout from get_partition_layout()
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
prefix = sdcard
@ -37,13 +37,13 @@ def partitions_mount(args, root_id, sdcard):
prefix + " to be located at " + prefix +
"1 or " + prefix + "p1!")
for i in [1, root_id]:
for i in [1, layout["root"]]:
source = prefix + partition_prefix + str(i)
target = args.work + "/chroot_native/dev/installp" + str(i)
pmb.helpers.mount.bind_file(args, source, target)
def partition(args, size_boot, size_reserve):
def partition(args, layout, size_boot, size_reserve):
"""
Partition /dev/install and create /dev/install{p1,p2,p3}:
* /dev/installp1: boot
@ -53,6 +53,7 @@ def partition(args, size_boot, size_reserve):
When adjusting this function, make sure to also adjust
ondev-prepare-internal-storage.sh in postmarketos-ondev.git!
:param layout: partition layout from get_partition_layout()
:param size_boot: size of the boot partition in MiB
:param size_reserve: empty partition between root and boot in MiB (pma#463)
"""
@ -84,7 +85,7 @@ def partition(args, size_boot, size_reserve):
commands += [
["mkpart", "primary", mb_root_start, "100%"],
["set", "1", "boot", "on"]
["set", str(layout["boot"]), "boot", "on"]
]
for command in commands: