install_system_image: add sdcard argument (MR 1946)
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:
parent
718839364b
commit
8fb69f9c46
|
@ -374,7 +374,7 @@ def sanity_check_sdcard(device):
|
||||||
|
|
||||||
|
|
||||||
def install_system_image(args, size_reserve, suffix, root_label="pmOS_root",
|
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 MiB (pma#463)
|
:param size_reserve: empty partition between root and boot in MiB (pma#463)
|
||||||
:param suffix: the chroot suffix, where the rootfs that will be installed
|
: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 step: next installation step
|
||||||
:param steps: total installation steps
|
:param steps: total installation steps
|
||||||
:param split: create separate images for boot and root partitions
|
: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
|
# Partition and fill image/sdcard
|
||||||
logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***")
|
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)
|
(size_boot, size_root) = get_subpartitions_size(args, suffix)
|
||||||
if not args.rsync:
|
if not args.rsync:
|
||||||
pmb.install.blockdevice.create(args, size_boot, size_root,
|
pmb.install.blockdevice.create(args, size_boot, size_root,
|
||||||
size_reserve, split)
|
size_reserve, split, sdcard)
|
||||||
if not split:
|
if not split:
|
||||||
pmb.install.partition(args, size_boot, size_reserve)
|
pmb.install.partition(args, size_boot, size_reserve)
|
||||||
if not split:
|
if not split:
|
||||||
root_id = 3 if size_reserve else 2
|
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
|
# Just copy all the files
|
||||||
logging.info(f"*** ({step + 1}/{steps}) FILL INSTALL BLOCKDEVICE ***")
|
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:
|
if sparse is None:
|
||||||
sparse = args.deviceinfo["flash_sparse"] == "true"
|
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")
|
logging.info("(native) make sparse rootfs")
|
||||||
pmb.chroot.apk.install(args, ["android-tools"])
|
pmb.chroot.apk.install(args, ["android-tools"])
|
||||||
sys_image = args.device + ".img"
|
sys_image = args.device + ".img"
|
||||||
|
@ -571,5 +572,6 @@ def install(args):
|
||||||
elif args.android_recovery_zip:
|
elif args.android_recovery_zip:
|
||||||
return install_recovery_zip(args)
|
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)
|
print_flash_info(args)
|
||||||
|
|
|
@ -9,14 +9,15 @@ import pmb.helpers.cli
|
||||||
import pmb.config
|
import pmb.config
|
||||||
|
|
||||||
|
|
||||||
def previous_install(args):
|
def previous_install(args, path):
|
||||||
"""
|
"""
|
||||||
Search the sdcard for possible existence of a previous installation of pmOS.
|
Search the sdcard for possible existence of a previous installation of pmOS.
|
||||||
We temporarily mount the possible pmOS_boot partition as /dev/sdcardp1 inside
|
We temporarily mount the possible pmOS_boot partition as /dev/sdcardp1 inside
|
||||||
the native chroot to check the label from there.
|
the native chroot to check the label from there.
|
||||||
|
:param path: path to sdcard device (e.g. /dev/mmcblk0)
|
||||||
"""
|
"""
|
||||||
label = ""
|
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):
|
if not os.path.exists(blockdevice_outside):
|
||||||
continue
|
continue
|
||||||
blockdevice_inside = "/dev/sdcardp1"
|
blockdevice_inside = "/dev/sdcardp1"
|
||||||
|
@ -28,29 +29,31 @@ def previous_install(args):
|
||||||
return "pmOS_boot" in label
|
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
|
# Sanity checks
|
||||||
if args.deviceinfo["external_storage"] != "true":
|
if args.deviceinfo["external_storage"] != "true":
|
||||||
raise RuntimeError("According to the deviceinfo, this device does"
|
raise RuntimeError("According to the deviceinfo, this device does"
|
||||||
" not support a sdcard installation.")
|
" not support a sdcard installation.")
|
||||||
if not os.path.exists(args.sdcard):
|
if not os.path.exists(path):
|
||||||
raise RuntimeError("The sdcard device does not exist: " +
|
raise RuntimeError(f"The sdcard device does not exist: {path}")
|
||||||
args.sdcard)
|
for path_mount in glob.glob(f"{path}*"):
|
||||||
for path in glob.glob(args.sdcard + "*"):
|
if pmb.helpers.mount.ismount(path_mount):
|
||||||
if pmb.helpers.mount.ismount(path):
|
raise RuntimeError(f"{path_mount} is mounted! Will not attempt to"
|
||||||
raise RuntimeError(path + " is mounted! We will not attempt"
|
" format this!")
|
||||||
" to format this!")
|
logging.info(f"(native) mount /dev/install (host: {path})")
|
||||||
logging.info("(native) mount /dev/install (host: " + args.sdcard + ")")
|
pmb.helpers.mount.bind_file(args, path,
|
||||||
pmb.helpers.mount.bind_file(args, args.sdcard,
|
|
||||||
args.work + "/chroot_native/dev/install")
|
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"
|
if not pmb.helpers.cli.confirm(args, "WARNING: This device has a"
|
||||||
" previous installation of pmOS."
|
" previous installation of pmOS."
|
||||||
" CONTINUE?"):
|
" CONTINUE?"):
|
||||||
raise RuntimeError("Aborted.")
|
raise RuntimeError("Aborted.")
|
||||||
else:
|
else:
|
||||||
if not pmb.helpers.cli.confirm(args, "EVERYTHING ON " + args.sdcard +
|
if not pmb.helpers.cli.confirm(args, f"EVERYTHING ON {path} WILL BE"
|
||||||
" WILL BE ERASED! CONTINUE?"):
|
" ERASED! CONTINUE?"):
|
||||||
raise RuntimeError("Aborted.")
|
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)
|
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").
|
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 MiB
|
:param size_root: size of the root partition in MiB
|
||||||
:param size_reserve: empty partition between root and boot in MiB (pma#463)
|
:param size_reserve: empty partition between root and boot in MiB (pma#463)
|
||||||
:param split: create separate images for boot and root partitions
|
: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(
|
pmb.helpers.mount.umount_all(
|
||||||
args, args.work + "/chroot_native/dev/install")
|
args, args.work + "/chroot_native/dev/install")
|
||||||
if args.sdcard:
|
if sdcard:
|
||||||
mount_sdcard(args)
|
mount_sdcard(args, sdcard)
|
||||||
else:
|
else:
|
||||||
create_and_mount_image(args, size_boot, size_root, size_reserve,
|
create_and_mount_image(args, size_boot, size_root, size_reserve,
|
||||||
split)
|
split)
|
||||||
|
|
|
@ -43,10 +43,11 @@ def format_and_mount_root(args, device):
|
||||||
raise RuntimeError("Failed to open cryptdevice!")
|
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 device: root partition on install block device (e.g. /dev/installp2)
|
||||||
:param root_label: label of the root partition (e.g. "pmOS_root")
|
: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
|
# Block device
|
||||||
if args.full_disk_encryption:
|
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
|
# When we don't know the file system size before hand like
|
||||||
# with non-block devices, we need to explicitely set a number of
|
# with non-block devices, we need to explicitely set a number of
|
||||||
# inodes. See #1717 and #1845 for details
|
# inodes. See #1717 and #1845 for details
|
||||||
if not args.sdcard:
|
if not sdcard:
|
||||||
mkfs_ext4_args = mkfs_ext4_args + ["-N", "100000"]
|
mkfs_ext4_args = mkfs_ext4_args + ["-N", "100000"]
|
||||||
|
|
||||||
pmb.chroot.root(args, mkfs_ext4_args + [device])
|
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])
|
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 MiB (pma#463)
|
:param size_reserve: empty partition between root and boot in MiB (pma#463)
|
||||||
:param root_label: label of the root partition (e.g. "pmOS_root")
|
: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 = "/dev/installp3" if size_reserve else "/dev/installp2"
|
||||||
format_and_mount_root(args, root_dev)
|
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)
|
format_and_mount_boot(args)
|
||||||
|
|
|
@ -8,13 +8,14 @@ import pmb.config
|
||||||
import pmb.install.losetup
|
import pmb.install.losetup
|
||||||
|
|
||||||
|
|
||||||
def partitions_mount(args, root_id):
|
def partitions_mount(args, root_id, sdcard):
|
||||||
"""
|
"""
|
||||||
Mount blockdevices of partitions inside native chroot
|
Mount blockdevices of partitions inside native chroot
|
||||||
:param root_id: root partition id
|
:param root_id: root partition id
|
||||||
|
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None
|
||||||
"""
|
"""
|
||||||
prefix = args.sdcard
|
prefix = sdcard
|
||||||
if not args.sdcard:
|
if not 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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue