Add a dummmy version of pmaports for testing. This gives us much better
control and simplifies a lot of the logic.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
We don't always have an initramfs-extra anymore, implement the
deviceinfo check for this. Also ensure we init the chroot before trying
to use it.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
Put ourselves in a new PID namespace so that daemons we might start in
the chroot like adbd will be killed on exit.
This simplifies "shutdown" since we no longer need to kill these
processes.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
We don't need to bother unmounting stuff anymore since that will be
handled automatically when all processes in the namespace exit.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
Handle the case where cross compilation is not needed since
cross_compiler can still be called when not actually cross compiling.
Install gcc since kernel packages don't actually depend on it
explicitly.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
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>
We use a default boot partition offset of 2048 sectors, encode this into
the Deviceinfo type and handle converting to int so we don't have to do
it everywhere we use this.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
The on-device installer has been unsupported for a while, start removing
it from pmbootstrap to simplify the partitioning code, for example we no
longer need to support having some "reserved" space in the rootfs.
This follows various discussions which essentially indicated that future
on device installation methods will take a different approach which will
not require bespoke partitioning.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
These helpers could be used to run commands as root prior to unsharing
namespaces, for example to probe the binfmt module. They aren't used
currently but are left in just in case...
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
Rework how we handle binfmt_misc so it will work inside a user
namespace.
* Use a custom mountpoint (only accessible inside the mount namespace),
this is the crux of the change, allowing us to mount it as non-root
and avoid messing with any host configs too!
* No longer explicitly modprobe binfmt_misc, any modern system should
probe it automatically when we try to mount it... I think so anyways
heh
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
They might be symlinks in some quirky setups, we need the absolute paths
for bind mounts to work correctly.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This command spawns an interactive shell on your host but inside the
user and mount namespaces that pmbootstrap set up. It is mostly useful
for debugging issues with permissions, etc.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
Use sandbox functions to unshare the entire pmbootstrap process with
user namespaces.
This lets us do whatever we want without polluting the global mount
namepsace, and eliminates the need for "pmbootstrap shutdown".
Currently install is broken since it uses loop devices, this should be
addressed by using something like systemd.repartd (or doing all the
offset calculation and gpt stuff ourselves).
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
sandbox has some nice and clever function to set up /dev as a tmpfs
inside the chroot. Since we can't run mknod() in the user namespace it
bind mounts from the host instead.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
This really needs to be fixed up properly, basically we want to map
ourselves in as root, then support the groups <1000 (e.g. abuild uses
group id 300) and finally use our UID namespace (the biiig UIDs) for the
pmos user.
You need "USER:100000:65536" in your /etc/subuid and /etc/subgid files
where "USER" is your username.
This basically results in the chroot perms matching your user for root
and some freaky UIDs for the build user.
Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
Fix that pmbootstrap doesn't recognize v25.06 with systemd enabled as
valid channel and suggests switching to edge. This happens because
pmb.config.pmaports.read_config() unconditionally prepends "systemd-"
before the channel name if systemd is enabled, even though the init code
doesn't expect this.
The result is when running 'yes "" | pmbootstrap init' (as we do in BPO
and CI), pmbootstrap attempts to replace the correctly checked out
v25.06 branch with edge:
Fix for:
[20:36:37] Available (12):
[20:36:37] * edge: Rolling release / Most devices / Occasional breakage: https://postmarketos.org/edge
[20:36:37] * v25.06: Upcoming stable release (DO NOT USE)
[20:36:37] * v24.12: Latest release / Recommended for best stability
[20:36:37] Channel [edge]:
[20:36:37] Currently checked out branch 'v25.06' of pmaports.git is on channel 'v25.06'.
[20:36:37] Switching to branch 'master' on channel 'edge'...
…
ERROR: pmbootstrap switched to the wrong branch: master
Related: https://builds.sr.ht/~postmarketos/job/1497179#task-bpo_setup-23
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2613
Apparently python reads uname for this value, the correct value for
64-bit intel/amd stuff is `x86_64` even though python's docs list
`amd64` as an example of a value `platform.machine()` can return 🤷fixes#2612
[ci:skip-build]: already built successfully in CI