install_system_image: add sdcard argument

The on-device installer will run install_system_image once with
sdcard=None and the second time with sdcard=args.sdcard.
This commit is contained in:
Oliver Smith 2020-06-09 15:43:25 +02:00
parent 9a0ef38ee3
commit 8d0f3a1c55
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
4 changed files with 40 additions and 31 deletions

View File

@ -374,7 +374,7 @@ def sanity_check_sdcard(device):
def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
step=3, steps=5, split=False):
step=3, steps=5, split=False, sdcard=None):
"""
:param size_reserve: empty partition between root and boot in MB (pma#463)
:param suffix: the chroot suffix, where the rootfs that will be installed
@ -383,6 +383,7 @@ def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
:param step: next installation step
:param steps: total installation steps
:param split: create separate images for boot and root partitions
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
# Partition and fill image/sdcard
logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***")
@ -390,14 +391,14 @@ def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
(size_boot, size_root) = get_subpartitions_size(args, suffix)
if not args.rsync:
pmb.install.blockdevice.create(args, size_boot, size_root,
size_reserve, split)
size_reserve, split, sdcard)
if not split:
pmb.install.partition(args, size_boot, size_reserve)
if not split:
root_id = 3 if size_reserve else 2
pmb.install.partitions_mount(args, root_id)
pmb.install.partitions_mount(args, root_id, sdcard)
pmb.install.format(args, size_reserve, root_label)
pmb.install.format(args, size_reserve, root_label, sdcard)
# Just copy all the files
logging.info(f"*** ({step + 1}/{steps}) FILL INSTALL BLOCKDEVICE ***")
@ -413,7 +414,7 @@ def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
if sparse is None:
sparse = args.deviceinfo["flash_sparse"] == "true"
if sparse and not split and not args.sdcard:
if sparse and not split and not sdcard:
logging.info("(native) make sparse rootfs")
pmb.chroot.apk.install(args, ["android-tools"])
sys_image = args.device + ".img"
@ -571,5 +572,6 @@ def install(args):
elif args.android_recovery_zip:
return install_recovery_zip(args)
install_system_image(args, 0, f"rootfs_{args.device}", split=args.split)
install_system_image(args, 0, f"rootfs_{args.device}", split=args.split,
sdcard=args.sdcard)
print_flash_info(args)

View File

@ -9,14 +9,15 @@ import pmb.helpers.cli
import pmb.config
def previous_install(args):
def previous_install(args, path):
"""
Search the sdcard for possible existence of a previous installation of pmOS.
We temporarily mount the possible pmOS_boot partition as /dev/sdcardp1 inside
the native chroot to check the label from there.
:param path: path to sdcard device (e.g. /dev/mmcblk0)
"""
label = ""
for blockdevice_outside in [args.sdcard + "1", args.sdcard + "p1"]:
for blockdevice_outside in [f"{path}1", f"{path}p1"]:
if not os.path.exists(blockdevice_outside):
continue
blockdevice_inside = "/dev/sdcardp1"
@ -28,29 +29,31 @@ def previous_install(args):
return "pmOS_boot" in label
def mount_sdcard(args):
def mount_sdcard(args, path):
"""
:param path: path to sdcard device (e.g. /dev/mmcblk0)
"""
# Sanity checks
if args.deviceinfo["external_storage"] != "true":
raise RuntimeError("According to the deviceinfo, this device does"
" not support a sdcard installation.")
if not os.path.exists(args.sdcard):
raise RuntimeError("The sdcard device does not exist: " +
args.sdcard)
for path in glob.glob(args.sdcard + "*"):
if pmb.helpers.mount.ismount(path):
raise RuntimeError(path + " is mounted! We will not attempt"
" to format this!")
logging.info("(native) mount /dev/install (host: " + args.sdcard + ")")
pmb.helpers.mount.bind_file(args, args.sdcard,
if not os.path.exists(path):
raise RuntimeError(f"The sdcard device does not exist: {path}")
for path_mount in glob.glob(f"{path}*"):
if pmb.helpers.mount.ismount(path_mount):
raise RuntimeError(f"{path_mount} is mounted! Will not attempt to"
" format this!")
logging.info(f"(native) mount /dev/install (host: {path})")
pmb.helpers.mount.bind_file(args, path,
args.work + "/chroot_native/dev/install")
if previous_install(args):
if previous_install(args, path):
if not pmb.helpers.cli.confirm(args, "WARNING: This device has a"
" previous installation of pmOS."
" CONTINUE?"):
raise RuntimeError("Aborted.")
else:
if not pmb.helpers.cli.confirm(args, "EVERYTHING ON " + args.sdcard +
" WILL BE ERASED! CONTINUE?"):
if not pmb.helpers.cli.confirm(args, f"EVERYTHING ON {path} WILL BE"
" ERASED! CONTINUE?"):
raise RuntimeError("Aborted.")
@ -115,7 +118,7 @@ def create_and_mount_image(args, size_boot, size_root, size_reserve,
args.work + "/chroot_native" + mount_point)
def create(args, size_boot, size_root, size_reserve, split):
def create(args, size_boot, size_root, size_reserve, split, sdcard):
"""
Create /dev/install (the "install blockdevice").
@ -123,11 +126,12 @@ def create(args, size_boot, size_root, size_reserve, split):
:param size_root: size of the root partition in MB
:param size_reserve: empty partition between root and boot in MB (pma#463)
:param split: create separate images for boot and root partitions
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
pmb.helpers.mount.umount_all(
args, args.work + "/chroot_native/dev/install")
if args.sdcard:
mount_sdcard(args)
if sdcard:
mount_sdcard(args, sdcard)
else:
create_and_mount_image(args, size_boot, size_root, size_reserve,
split)

View File

@ -43,10 +43,11 @@ def format_and_mount_root(args, device):
raise RuntimeError("Failed to open cryptdevice!")
def format_and_mount_pm_crypt(args, device, root_label):
def format_and_mount_pm_crypt(args, device, root_label, sdcard):
"""
:param device: root partition on install block device (e.g. /dev/installp2)
:param root_label: label of the root partition (e.g. "pmOS_root")
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
# Block device
if args.full_disk_encryption:
@ -64,7 +65,7 @@ def format_and_mount_pm_crypt(args, device, root_label):
# When we don't know the file system size before hand like
# with non-block devices, we need to explicitely set a number of
# inodes. See #1717 and #1845 for details
if not args.sdcard:
if not sdcard:
mkfs_ext4_args = mkfs_ext4_args + ["-N", "100000"]
pmb.chroot.root(args, mkfs_ext4_args + [device])
@ -76,12 +77,13 @@ def format_and_mount_pm_crypt(args, device, root_label):
pmb.chroot.root(args, ["mount", device, mountpoint])
def format(args, size_reserve, root_label):
def format(args, size_reserve, root_label, sdcard):
"""
:param size_reserve: empty partition between root and boot in MB (pma#463)
: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"
format_and_mount_root(args, root_dev)
format_and_mount_pm_crypt(args, root_dev, root_label)
format_and_mount_pm_crypt(args, root_dev, root_label, sdcard)
format_and_mount_boot(args)

View File

@ -8,13 +8,14 @@ import pmb.config
import pmb.install.losetup
def partitions_mount(args, root_id):
def partitions_mount(args, root_id, sdcard):
"""
Mount blockdevices of partitions inside native chroot
:param root_id: root partition id (3 with --reserve-space, otherwise 2)
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
"""
prefix = args.sdcard
if not args.sdcard:
prefix = sdcard
if not sdcard:
img_path = "/home/pmos/rootfs/" + args.device + ".img"
prefix = pmb.install.losetup.device_by_back_file(args, img_path)