install: rename --sdcard arg to --disk

Rename the argument, because any block device can be passed to the
argument. Use "disk", because the other short word "device" usually
means the target device/phone to install.

Keep --sdcard as alias for compatibility with existing scripts and
muscle memory.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20231119182302.2415-1-ollieparanoid@postmarketos.org%3E
This commit is contained in:
Oliver Smith 2023-11-19 19:22:50 +01:00
parent 942ee20789
commit ef047137d0
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
8 changed files with 58 additions and 56 deletions

View File

@ -171,7 +171,7 @@ $ pmbootstrap install --fde
Update existing installation on SD card: Update existing installation on SD card:
``` ```
$ pmbootstrap install --sdcard=/dev/mmcblk0 --rsync $ pmbootstrap install --disk=/dev/mmcblk0 --rsync
``` ```
Run the image in QEMU: Run the image in QEMU:

View File

@ -19,7 +19,7 @@ def frontend(args):
pattern = chroot + "/home/pmos/rootfs/" + args.device + "*.img" pattern = chroot + "/home/pmos/rootfs/" + args.device + "*.img"
if not glob.glob(pattern): if not glob.glob(pattern):
logging.info("NOTE: To export the rootfs image, run 'pmbootstrap" logging.info("NOTE: To export the rootfs image, run 'pmbootstrap"
" install' first (without the 'sdcard' parameter).") " install' first (without the 'disk' parameter).")
# Rebuild the initramfs, just to make sure (see #69) # Rebuild the initramfs, just to make sure (see #69)
flavor = pmb.helpers.frontend._parse_flavor(args, args.autoinstall) flavor = pmb.helpers.frontend._parse_flavor(args, args.autoinstall)

View File

@ -238,12 +238,12 @@ def install(args):
if args.rsync and args.full_disk_encryption: if args.rsync and args.full_disk_encryption:
raise ValueError("Installation using rsync is not compatible with full" raise ValueError("Installation using rsync is not compatible with full"
" disk encryption.") " disk encryption.")
if args.rsync and not args.sdcard: if args.rsync and not args.disk:
raise ValueError("Installation using rsync only works on sdcard.") raise ValueError("Installation using rsync only works with --disk.")
# On-device installer checks # On-device installer checks
# Note that this can't be in the mutually exclusive group that has most of # Note that this can't be in the mutually exclusive group that has most of
# the conflicting options, because then it would not work with --sdcard. # the conflicting options, because then it would not work with --disk.
if args.on_device_installer: if args.on_device_installer:
if args.full_disk_encryption: if args.full_disk_encryption:
raise ValueError("--on-device-installer cannot be combined with" raise ValueError("--on-device-installer cannot be combined with"
@ -287,7 +287,7 @@ def install(args):
" installer.") " installer.")
args.user = "user" args.user = "user"
if not args.sdcard and args.split is None: if not args.disk and args.split is None:
# Default to split if the flash method requires it # Default to split if the flash method requires it
flasher = pmb.config.flashers.get(args.deviceinfo["flash_method"], {}) flasher = pmb.config.flashers.get(args.deviceinfo["flash_method"], {})
if flasher.get("split", False): if flasher.get("split", False):

View File

