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:
```
$ pmbootstrap install --sdcard=/dev/mmcblk0 --rsync
$ pmbootstrap install --disk=/dev/mmcblk0 --rsync
```
Run the image in QEMU:

View File

@ -19,7 +19,7 @@ def frontend(args):
pattern = chroot + "/home/pmos/rootfs/" + args.device + "*.img"
if not glob.glob(pattern):
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)
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:
raise ValueError("Installation using rsync is not compatible with full"
" disk encryption.")
if args.rsync and not args.sdcard:
raise ValueError("Installation using rsync only works on sdcard.")
if args.rsync and not args.disk:
raise ValueError("Installation using rsync only works with --disk.")
# On-device installer checks
# 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.full_disk_encryption:
raise ValueError("--on-device-installer cannot be combined with"
@ -287,7 +287,7 @@ def install(args):
" installer.")
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
flasher = pmb.config.flashers.get(args.deviceinfo["flash_method"], {})
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']}"])
def sanity_check_sdcard(args):
device = args.sdcard
def sanity_check_disk(args):
device = args.disk
device_name = os.path.basename(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)):
with open('/sys/class/block/{}/ro'.format(device_name), 'r') as handle:
ro = handle.read()
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):
device = args.sdcard
def sanity_check_disk_size(args):
device = args.disk
devpath = os.path.realpath(device)
sysfs = '/sys/class/block/{}/size'.format(devpath.replace('/dev/', ''))
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,
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 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 root_label: label of the root partition (e.g. "pmOS_root")
: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 ***")
pmb.chroot.shutdown(args, True)
(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)
if not args.rsync:
pmb.install.blockdevice.create(args, size_boot, size_root,
size_reserve, split, sdcard)
size_reserve, split, disk)
if not split:
if args.deviceinfo["cgpt_kpart"] and args.install_cgpt:
pmb.install.partition_cgpt(
@ -798,9 +798,9 @@ def install_system_image(args, size_reserve, suffix, step, steps,
else:
pmb.install.partition(args, layout, size_boot, size_reserve)
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
logging.info("(native) create /etc/fstab")
@ -831,8 +831,8 @@ def install_system_image(args, size_reserve, suffix, step, steps,
embed_firmware(args, suffix)
write_cgpt_kpart(args, layout, suffix)
if sdcard:
logging.info("Unmounting SD card (this may take a while "
if disk:
logging.info(f"Unmounting disk {disk} (this may take a while "
"to sync, please wait)")
pmb.chroot.shutdown(args, True)
@ -841,7 +841,7 @@ def install_system_image(args, size_reserve, suffix, step, steps,
if sparse is None:
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")
pmb.chroot.apk.install(args, ["android-tools"])
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"
" 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:
logging.info("* pmbootstrap flasher flash_rootfs")
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.
# (e.g. an Android boot image is generated). In that case, "flash_kernel"
# works even when partitions are split or installing for sdcard.
# This is not possible if the flash method requires split partitions.
# works even when partitions are split or installing to disk. This is not
# possible if the flash method requires split partitions.
if "flash_kernel" in flasher_actions and \
(not requires_split or args.split):
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",
"pmOS_inst_boot")
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):
@ -1154,9 +1154,9 @@ def create_device_rootfs(args, step, steps):
def install(args):
# Sanity checks
if not args.android_recovery_zip and args.sdcard:
sanity_check_sdcard(args)
sanity_check_sdcard_size(args)
if not args.android_recovery_zip and args.disk:
sanity_check_disk(args)
sanity_check_disk_size(args)
if args.on_device_installer:
sanity_check_ondev_version(args)
@ -1191,7 +1191,7 @@ def install(args):
install_on_device_installer(args, step, steps)
else:
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_sshd_info(args)

View File

@ -11,16 +11,16 @@ import pmb.config
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
/dev/sdcardp1 inside the native chroot to check the label from there.
:param path: path to sdcard device (e.g. /dev/mmcblk0)
/dev/diskp1 inside the native chroot to check the label from there.
:param path: path to disk block device (e.g. /dev/mmcblk0)
"""
label = ""
for blockdevice_outside in [f"{path}1", f"{path}p1"]:
if not os.path.exists(blockdevice_outside):
continue
blockdevice_inside = "/dev/sdcardp1"
blockdevice_inside = "/dev/diskp1"
pmb.helpers.mount.bind_file(args, blockdevice_outside,
args.work + '/chroot_native' +
blockdevice_inside)
@ -38,13 +38,13 @@ def previous_install(args, path):
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
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}*"):
if pmb.helpers.mount.ismount(path_mount):
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)
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").
@ -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_reserve: empty partition between root and boot in MiB (pma#463)
: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(
args, args.work + "/chroot_native/dev/install")
if sdcard:
mount_sdcard(args, sdcard)
if disk:
mount_disk(args, disk)
else:
create_and_mount_image(args, size_boot, size_root, size_reserve,
split)

View File

@ -86,11 +86,11 @@ def get_root_filesystem(args):
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 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
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
# with non-block devices, we need to explicitly set a number of
# inodes. See #1717 and #1845 for details
if not sdcard:
if not disk:
mkfs_root_args = mkfs_root_args + ["-N", "100000"]
elif filesystem == "f2fs":
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])
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 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
:param disk: path to disk block device (e.g. /dev/mmcblk0) or None
"""
root_dev = f"/dev/installp{layout['root']}"
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)
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)

View File

@ -8,14 +8,14 @@ import pmb.config
import pmb.install.losetup
def partitions_mount(args, layout, sdcard):
def partitions_mount(args, layout, disk):
"""
Mount blockdevices of partitions inside native chroot
: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
if not sdcard:
prefix = disk
if not disk:
img_path = "/home/pmos/rootfs/" + args.device + ".img"
prefix = pmb.install.losetup.device_by_back_file(args, img_path)

View File

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