mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-19 02:25:08 +03:00
Refactor the install code to stop using loop devices and instead create and manipulate a disk image directly. Both ext4 and vfat have mechanisms for formatting and populating partitions at an offset inside an image, other filesystems likely do as well but so far have not been implemented or tested. With this "pmbootstrap install" works for standard EFI disk images (e.g. QEMU, X64 or trailblazer) entirely rootless. Since the creation of the disk images happens in the same user namespace as everything else, the resulting disk images have correct ownership and permissions even though from the host perspective they are all subuids. This gets image building working properly *for the default case*. We can now build disk images! In particular, we can build disk images with a 4k sector size even on a host with a 512 byte sector size (or block size in the filesystem). This is surprisingly hard for some reason since not all libfdisk tools have the right flags. Thankfully sfdisk does. In addition, we now generate UUIDs ourselves, to break the loop between generating fstab and running mkfs (since we also populate the disk image /with/ mkfs, we need to already know the UUID when we run it...). Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
118 lines
3.7 KiB
Python
118 lines
3.7 KiB
Python
# Copyright 2023 Oliver Smith
|
|
# Copyright 2024 Stefan Hansson
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import pmb.parse.deviceinfo
|
|
from pmb import commands
|
|
from pmb.core.context import get_context
|
|
from pmb.core.chroot import Chroot
|
|
from pmb.flasher.frontend import flash_lk2nd, kernel, list_flavors, rootfs, sideload
|
|
from pmb.helpers import logging
|
|
import pmb.chroot
|
|
|
|
|
|
class Flasher(commands.Command):
|
|
def __init__(
|
|
self,
|
|
action_flasher: str,
|
|
autoinstall: bool,
|
|
cmdline: str | None,
|
|
flash_method: str,
|
|
no_reboot: bool | None,
|
|
partition: str | None,
|
|
resume: bool | None,
|
|
) -> None:
|
|
self.action_flasher = action_flasher
|
|
self.autoinstall = autoinstall
|
|
self.cmdline = cmdline
|
|
self.flash_method = flash_method
|
|
self.no_reboot = no_reboot
|
|
self.partition = partition
|
|
self.resume = resume
|
|
|
|
def run(self) -> None:
|
|
context = get_context()
|
|
action = self.action_flasher
|
|
device = context.config.device
|
|
deviceinfo = pmb.parse.deviceinfo()
|
|
method = self.flash_method or deviceinfo.flash_method
|
|
|
|
if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs", "flash_lk2nd"]:
|
|
logging.info("This device doesn't support any flash method.")
|
|
return
|
|
|
|
# Ensure the chroot is ready
|
|
pmb.chroot.init(Chroot.native())
|
|
|
|
if action in ["boot", "flash_kernel"]:
|
|
kernel(
|
|
deviceinfo,
|
|
method,
|
|
action == "boot",
|
|
self.autoinstall,
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "flash_rootfs":
|
|
rootfs(
|
|
deviceinfo,
|
|
method,
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "flash_vbmeta":
|
|
logging.info("(native) flash vbmeta.img with verity disabled flag")
|
|
pmb.flasher.run(
|
|
deviceinfo,
|
|
method,
|
|
"flash_vbmeta",
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "flash_dtbo":
|
|
logging.info("(native) flash dtbo image")
|
|
pmb.flasher.run(
|
|
deviceinfo,
|
|
method,
|
|
"flash_dtbo",
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "flash_lk2nd":
|
|
flash_lk2nd(
|
|
deviceinfo,
|
|
method,
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "list_flavors":
|
|
list_flavors(device)
|
|
elif action == "list_devices":
|
|
pmb.flasher.run(
|
|
deviceinfo,
|
|
method,
|
|
"list_devices",
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|
|
elif action == "sideload":
|
|
sideload(
|
|
deviceinfo,
|
|
method,
|
|
cmdline=self.cmdline,
|
|
no_reboot=self.no_reboot,
|
|
partition=self.partition,
|
|
resume=self.resume,
|
|
)
|