pmb.chroot package

Submodules

pmb.chroot.apk module

pmb.chroot.apk.install(packages, chroot: Chroot, build=True)

Install packages from pmbootstrap’s local package index or the pmOS/Alpine binary package mirrors. Iterate over all dependencies recursively, and build missing packages as necessary.

Parameters:
  • packages – list of pkgnames to be installed

  • suffix – the chroot suffix, e.g. “native” or “rootfs_qemu-amd64”

  • build – automatically build the package, when it does not exist yet or needs to be updated, and it is inside pmaports. For the special case that all packages are expected to be in Alpine’s repositories, set this to False for performance optimization.

pmb.chroot.apk.install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[str], chroot: Chroot)

Run apk to add packages, and ensure only the desired packages get explicitly marked as installed.

Parameters:
  • to_add – list of pkgnames to install, without their dependencies

  • to_add_local – return of packages_get_locally_built_apks()

  • to_del – list of pkgnames to be deleted, this should be set to conflicting dependencies in any of the packages to be installed or their dependencies (e.g. [“unl0kr”])

  • chroot – the chroot suffix, e.g. “native” or “rootfs_qemu-amd64”

pmb.chroot.apk.installed(suffix: ~pmb.core.chroot.Chroot = <pmb.core.chroot.Chroot object>)

Read the list of installed packages (which has almost the same format, as an APKINDEX, but with more keys).

Returns:

a dictionary with the following structure: { “postmarketos-mkinitfs”: { “pkgname”: “postmarketos-mkinitfs” “version”: “0.0.4-r10”, “depends”: [“busybox-extras”, “lddtree”, …], “provides”: [“mkinitfs=0.0.1”] }, …

}

pmb.chroot.apk.packages_get_locally_built_apks(packages, arch: Arch) list[Path]

Iterate over packages and if existing, get paths to locally built packages. This is used to force apk to upgrade packages to newer local versions, even if the pkgver and pkgrel did not change.

Parameters:
  • packages – list of pkgnames

  • arch – architecture that the locally built packages should have

Returns:

Pair of lists, the first is the input packages with local apks removed. the second is a list of apk file paths that are valid inside the chroots, e.g. [“/mnt/pmbootstrap/packages/x86_64/hello-world-1-r6.apk”, …]

pmb.chroot.apk.packages_split_to_add_del(packages)

Sort packages into “to_add” and “to_del” lists depending on their pkgname starting with an exclamation mark.

Parameters:

packages – list of pkgnames

Returns:

(to_add, to_del) - tuple of lists of pkgnames, e.g. ([“hello-world”, …], [“some-conflict-pkg”, …])

pmb.chroot.apk_static module

pmb.chroot.apk_static.download(file)

Download a single file from an Alpine mirror.

pmb.chroot.apk_static.extract(version, apk_path)

Extract everything to temporary locations, verify signatures and reported versions. When everything is right, move the extracted apk.static to the final location.

pmb.chroot.apk_static.extract_temp(tar, sigfilename)

Extract apk.static and signature as temporary files.

pmb.chroot.apk_static.init()

Download, verify, extract $WORK/apk.static.

pmb.chroot.apk_static.read_signature_info(tar)

Find various information about the signature that was used to sign /sbin/apk.static inside the archive (not to be confused with the normal apk archive signature!)

Returns:

(sigfilename, sigkey_path)

pmb.chroot.apk_static.run(parameters)
pmb.chroot.apk_static.verify_signature(files, sigkey_path)

Verify the signature with openssl.

Parameters:

files – return value from extract_temp()

Raises:

RuntimeError – when verification failed and removes temp files

pmb.chroot.binfmt module

pmb.chroot.binfmt.is_registered(arch_qemu: Arch)
pmb.chroot.binfmt.register(arch: Arch)

Get arch, magic, mask.

pmb.chroot.binfmt.unregister(arch: Arch)

pmb.chroot.init module