@ -621,20 +621,20 @@ def write_cgpt_kpart(args, layout, suffix):
args, ["dd", f"if={filename}", f"of=/dev/installp{layout['kernel']}"]) args, ["dd", f"if={filename}", f"of=/dev/installp{layout['kernel']}"])
def sanity_check_sdcard(args): def sanity_check_disk(args):
device = args.sdcard device = args.disk
device_name = os.path.basename(device) device_name = os.path.basename(device)
if not os.path.exists(device): if not os.path.exists(device):
raise RuntimeError(f"{device} doesn't exist, is the sdcard plugged?") raise RuntimeError(f"{device} doesn't exist, is the disk plugged?")
if os.path.isdir('/sys/class/block/{}'.format(device_name)): if os.path.isdir('/sys/class/block/{}'.format(device_name)):
with open('/sys/class/block/{}/ro'.format(device_name), 'r') as handle: with open('/sys/class/block/{}/ro'.format(device_name), 'r') as handle:
ro = handle.read() ro = handle.read()
if ro == '1\n': if ro == '1\n':
raise RuntimeError(f"{device} is read-only, is the sdcard locked?") raise RuntimeError(f"{device} is read-only, maybe a locked SD card?")
def sanity_check_sdcard_size(args): def sanity_check_disk_size(args):
device = args.sdcard device = args.disk
devpath = os.path.realpath(device) devpath = os.path.realpath(device)
sysfs = '/sys/class/block/{}/size'.format(devpath.replace('/dev/', '')) sysfs = '/sys/class/block/{}/size'.format(devpath.replace('/dev/', ''))
if not os.path.isfile(sysfs): if not os.path.isfile(sysfs):
@ -770,7 +770,7 @@ def create_fstab(args, layout, suffix):
def install_system_image(args, size_reserve, suffix, step, steps, def install_system_image(args, size_reserve, suffix, step, steps,
boot_label="pmOS_boot", root_label="pmOS_root", boot_label="pmOS_boot", root_label="pmOS_root",
split=False, sdcard=None): split=False, disk=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
@ -780,9 +780,9 @@ def install_system_image(args, size_reserve, suffix, step, steps,
:param boot_label: label of the boot partition (e.g. "pmOS_boot") :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 root_label: label of the root partition (e.g. "pmOS_root")
: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 :param disk: path to disk block device (e.g. /dev/mmcblk0) or None
""" """
# Partition and fill image/sdcard # Partition and fill image file/disk block device
logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***") logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***")
pmb.chroot.shutdown(args, True) pmb.chroot.shutdown(args, True)
(size_boot, size_root) = get_subpartitions_size(args, suffix) (size_boot, size_root) = get_subpartitions_size(args, suffix)
@ -790,7 +790,7 @@ def install_system_image(args, size_reserve, suffix, step, steps,
and args.install_cgpt) and args.install_cgpt)
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, sdcard) size_reserve, split, disk)
if not split: if not split:
if args.deviceinfo["cgpt_kpart"] and args.install_cgpt: if args.deviceinfo["cgpt_kpart"] and args.install_cgpt:
pmb.install.partition_cgpt( pmb.install.partition_cgpt(
@ -798,9 +798,9 @@ def install_system_image(args, size_reserve, suffix, step, steps,
else: else:
pmb.install.partition(args, layout, size_boot, size_reserve) pmb.install.partition(args, layout, size_boot, size_reserve)
if not split: if not split:
pmb.install.partitions_mount(args, layout, sdcard) pmb.install.partitions_mount(args, layout, disk)
pmb.install.format(args, layout, boot_label, root_label, sdcard) pmb.install.format(args, layout, boot_label, root_label, disk)
# Create /etc/fstab and /etc/crypttab # Create /etc/fstab and /etc/crypttab
logging.info("(native) create /etc/fstab") logging.info("(native) create /etc/fstab")
@ -831,8 +831,8 @@ def install_system_image(args, size_reserve, suffix, step, steps,
embed_firmware(args, suffix) embed_firmware(args, suffix)
write_cgpt_kpart(args, layout, suffix) write_cgpt_kpart(args, layout, suffix)
if sdcard: if disk:
logging.info("Unmounting SD card (this may take a while " logging.info(f"Unmounting disk {disk} (this may take a while "
"to sync, please wait)") "to sync, please wait)")
pmb.chroot.shutdown(args, True) pmb.chroot.shutdown(args, True)
@ -841,7 +841,7 @@ def install_system_image(args, size_reserve, suffix, step, steps,
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 sdcard: if sparse and not split and not disk:
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"
@ -887,7 +887,7 @@ def print_flash_info(args):
logging.info("Run the following to flash your installation to the" logging.info("Run the following to flash your installation to the"
" target device:") " target device:")
if "flash_rootfs" in flasher_actions and not args.sdcard and \ if "flash_rootfs" in flasher_actions and not args.disk and \
bool(args.split) == requires_split: bool(args.split) == requires_split:
logging.info("* pmbootstrap flasher flash_rootfs") logging.info("* pmbootstrap flasher flash_rootfs")
logging.info(" Flashes the generated rootfs image to your device:") logging.info(" Flashes the generated rootfs image to your device:")
@ -920,8 +920,8 @@ def print_flash_info(args):
# Most flash methods operate independently of the boot partition. # Most flash methods operate independently of the boot partition.
# (e.g. an Android boot image is generated). In that case, "flash_kernel" # (e.g. an Android boot image is generated). In that case, "flash_kernel"
# works even when partitions are split or installing for sdcard. # works even when partitions are split or installing to disk. This is not
# This is not possible if the flash method requires split partitions. # possible if the flash method requires split partitions.
if "flash_kernel" in flasher_actions and \ if "flash_kernel" in flasher_actions and \
(not requires_split or args.split): (not requires_split or args.split):
logging.info("* pmbootstrap flasher flash_kernel") logging.info("* pmbootstrap flasher flash_kernel")
@ -1033,7 +1033,7 @@ def install_on_device_installer(args, step, steps):
boot_label = pmaports_cfg.get("supported_install_boot_label", boot_label = pmaports_cfg.get("supported_install_boot_label",
"pmOS_inst_boot") "pmOS_inst_boot")
install_system_image(args, size_reserve, suffix_installer, step, steps, install_system_image(args, size_reserve, suffix_installer, step, steps,
boot_label, "pmOS_install", args.split, args.sdcard) boot_label, "pmOS_install", args.split, args.disk)
def get_selected_providers(args, packages): def get_selected_providers(args, packages):
@ -1154,9 +1154,9 @@ def create_device_rootfs(args, step, steps):
def install(args): def install(args):
# Sanity checks # Sanity checks
if not args.android_recovery_zip and args.sdcard: if not args.android_recovery_zip and args.disk:
sanity_check_sdcard(args) sanity_check_disk(args)
sanity_check_sdcard_size(args) sanity_check_disk_size(args)
if args.on_device_installer: if args.on_device_installer:
sanity_check_ondev_version(args) sanity_check_ondev_version(args)
@ -1191,7 +1191,7 @@ def install(args):
install_on_device_installer(args, step, steps) install_on_device_installer(args, step, steps)
else: else:
install_system_image(args, 0, f"rootfs_{args.device}", step, steps, install_system_image(args, 0, f"rootfs_{args.device}", step, steps,
split=args.split, sdcard=args.sdcard) split=args.split, disk=args.disk)
print_flash_info(args) print_flash_info(args)
print_sshd_info(args) print_sshd_info(args)

View File

@ -11,16 +11,16 @@ import pmb.config
def previous_install(args, path): def previous_install(args, path):
""" """
Search the sdcard for possible existence of a previous installation of Search the disk for possible existence of a previous installation of
pmOS. We temporarily mount the possible pmOS_boot partition as pmOS. We temporarily mount the possible pmOS_boot partition as
/dev/sdcardp1 inside the native chroot to check the label from there. /dev/diskp1 inside the native chroot to check the label from there.
:param path: path to sdcard device (e.g. /dev/mmcblk0) :param path: path to disk block device (e.g. /dev/mmcblk0)
""" """
label = "" label = ""
for blockdevice_outside in [f"{path}1", f"{path}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/diskp1"
pmb.helpers.mount.bind_file(args, blockdevice_outside, pmb.helpers.mount.bind_file(args, blockdevice_outside,
args.work + '/chroot_native' + args.work + '/chroot_native' +
blockdevice_inside) blockdevice_inside)
@ -38,13 +38,13 @@ def previous_install(args, path):
return "pmOS_boot" in label return "pmOS_boot" in label
def mount_sdcard(args, path): def mount_disk(args, path):
""" """
:param path: path to sdcard device (e.g. /dev/mmcblk0) :param path: path to disk block device (e.g. /dev/mmcblk0)
""" """
# Sanity checks # Sanity checks
if not os.path.exists(path): if not os.path.exists(path):
raise RuntimeError(f"The sdcard device does not exist: {path}") raise RuntimeError(f"The disk block device does not exist: {path}")
for path_mount in glob.glob(f"{path}*"): for path_mount in glob.glob(f"{path}*"):
if pmb.helpers.mount.ismount(path_mount): if pmb.helpers.mount.ismount(path_mount):
raise RuntimeError(f"{path_mount} is mounted! Will not attempt to" raise RuntimeError(f"{path_mount} is mounted! Will not attempt to"
@ -126,7 +126,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, sdcard): def create(args, size_boot, size_root, size_reserve, split, disk):
""" """
Create /dev/install (the "install blockdevice"). Create /dev/install (the "install blockdevice").
@ -134,12 +134,12 @@ def create(args, size_boot, size_root, size_reserve, split, sdcard):
: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 :param disk: path to disk block 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 sdcard: if disk:
mount_sdcard(args, sdcard) mount_disk(args, disk)
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)

View File

@ -86,11 +86,11 @@ def get_root_filesystem(args):
return ret return ret
def format_and_mount_root(args, device, root_label, sdcard): def format_and_mount_root(args, device, root_label, disk):
""" """
: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 :param disk: path to disk block device (e.g. /dev/mmcblk0) or None
""" """
# Format # Format
if not args.rsync: if not args.rsync:
@ -105,7 +105,7 @@ def format_and_mount_root(args, device, root_label, sdcard):
# 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 explicitly set a number of # with non-block devices, we need to explicitly set a number of
# inodes. See #1717 and #1845 for details # inodes. See #1717 and #1845 for details
if not sdcard: if not disk:
mkfs_root_args = mkfs_root_args + ["-N", "100000"] mkfs_root_args = mkfs_root_args + ["-N", "100000"]
elif filesystem == "f2fs": elif filesystem == "f2fs":
mkfs_root_args = ["mkfs.f2fs", "-f", "-l", root_label] mkfs_root_args = ["mkfs.f2fs", "-f", "-l", root_label]
@ -125,12 +125,12 @@ def format_and_mount_root(args, device, root_label, sdcard):
pmb.chroot.root(args, ["mount", device, mountpoint]) pmb.chroot.root(args, ["mount", device, mountpoint])
def format(args, layout, boot_label, root_label, sdcard): def format(args, layout, boot_label, root_label, disk):
""" """
:param layout: partition layout from get_partition_layout() :param layout: partition layout from get_partition_layout()
:param boot_label: label of the boot partition (e.g. "pmOS_boot") :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 root_label: label of the root partition (e.g. "pmOS_root")
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None :param disk: path to disk block device (e.g. /dev/mmcblk0) or None
""" """
root_dev = f"/dev/installp{layout['root']}" root_dev = f"/dev/installp{layout['root']}"
boot_dev = f"/dev/installp{layout['boot']}" boot_dev = f"/dev/installp{layout['boot']}"
@ -139,5 +139,5 @@ def format(args, layout, boot_label, root_label, sdcard):
format_luks_root(args, root_dev) format_luks_root(args, root_dev)
root_dev = "/dev/mapper/pm_crypt" root_dev = "/dev/mapper/pm_crypt"
format_and_mount_root(args, root_dev, root_label, sdcard) format_and_mount_root(args, root_dev, root_label, disk)
format_and_mount_boot(args, boot_dev, boot_label) format_and_mount_boot(args, boot_dev, boot_label)

View File

@ -8,14 +8,14 @@ import pmb.config
import pmb.install.losetup import pmb.install.losetup
def partitions_mount(args, layout, sdcard): def partitions_mount(args, layout, disk):
""" """
Mount blockdevices of partitions inside native chroot Mount blockdevices of partitions inside native chroot
:param layout: partition layout from get_partition_layout() :param layout: partition layout from get_partition_layout()
:param sdcard: path to sdcard device (e.g. /dev/mmcblk0) or None :param disk: path to disk block device (e.g. /dev/mmcblk0) or None
""" """
prefix = sdcard prefix = disk
if not sdcard: if not disk:
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)

View File

@ -96,9 +96,11 @@ def arguments_install(subparser):
default=None) default=None)
group.add_argument("--split", help="create separate boot and root image" group.add_argument("--split", help="create separate boot and root image"
" files", action="store_true") " files", action="store_true")
group.add_argument("--sdcard", help="do not create an image file, instead" group.add_argument("--disk", "--sdcard",
" write to the given SD card device (e.g." help="do not create an image file, instead"
" '/dev/mmcblk0')", metavar="BLOCKDEV") " write to the given block device (SD card, USB"
" stick, etc.), for example: '/dev/mmcblk0'",
metavar="BLOCKDEV")
group.add_argument("--android-recovery-zip", group.add_argument("--android-recovery-zip",
help="generate TWRP flashable zip (recommended read:" help="generate TWRP flashable zip (recommended read:"
" https://postmarketos.org/recoveryzip)", " https://postmarketos.org/recoveryzip)",
@ -106,9 +108,9 @@ def arguments_install(subparser):
group.add_argument("--no-image", help="do not generate an image", group.add_argument("--no-image", help="do not generate an image",
action="store_true", dest="no_image") action="store_true", dest="no_image")
# Image type "--sdcard" related # Image type "--disk" related
group = ret.add_argument_group("optional image type 'sdcard' arguments") group = ret.add_argument_group("optional image type 'disk' arguments")
group.add_argument("--rsync", help="update the SD card using rsync", group.add_argument("--rsync", help="update the disk using rsync",
action="store_true") action="store_true")
# Image type "--android-recovery-zip" related # Image type "--android-recovery-zip" related