Commit graph

367 commits

Author SHA1 Message Date
Oliver Smith
3ea5a3433b
Revert "pmb: Make RunOutputTypeDefault and RunOutputTypePopen enums"
Revert the patch, as it breaks "pmbootstrap chroot".

This reverts commit 7d2f055bcb.
2025-07-10 23:53:54 +02:00
Newbyte
7d2f055bcb
pmb: Make RunOutputTypeDefault and RunOutputTypePopen enums
This allows us to get rid of some of the validation in sanity_checks()
as mypy handles this validation at "build time", and any typos in the
enum instantiation would be a runtime error rather than a silent
failure.

Additionally, it allows us to encode some of the behaviour of the
different output types into the type definition itself by using methods.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2642
2025-07-10 20:57:51 +02:00
Newbyte
7b78bcfcf9
pmb: Also apply ext4 metadata_csum workaround for archived ports
Ports in the archived category may be downstream ports. While mainline
ports also are allowed, archived ports should generally not be relied on
anyway so the loss of ext4 reliability on those shouldn't matter.

Fixes 89a80265de

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2640
2025-07-07 15:08:54 +02:00
Marc Lehmann
ec49117cff
Don't set esp flag for msdos boot partitions
When using an msdos partition table and parted is called to enable the
esp flag on the boot partition, it will disable a previously existing
lba flag on that partition. However, some devices (at least the
Raspberry Pi 3) will not boot without that flag.

Only set that flag if the partition type is gpt.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2632
2025-07-06 20:45:20 +02:00
Newbyte
89a80265de
pmb: Only disable metadata_csum for ext4 on downstream ports
No need to worsen filesystem reliability for mainline devices that don't
need this workaround.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2557

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2616
2025-07-06 19:15:21 +02:00
Pablo Correa Gómez
496d1b657d
Revert "install: openrc: fix installing alpine-base early"
This reverts commit 6eb8cab84d.

This is a problematic way to solve the issue. We want to eventually
allow people to migrate from openrc, and having alpine-base in the
world file is an issue. Moreover, a package that runs rc-update
and doesn't depend on openrc simply has a packaging bug. This is
something that is documented, and should be generally fixed
(https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/2097).
If we manage to detect more issues, we should fix them in packaging
instead, like with
https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6474

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2593
2025-05-05 21:58:17 +02:00
Oliver Smith
6eb8cab84d
install: openrc: fix installing alpine-base early
With recent changes we don't install alpine-base in the chroots anymore.
It still gets installed as postmarketos-base depends on it (for now,
this will change soon in master). But it is not guaranteed to be
installed before other packages which may run "rc-update" in their
postinst scripts.

Fix this by explicitly installing alpine-base early on during
"pmbootstrap install".

Fix for e.g. v24.12:pine64-pinephone:phosh images:

  (342/976) Installing eg25-manager-openrc (0.4.6-r5)
  (343/976) Installing device-pine64-pinephone-openrc (7-r0)
  Executing device-pine64-pinephone-openrc-7-r0.post-install
  lib/apk/exec/device-pine64-pinephone-openrc-7-r0.post-install: line 3: rc-update: not found
  ERROR: device-pine64-pinephone-openrc-7-r0.post-install: script exited with error 127

Related: https://builds.sr.ht/~postmarketos/job/1473669#task-img-743
Fixes: 12d125ab ("chroot: don't depende on alpine-base")

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2585
2025-04-18 10:38:34 +02:00
Anri Dellal
a80b27d0bd
install: Do not fail on invalid SSH key
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2576
2025-04-11 17:37:35 +02:00
Stephan Gerhold
e9038e50d6
pmb/install: Add option to create single combined boot/root partition
With recent rework in postmarketos-initramfs, we no longer need to mount
the /boot partition in the initramfs (assuming initramfs-extra is not
used). On devices that boot without accessing the boot file system (e.g.
Android boot images, fastboot, ...), that makes it possible to install
postmarketOS on a single (potentially encrypted) partition that contains
both root (/) and /boot files.