class pmb.chroot.init.UsrMerge(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Merge /usr while initializing chroot. https://systemd.io/THE_CASE_FOR_THE_USR_MERGE/

AUTO = 0
OFF = 2
ON = 1
pmb.chroot.init.copy_resolv_conf(chroot: Chroot)

Use pythons super fast file compare function (due to caching) and copy the /etc/resolv.conf to the chroot, in case it is different from the host. If the file doesn’t exist, create an empty file with ‘touch’.

pmb.chroot.init.init_keys()

All Alpine and postmarketOS repository keys are shipped with pmbootstrap. Copy them into $WORK/config_apk_keys, which gets mounted inside the various chroots as /etc/apk/keys.

This is done before installing any package, so apk can verify APKINDEX files of binary repositories even though alpine-keys/postmarketos-keys are not installed yet.

pmb.chroot.init.init_usr_merge(chroot: Chroot)
pmb.chroot.init.mark_in_chroot(chroot: ~pmb.core.chroot.Chroot = <pmb.core.chroot.Chroot object>)

Touch a flag so we can know when we’re running in chroot (and don’t accidentally flash partitions on our host). This marker gets removed in pmb.chroot.shutdown (pmbootstrap shutdown).

pmb.chroot.init.warn_if_chroot_is_outdated(chroot: Chroot)

pmb.chroot.initfs module

pmb.chroot.initfs.build(flavor, chroot: Chroot)
pmb.chroot.initfs.extract(flavor, chroot: Chroot, extra=False)

Extract the initramfs to /tmp/initfs-extracted or the initramfs-extra to /tmp/initfs-extra-extracted and return the outside extraction path.

pmb.chroot.initfs.frontend(args: PmbArgs)
pmb.chroot.initfs.ls(flavor, suffix, extra=False)

pmb.chroot.initfs_hooks module

pmb.chroot.initfs_hooks.add(hook, suffix: Chroot)
pmb.chroot.initfs_hooks.delete(hook, suffix: Chroot)
pmb.chroot.initfs_hooks.list_aports()
pmb.chroot.initfs_hooks.list_chroot(suffix: Chroot, remove_prefix=True)
pmb.chroot.initfs_hooks.ls(suffix: Chroot)
pmb.chroot.initfs_hooks.update(suffix: Chroot)

Rebuild and update all hooks that are out of date

pmb.chroot.mount module

pmb.chroot.mount.create_device_nodes(chroot: Chroot)

Create device nodes for null, zero, full, random, urandom in the chroot.

pmb.chroot.mount.mount(chroot: Chroot)
pmb.chroot.mount.mount_chroot_image(chroot: Chroot)

Mount an IMAGE type chroot, to modify an existing rootfs image. This doesn’t support split images yet!

pmb.chroot.mount.mount_dev_tmpfs(chroot: ~pmb.core.chroot.Chroot = <pmb.core.chroot.Chroot object>)

Mount tmpfs inside the chroot’s dev folder to make sure we can create device nodes, even if the filesystem of the work folder does not support it.

pmb.chroot.mount.mount_native_into_foreign(chroot: Chroot)
pmb.chroot.mount.remove_mnt_pmbootstrap(chroot: Chroot)

Safely remove /mnt/pmbootstrap directories from the chroot, without running rm -r as root and potentially removing data inside the mountpoint in case it was still mounted (bug in pmbootstrap, or user ran pmbootstrap 2x in parallel). This is similar to running ‘rm -r -d’, but we don’t assume that the host’s rm has the -d flag (busybox does not).

pmb.chroot.other module

pmb.chroot.other.copy_xauthority(args: PmbArgs)

Copy the host system’s Xauthority file to the pmos user inside the chroot, so we can start X11 applications from there.

pmb.chroot.other.kernel_flavor_installed(chroot: Chroot, autoinstall=True)

Get installed kernel flavor. Optionally install the device’s kernel beforehand.

Parameters:
  • suffix – the chroot suffix, e.g. “native” or “rootfs_qemu-amd64”

  • autoinstall – install the device’s kernel if it is not installed

Returns:

  • string with the installed kernel flavor, e.g. [“postmarketos-qcom-sdm845”]

  • None if no kernel is installed

pmb.chroot.root module

pmb.chroot.shutdown module

pmb.chroot.shutdown.kill_adb()

Kill adb daemon if it’s running.

pmb.chroot.shutdown.kill_sccache()

Kill sccache daemon if it’s running. Unlike ccache it automatically spawns a daemon when you call it and exits after some time of inactivity.

pmb.chroot.shutdown.shutdown(only_install_related=False)
pmb.chroot.shutdown.shutdown_cryptsetup_device(name: str)
Parameters:

name – cryptsetup device name, usually “pm_crypt” in pmbootstrap

pmb.chroot.user module

pmb.chroot.zap module

pmb.chroot.zap.del_chroot(path: Path, confirm=True, dry=False)
pmb.chroot.zap.zap(confirm=True, dry=False, pkgs_local=False, http=False, pkgs_local_mismatch=False, pkgs_online_mismatch=False, distfiles=False, rust=False, netboot=False)

Shutdown everything inside the chroots (e.g. adb), umount everything and then safely remove folders from the work-directory.

Parameters:
  • dry – Only show what would be deleted, do not delete for real

  • pkgs_local – Remove all self-compiled packages (!)

  • http – Clear the http cache (used e.g. for the initial apk download)

  • pkgs_local_mismatch – Remove the packages that have a different version compared to what is in the aports folder.

  • pkgs_online_mismatch – Clean out outdated binary packages downloaded from mirrors (e.g. from Alpine)

  • distfiles – Clear the downloaded files cache

  • rust – Remove rust related caches

  • netboot – Remove images for netboot

NOTE: This function gets called in pmb/config/init.py, with only get_context().config.work and args.device set!

pmb.chroot.zap.zap_pkgs_local_mismatch(confirm=True, dry=False)
pmb.chroot.zap.zap_pkgs_online_mismatch(confirm=True, dry=False)

Module contents