This avoids the extra complexity of the subpartition setup we usually use
on such devices, and also avoids having to flash two partitions (when using
--split to avoid the subpartitions).

Add a --single-partition option to pmbootstrap install that allows
installing postmarketOS in this mode. For now this is just an option that
must be selected explicitly, in the future we could choose to make this the
default for Android-based devices with a large enough boot partition.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2512
2025-04-11 17:35:20 +02:00
fossdd
745ee74138
pmb.install._install: install locale config on default lang aswell
Reduces complexity allows applications and users to have a single source
of truth without involving /etc/profile.d/..

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:29 +02:00
fossdd
50d2bb45f4
pmb.install._install: write lang configuration to /etc/locale.conf
Previous reasons to write the locales to /etc/profile.d/.. was because
musl-locales do only support reading from environment variables and not
/etc/locale.conf.

However systemd-localed (and glibc) uses /etc/locale.conf to read and
write locale configurations. gnome-control-center, for example, uses
localed to change locales.

In the sake of a single source of truth, allow pmb to write to
/etc/locale.conf and allow its consumers (e.g. g-c-c via systemd) to
read/change these variables.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:29 +02:00
fossdd
9656c53a6a
pmb.install._install: remove installation of lang
lang gets moved to `_pmb_recommends` of postmarketos-base-ui to allow
switching between languages on en_US devices

Closes: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/3314

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2547
2025-04-03 22:58:24 +02:00
Theresa Schönhammer
ca1f87b873
install: remove redundant package musl-locales
lang depends on musl-locales

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2579
2025-03-31 17:45:48 +02:00
Clayton Craft
561ff0dc4c
pmb.install.format: add support for setting FDE passphrase
This adds support for using an environment variable to set the FDE
passphrase, allowing us to automate image creation when using FDE.
The method used here was borrowed from how we set the password with when
using the --password arg: write to a temp file, call something in the
chroot to read/use it, then remove it.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2538
2025-03-14 09:45:04 -07:00
Oliver Smith
d90a037fd6
pmb.install.format: set bytes-per-inode to 16384 (MR 2558)
After setting "-T big", we still saw some images failing with "out of
space" errors in bpo, such as "v24.12:samsung-espresso10:xfce4".

I've looked at /etc/mke2fs.conf to figure out what exactly gets
configured with "-T big". What I did not realize is that the inode
ratio gets bigger by going from small -> big, big -> huge, but with a
larger ratio FEWER inodes will be created (see man mkfs.ext4, -i
bytes-per-inode).

In /etc/mke2fs.conf in Alpine edge:

	[defaults]
	…
		blocksize = 4096
		inode_size = 256
		inode_ratio = 16384

	[fs_types]
	…
		small = {
			blocksize = 1024
			inode_ratio = 4096
		}
		floppy = {
			blocksize = 1024
			inode_ratio = 8192
		}
		big = {
			inode_ratio = 32768
		}
		huge = {
			inode_ratio = 65536
		}
		news = {
			inode_ratio = 4096
		}
	…

So I've tried out half the ratio value we get with "big" now, 16384.
With that we finally seem to have:

* Enough inodes for small UIs (console, none) as well as big UIs with
  lots of files (xfce4, plasma-desktop, ...)

* We don't directly specify an inode count (-N) anymore as we did
  earlier, which had problems with small images as the inode count would
  be too large for the given image size (pmb#2572).

Test builds with various images:

Filesystem              Inodes      Used Available Use% Mounted on
master:postmarketos-trailblazer:none:
/dev/installp2           35440      5111     30329  14% /mnt/install
master:postmarketos-trailblazer:console:
/dev/installp2           47232      8713     38519  18% /mnt/install
master:pine64-pinebookpro:plasma-desktop:
/dev/installp2          276352    100607    175745  36% /mnt/install
v24.12:samsung-espresso10:xfce4:
/dev/installp2           80960     51150     29810  63% /mnt/install

So the most Use% I could get is 63% with this, leaving a nice margin for
the future.
2025-02-23 13:45:36 +01:00
Oliver Smith
06957b2173
install: log space/inodes used in image (MR 2558)
Log how well we have used the space and available inodes in the
resulting images, to show how well the mkfs parameters we have decided
on are working.
2025-02-23 13:45:32 +01:00
Stefan Hansson
bdcc188f05
pmb: Use explicit re-exports (MR 2545)
See https://docs.astral.sh/ruff/rules/unused-import
2025-02-23 11:40:44 +01:00
Oliver Smith
63fce4fcb5
pmb.install.format: set ext4 usage-type to big (MR 2555)
Using "-N" to set a specific inode count caused errors:
* With 100K, we got "out of space" errors when creating images for
  bigger UIs with many small files like:
  pine64-pinebookpro:plasma-desktop
* With 1M (current value), we got "out of space" for small images like:
  postmarketos-trailblazer:console

Use "-T big" instead to set the usage-type that is closest to how we
expect the filesystem to be used, once it is flashed to the user's
device and resized. This will indirectly set the bytes-per-inode. I've
verified that building both the big
pine64-pinebookpro:plasma-desktop and small
postmarketos-trailblazer:console (and even with UI=none) works with
this change.

I've verified that building both the small image works with this.

From the mkfs.ext4 man page:

       -T usage-type[,...]
              Specify how the file system is going to be used, so that mke2fs
              can choose optimal file system parameters for that use.  The
              usage types that are supported are defined in the configuration
              file /etc/mke2fs.conf.  The user may specify one or more usage
              types using a comma separated list.

              If this option is is not specified, mke2fs will pick a single
              default usage type based on the size of the file system to be
              created.  If the file system size is less than 3 megabytes,
              mke2fs will use the file system type floppy.  If the file system
              size is greater than or equal to 3 but less than 512 megabytes,
              mke2fs(8) will use the file system type small.  If the file
              system size is greater than or equal to 4 terabytes but less
              than 16 terabytes, mke2fs(8) will use the file system type big.
              If the file system size is greater than or equal to 16
              terabytes, mke2fs(8) will use the file system type huge.
              Otherwise, mke2fs(8) will use the default file system type
              default.

Fixes: d0d7c2d4 ("pmb.install.format: set ext4 usage-type to big")
Fixes: issue 2572
2025-02-19 19:49:17 +01:00
Oliver Smith
ffa58f402c
pmb.install.format: set ext4 inodes to 1M (MR 2552)
Make 10x the amount of inodes available for ext4 partitions when using
"pmbootstrap install" without the "--disk" argument so we won't run out
for sure. The previous value was not enough in some edge cases. We do
need to set this as the default is not enough either.

Fixes: issue 2568
2025-02-16 18:08:03 +01:00
Newbyte
70411ce3c4
pmb.install.losetup: Remove unnecessary range start (MR 2537)
See https://docs.astral.sh/ruff/rules/unnecessary-range-start
2025-02-02 22:48:50 +01:00
Newbyte
6415aea8af
pmb: Remove unnecessary pass statements (MR 2537)
See https://docs.astral.sh/ruff/rules/unnecessary-placeholder
2025-02-02 22:48:50 +01:00
SzczurekYT
b5f14e2b94
install: create_device_rootfs: check if ui extras package exists (MR 2534)
Don't try installing the ui -extras subpackage if the currently selected ui doesn't have one.
2025-01-28 11:41:33 +01:00
Newbyte
3061e702ab
pmb: Reformat with Ruff 0.9 (MR 2525)
See https://astral.sh/blog/ruff-v0.9.0
2025-01-15 22:35:02 +01:00
Newbyte
2be49f8caf
pmb.install: Remove unnecessary calls to round() (MR 2525)
These values are already integers, so calling round() on them is
effectively a no-op.
2025-01-15 22:35:02 +01:00
Newbyte
c797b30dfe
pmb: Use unpacking operator to concatenate collections (MR 2525)
See https://docs.astral.sh/ruff/rules/collection-literal-concatenation

This is also slightly faster according to a microbenchmark that
shows it taking around 19% less time to run:
https://github.com/astral-sh/ruff/pull/1957#issue-1538092351
2025-01-15 22:35:02 +01:00
Oliver Smith
3f9f1c96c1
install: support systemd for disabling services (MR 2529)
Write a preset file and run "systemctl preset" afterwards:

    % sh -c echo 'disable sshd.service' > /usr/lib/systemd/system-preset/80-pmbootstrap-install-disable-sshd.preset
    % systemctl preset sshd.service
    % systemctl is-enabled sshd.service
    disabled
2025-01-12 15:33:02 +01:00
Oliver Smith
786c62767e
install: merge disable_sshd(), disable_firewall() (MR 2529)
These functions are identical, except for the service name. Merge them
in preparation to add systemd support.
2025-01-12 15:33:02 +01:00
Robert Eckelmann
a2f177433f
Cosmetic: pmb/install/_install.py: tweak strings (MR 2529)
Merge strings that have a break in the same line. These were generated
when running "ruff format" initially.

Old:
  logging.info("Firewall is not supported in checked out pmaports" " branch.")
New:
  logging.info("Firewall is not supported in checked out pmaports branch.")

Signed-off-by: Robert Eckelmann <longnoserob@postmarketos.org>
Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
2025-01-12 15:32:57 +01:00
Newbyte
510469b304
pmb.config.pmaports: Get rid of cast hack for SectionProxy (MR 2519)
For some reason this also requires a fix in pmb.install._install.py,
didn't bother investigating why but the necessary change seems fine to
me.

Requires mypy 1.14 (maybe 1.14.1, not sure).
2025-01-02 14:17:55 +01:00
Newbyte
5ed5817e80
pmb: Add more type hints (MR 2490) 2024-12-19 10:09:22 +00:00
Anri Dellal
c831302a57
pmb.install._install: add setup_locale() (MR 2497)
Moves locale setup code to separate function
Adds code to install keyboard configuration based on chosen locale
2024-12-03 13:17:15 +01:00
Newbyte
472726a9dc
pmb: Add more type hints (MR 2489) 2024-11-14 23:16:29 +01:00
Dominik Bayerl
87515529cf
pmbootstrap: run partprobe after repartitioning (MR 2473)
On some kernels (notably, WSL2) parted fails to inform the kernel
about the new partition layout, leading to errors when trying to
create the new filesystems.

This change runs an additional `partprobe` after updating the
partition table, informing the kernel about the new layout.

Fixes: #2422
Signed-off-by: Dominik Bayerl <dominik.bayerl@carissma.eu>
[caleb: move call so it runs after partition_cgpt() as well]
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-04 08:09:37 +01:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
d05d57b37e
pmb.install.recovery: Assert that partitions are not None (MR 2464)
They should definitely not be None here, thus assert it so we don't need
to keep checking for None later.
2024-10-29 23:08:37 +01:00
Newbyte
b49da9ad82
pmb.install.recovery: Check for None before going through blacklist (MR 2464)
It doesn't really make sense to check the blacklist against None, so
just skip the value if it's None. Appeases mypy.
2024-10-29 23:08:37 +01:00
Newbyte
8bc848fa77
pmb.install._install: Use bool(...) when figuring out whether to use cgpt (MR 2464)
Otherwise, if pmb.parse.deviceinfo().cgpt_kpart is an empty string, for
example, we end up passing an empty string to get_partition_layout()
instead of False.
2024-10-29 23:08:37 +01:00
Newbyte
b0526128fe
pmb.install._install: Round root size to nearest int in get_subpartitions_size() (MR 2464)
This makes the behaviour match the docstring which specifies that this
function returns integers.
2024-10-29 23:08:36 +01:00
Newbyte
1aa0b05014
pmb.install.blockdevice: Avoid reusing size_mb variable in create_and_mount_image() (MR 2464)
Reusing this variable might lead to confusing bugs later if this code is
changed in the future, and also leads to mypy being confused about the
type of size_mb as it then gets assigned both str and int values.
2024-10-29 14:21:01 +01:00
Vikram Alagh
8ac2e48a21
install: losetup: check if the back-file attribute for a loop device is null (MR 2456)
Seems to be ChromeOS specific:

> this happens every time on my machine. I am on ChromeOS 129.0.6668.112
> using a Debian bookworm chroot through Crouton. I am not sure why
> this is happening nor which layer is responsible for this. I deleted
> the chroot and created another one but the problem persists.

Commit msg tweaked by Oliver.
2024-10-27 16:03:17 +01:00
Newbyte
3c47a52f91
pmb.install.losetup: Remove debug print (MR 2450)
Looks like an unintended leftover from debugging.

---

This was needlessly reverted by
1ec55fc11a. While revreting
0975d06437 was good, this commit did not
cause any harm.
2024-10-27 13:14:11 +01:00
Newbyte
bbf20a030b
pmb.install.losetup: Annotate return types (MR 2430) (MR 2450)
And fix type errors.

---

This was needlessly reverted by
1ec55fc11a. While revreting
0975d06437 was good, this commit did not
cause any harm.
2024-10-27 13:14:11 +01:00
Newbyte
37ec73c07c
pmb.flasher: Remove use of args (MR 2441)
Also adapt pmb/install/recovery.py to new API for variables.py.

[ci:skip-build]: already built successfully in CI
2024-10-22 15:12:40 +02:00
Clayton Craft
47dc493701
pmb.parse.depends.package_provider: add type hinting and fix references (MR 2439)
pmb.parse.apkindex.providers now returns a dict of string:ApkindexBlock,
probably from 71772b9b6

This adds type hinting to package_provider to reflect this, and fixes
code that calls it to properly deal with the possible return types.
Without this, building FDE images is broken.
2024-10-18 13:45:57 +02:00
Clayton Craft
1ec55fc11a
Revert "pmb.install.losetup: Run kpartx, losetup in chroot (MR 2430)"
This series breaks pmbootstrap, and that's not good[1]. A bug was filed
about this (#2465), and there have been multiple attempts to fix it (!
2435 and !2436). It kinda seems like we don't have time to fix/test this
for a while longer, which is fine, but given the impact this bug has I
think we should be revert this series until this issue is solved/tested.

1. pmb is broken in some specific cases, which means some workflows are
broken. One example is that this breaks the pmaports CI, so no work can
be done in pmaports.
2024-10-16 11:35:36 -07:00
Newbyte
a7e2592f1a
pmb.install.losetup: Remove debug print (MR 2430)
Looks like an unintended leftover from debugging.
2024-10-16 00:07:48 +02:00
Newbyte
0975d06437
pmb.install.losetup: Run kpartx, losetup in chroot (MR 2430)
I tested $ pmbootstrap shutdown with this and observed no problems. All
the mounts disappear in lsblk as expected.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2423
2024-10-16 00:07:48 +02:00
Newbyte
6455441464
pmb.install.losetup: Annotate return types (MR 2430)
And fix type errors.
2024-10-16 00:07:44 +02:00
Stefan Hansson
71772b9b6b
pmb.parse.apkindex: Introduce proper typing (MR 2425)
And adjust other code.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2455
2024-10-13 20:12:34 +02:00
Aster Boese
8335d050bf
pmb.install: switch to gpt with discoverable partitions (MR 2426) 2024-10-13 19:59:26 +02:00