Compare commits

..
Author SHA1 Message Date
Caleb Connolly e8aa17ab53 main/bootrr: new aport
bootrr is a basic sanity checker for automated testing. It ensures that
the correct drivers are loaded and devices are available for the running
board.
2023-07-23 20:55:23 +01:00
Caleb Connolly b3160693f4 postmarketos-mkinitfs-hook-kernelmodules: new aport
This hook is used to copy newer kernel modules that are included in the
ramdisk into the rootfs during boot. Effectively allowing for new
kernels that have been built in CI to be "installed" seamlessly on
Android devices by just flashing/booting a new boot image.

This is intended for use in CI or for local kernel development.
2023-07-23 20:55:22 +01:00
Caleb Connolly 9a59740886 postmarketos-initramfs: add sysroot hooks
Add another hook stage for hooks that need to run after the root
partition is mounted. Simply use /hook/sysroot for these.
2023-07-23 20:55:22 +01:00
Clayton Craft a038eb7316 main/postmarketos-initramfs: use only one method to resize the root partition
This removes the possibility that multiple resize root partition methods
could be invoked. I'm not sure how likely this is in practice, but it
seems like we should avoid the possiblity altogether.

This also adds some more helpful printing to stdout when the partition
resize is skipped / not done.
2023-07-23 20:31:47 +01:00
Caleb Connolly 5ec6b0bb38 main/postmarketos-initramfs: fixup device-mapper paths
findfs might produce a block device path like /dev/dm-3, these can
change across boots and devices. Make things more readable and
consistent by mapping from the /dev/dm-* path to the equivalent
/dev/mapper/xyz path. Combined with invoking kpartx from a
/dev/disk/by-partlabel/abc symlink, this results in the final block
device having a name like /dev/mapper/userdata2 on an Android device.

Whilst this is just nicer to work with, this will be especially useful for
the upcoming ondev2 postmarketOS installer to make device-specific
configuration and detection easier.
2023-07-23 20:25:22 +01:00
Caleb Connolly 05676d6c75 main/postmarketos-initramfs: optimise find_*_partition
Save the root/boot partition paths once found, and optimise a few loops.
2023-07-23 20:25:00 +01:00
Caleb Connolly 0e4c6271a4 main/postmarketos-initramfs: use mdev properly
Drop in mdev.conf and the /lib/mdev/persistent-storage script, these
cause /dev/disk/by-* to be populated in the ramdisk, making it
possible to do look up partition by-label and by-partlabel for free,
compared to findfs which can take some time.

As a first optimisation based on this, check for some partitions using
these paths and prioritise them when looking for subpartitions. Drop the
first find_boot_partition call as it doesn't really save time over the
call in the while loop.

The mdev config also handles setting up /dev/null, /dev/random, etc, so
these don't have to be done manually.
2023-07-23 20:25:00 +01:00
Caleb Connolly f9dc29175b main/postmarketos-initramfs: rework logging
Make logs always go to kmsg, so that if you have a console configured
then you'll always be able to see the init script output. The
behaviour of PMOS_NO_OUTPUT_REDIRECT is adjusted so that it just
decides whether or not openrc will log to the console or not.

The original stdout/stderr fds are preserved and later restored, this is
important for debug-shell to run on the TTY.
2023-07-23 20:25:00 +01:00
Caleb Connolly 29482ba162 main/postmarketos-initramfs: silence pbsplash 2023-07-23 20:19:15 +01:00
Caleb Connolly 225bb5b313 main/postmarketos-mkinitfs-hook-debug-shell: reconfigure logging
It's necessary to reconfigure the stdout/stderr streams before spawning
the debug shell, so that it will correctly launch a getty on the serial
console if available.
2023-07-23 20:19:14 +01:00
Luca Weiss df876eff36 main/postmarketos-initramfs: switch_root with /dev (MR 3230)
Mount /dev (and /run) in initramfs so util-linux switch_root can move
the mounts over to the new sysroot before changing root.
BusyBox switch_root doesn't even attempt to move anything so use
util-linux's switch_root for this.

Explicitly disable tests too...
2023-07-23 19:46:47 +01:00
10 changed files with 179 additions and 69 deletions

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
# Maintainer: Caleb Connolly <caleb@connolly.tech>
pkgname=bootrr
pkgver=0.1
_commit="6ac3e34d3471785621429ce39c3c3403a2da9820"
pkgrel=0
pkgdesc="A sanity checker for boards under automated test"
url="https://github.com/andersson/bootrr"
arch="noarch"
license="BSD-3-Clause"
source="
bootrr-$_commit.tar.gz::https://github.com/andersson/bootrr/archive/$_commit.tar.gz
"
builddir="$srcdir/bootrr-$_commit"
options="!check"
build() {
make prefix=/usr all
}
package() {
make prefix=/usr DESTDIR="$pkgdir" install
}
sha512sums="
65872ca5875439dd165648a9f2711f9d557ef1058be9f90c927c8364d732f06d98d302eb5d6d2c3c222005f6d4f39e0e85d31711149ac4e1b972a56f71cec8f2 bootrr-6ac3e34d3471785621429ce39c3c3403a2da9820.tar.gz
"
@@ -2,6 +2,11 @@
/bin/busybox-extras
/bin/sh
/etc/deviceinfo
/etc/mdev.conf
/etc/group
/etc/passwd
/lib/mdev/persistent-storage
/sbin/blkid
/usr/share/misc/source_deviceinfo
/usr/bin/unudhcpd
/usr/sbin/kpartx
+4 -4
View File
@@ -1,7 +1,7 @@
# Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=postmarketos-initramfs
pkgver=1.3.0
pkgver=1.4.2
pkgrel=0
pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
url="https://postmarketos.org"
@@ -68,8 +68,8 @@ package() {
sha512sums="
bed319179bcd0b894d6267c7e73f2890db07bc07df71542936947dfb3bdb17fade8a7b4e7b577f278af4472464427bba07f75aff0a1e454a4167052c088f3b6a 00-default.modules
5b364300f31c91fd0591eb0715f67cbf5383f45246a5fb9f34b79f7cb2e3b15768b2130e5f32f816cc169950f988c1beabc879ba31645c58ce131a288dbc071d 00-initramfs-base.dirs
3bc73f3a0d1de210444d9c45fab51fd4520e38b43ffbb76368f8ff854b990aa2f21c6356840c5a48eb9808e834eb885a6d581639a60707c26abf66fc20b70db9 00-initramfs-base.files
77ee384c6b4a74f5c8cc901cebcfca1a60c98885354582ad18d932ae2736376ccd408a0e711f6ac5f043f63194d17b01119e736b8dddec96034cf4ec9e93c341 00-initramfs-base.files
8a4adad3785af474b36a09a05f6a3b2c4b4f43aac331a53b903abfa51ea12be1e3d1d807b7a6e66a1346815f3b0044daf8cd62e21e2dc75d2db13ee265a72985 00-initramfs-extra-base.files
911f1b9becbcd25a0f96a7c0b96c1add920d7e50a041719f2947c13729c543fa87e4332ae329ad8f74a7dabd53e5ed56a6f3bba89f2275587bf9f970fd652989 init.sh
71442e33dbb81f4aa8220838a52af6033b453e9010f40109f91775f1b0d19a5738fff1329397eaa05ab42edcc80fe9d335700cfeab0366901f6560e5963d4ea7 init_functions.sh
40a061b240d9e2d0668e559c74c5386ba7f021b342fccda377bff6bf5754b6ad740816dc997cc8307298890e22cfd8ddec9854fb5376b4835ba9efa226495fa6 init.sh
405c049d5bb1a09152c786036e9d755772ec376683d09c53b35f4f5ca36990518b86f7791e84801a2ce2166774092f46faf2129eb4e0d377785c22447fc43e45 init_functions.sh
"
+2 -1
View File
@@ -12,7 +12,6 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# Mount everything, set up logging, modules, mdev
mount_proc_sys_dev
create_device_nodes
setup_log
setup_firmware_path
# shellcheck disable=SC2154
@@ -42,6 +41,7 @@ resize_root_partition
unlock_root_partition
resize_root_filesystem
mount_root_partition
run_hooks /hooks/sysroot
# Mount boot partition into sysroot, so OpenRC doesn't need to do it (#664)
umount /boot
@@ -52,6 +52,7 @@ setup_bootchart2
# Switch root
killall telnetd mdev udevd msm-fb-refresher 2>/dev/null
reconfigure_logging ""
# shellcheck disable=SC2093
exec switch_root /sysroot "$init"
+102 -62
View File
@@ -3,23 +3,37 @@
IP=172.16.42.1
ROOT_PARTITION_UNLOCKED=0
ROOT_PARTITION_RESIZED=0
PMOS_BOOT=""
PMOS_ROOT=""
# Redirect stdout and stderr to logfile
setup_log() {
# Bail out if PMOS_NO_OUTPUT_REDIRECT is set
echo "### postmarketOS initramfs ###"
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && return
# Save stdout/stderr for later
exec 6>&1
exec 7>&2
# Redirects all output to a subshell which prepends "PMOS: " to each line
# and then pipes to the logfile and the kernel logbuffer.
# shellcheck disable=SC3001
exec > >(awk '$0="PMOS: "$0' - | tee -a /pmOS_init.log /dev/kmsg >/dev/null)
exec 2>&1
# Print a message about what is going on to the normal output
echo "NOTE: All output from the initramfs gets redirected to:"
echo "/pmOS_init.log"
echo "If you want to disable this behavior (e.g. because you're"
echo "debugging over serial), please add this to your kernel"
echo "command line: PMOS_NO_OUTPUT_REDIRECT"
# Start redirect, print the first line again
exec >/pmOS_init.log 2>&1
echo "### postmarketOS initramfs ###"
echo "NOTE: All output from the initramfs gets redirected to"
echo "the kernel log buffer (dmesg) and /pmOS_init.log in the ramdisk"
}
# Reconfigure logging before switch_root
reconfigure_logging() {
echo "Reconfiguring stdout/stderr $1"
# For debugging, allow logging to the console
if [ -n "$1" ] || grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline; then
exec 1>&6 6>&-
exec 2>&7 7>&-
return
fi
# Pipe to /dev/null and delete the original stdout/stderr
exec >/dev/null 6>&-
exec 2>/dev/null 7>&-
}
mount_proc_sys_dev() {
@@ -35,12 +49,12 @@ mount_proc_sys_dev() {
# /dev/pts (needed for telnet)
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
}
create_device_nodes() {
mknod -m 666 /dev/null c 1 3
mknod -m 644 /dev/random c 1 8
mknod -m 644 /dev/urandom c 1 9
# Set up fd symlinks for I/O redirects
ln -s /proc/self/fd /dev/fd
ln -sf /proc/self/fd/0 /dev/stdin
ln -sf /proc/self/fd/1 /dev/stdout
ln -sf /proc/self/fd/2 /dev/stderr
}
setup_firmware_path() {
@@ -111,16 +125,19 @@ setup_dynamic_partitions() {
}
mount_subpartitions() {
# Do not create subpartition mappings if pmOS_boot
# already exists (e.g. installed on an sdcard)
[ -n "$(find_boot_partition)" ] && return
try_parts="/dev/disk/by-partlabel/userdata /dev/disk/by-partlabel/system* /dev/mapper/system*"
android_parts=""
for x in $try_parts; do
[ -e "$x" ] && android_parts="$android_parts $x"
done
attempt_start=$(get_uptime_seconds)
wait_seconds=10
echo "Trying to mount subpartitions for $wait_seconds seconds..."
while [ -z "$(find_boot_partition)" ]; do
partitions="$(grep -v "loop\|ram" < /proc/diskstats |\
partitions="$android_parts $(grep -v "loop\|ram" < /proc/diskstats |\
sed 's/\(\s\+[0-9]\+\)\+\s\+//;s/ .*//;s/^/\/dev\//')"
echo "$partitions" | while read -r partition; do
for partition in $partitions; do
case "$(kpartx -l "$partition" 2>/dev/null | wc -l)" in
2)
echo "Mount subpartitions of $partition"
@@ -147,7 +164,22 @@ mount_subpartitions() {
done
}
# Rewrite /dev/dm-X paths to /dev/mapper/...
pretty_dm_path() {
dm="$1"
n="${dm#/dev/dm-}"
# If the substitution didn't do anything, then we're done
[ "$n" = "$dm" ] && echo "$dm" && return
# Get the name of the device mapper device
name="/dev/mapper/$(cat "/sys/class/block/dm-${n}/dm/name")"
echo "$name"
}
find_root_partition() {
[ -n "$PMOS_ROOT" ] && echo "$PMOS_ROOT" && return
# The partition layout is one of the following:
# a) boot, root partitions on sdcard
# b) boot, root partition on the "system" partition (which has its
@@ -161,13 +193,14 @@ find_root_partition() {
# shellcheck disable=SC2013
if [ "$ROOT_PARTITION_UNLOCKED" = 0 ]; then
for x in $(cat /proc/cmdline); do
[ "$x" = "${x#pmos_root_uuid=}" ] && continue
DEVICE="$(findfs UUID="${x#pmos_root_uuid=}")"
done
for x in $(cat /proc/cmdline); do
[ "$x" = "${x#pmos_root=}" ] && continue
DEVICE="${x#pmos_root=}"
if ! [ "$x" = "${x#pmos_root_uuid=}" ]; then
PMOS_ROOT="$(findfs UUID="${x#pmos_root_uuid=}")"
break
fi
if ! [ "$x" = "${x#pmos_root=}" ]; then
PMOS_ROOT="${x#pmos_root=}"
break
fi
done
# On-device installer: before postmarketOS is installed,
@@ -178,61 +211,61 @@ find_root_partition() {
# p2: (reserved space) <--- pmos_root
# p3: pmOS_install
# Details: https://postmarketos.org/on-device-installer
if [ -n "$DEVICE" ]; then
next="$(echo "$DEVICE" | sed 's/2$/3/')"
if [ -n "$PMOS_ROOT" ]; then
next="$(echo "$PMOS_ROOT" | sed 's/2$/3/')"
# If the next partition is labeled pmOS_install (and
# not pmOS_deleteme), then postmarketOS is not
# installed yet.
if blkid | grep "$next" | grep -q pmOS_install; then
DEVICE="$next"
PMOS_ROOT="$next"
fi
fi
fi
# Try partitions in /dev/mapper and /dev/dm-* first
if [ -z "$DEVICE" ]; then
for id in pmOS_install pmOS_root crypto_LUKS; do
for path in /dev/mapper /dev/dm; do
DEVICE="$(blkid | grep "$path" | grep "$id" \
| cut -d ":" -f 1 | head -n 1)"
[ -z "$DEVICE" ] || break 2
done
done
fi
[ -n "$PMOS_ROOT" ] && echo "$PMOS_ROOT" && return
# Then try all devices
if [ -z "$DEVICE" ]; then
for id in pmOS_install pmOS_root crypto_LUKS; do
DEVICE="$(blkid | grep "$id" | cut -d ":" -f 1 \
| head -n 1)"
[ -z "$DEVICE" ] || break
done
fi
echo "$DEVICE"
for id in pmOS_install pmOS_root crypto_LUKS; do
PMOS_ROOT="$(findfs LABEL="$id")"
[ -n "$PMOS_ROOT" ] && break
done
PMOS_ROOT=$(pretty_dm_path "$PMOS_ROOT")
echo "$PMOS_ROOT"
}
find_boot_partition() {
[ -n "$PMOS_BOOT" ] && echo "$PMOS_BOOT" && return
# shellcheck disable=SC2013
for x in $(cat /proc/cmdline); do
[ "$x" = "${x#pmos_boot_uuid=}" ] && continue
findfs UUID="${x#pmos_boot_uuid=}"
path="/dev/disk/by-uuid/${x#pmos_boot_uuid=}"
[ -e "$path" ] && PMOS_BOOT="$path" && echo "$path"
return
done
# shellcheck disable=SC2013
for x in $(cat /proc/cmdline); do
[ "$x" = "${x#pmos_boot=}" ] && continue
echo "${x#pmos_boot=}"
path="${x#pmos_boot=}"
[ -e "$path" ] && PMOS_BOOT="$path" && echo "$path"
return
done
# * "pmOS_i_boot" installer boot partition (fits 11 chars for fat32)
# * "pmOS_inst_boot" old installer boot partition (backwards compat)
# * "pmOS_boot" boot partition after installation
findfs LABEL="pmOS_i_boot" \
|| findfs LABEL="pmOS_inst_boot" \
|| findfs LABEL="pmOS_boot"
for p in pmOS_i_boot pmOS_inst_boot pmOS_boot; do
PMOS_BOOT="$(findfs LABEL="$p")"
[ -n "$PMOS_BOOT" ] && break
done
# If we didn't find it, then we're done
[ -z "$PMOS_BOOT" ] && return
PMOS_BOOT=$(pretty_dm_path "$PMOS_BOOT")
echo "$PMOS_BOOT"
}
get_partition_type() {
@@ -351,22 +384,24 @@ resize_root_partition() {
parted -f -s "$partition_dev" resizepart 2 100%
kpartx -afs "$partition_dev"
ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi
fi
# Resize the root partition (non-subpartitions). Usually we do not want
# this, except for QEMU devices and non-android devices (e.g.
# PinePhone). For them, it is fine to use the whole storage device and
# so we pass PMOS_FORCE_PARTITION_RESIZE as kernel parameter.
if grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
elif grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
partition_dev="$(echo "$partition" | sed -E 's/p?2$//')"
if has_unallocated_space "$partition_dev"; then
echo "Resize root partition ($partition)"
parted -f -s "$partition_dev" resizepart 2 100%
partprobe
ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi
fi
# Resize the root partition (non-subpartitions) on Chrome OS devices.
# Match $deviceinfo_cgpt_kpart not being empty instead of cmdline
@@ -374,14 +409,19 @@ resize_root_partition() {
# partitioning methods. This also resizes third partition instead of
# second, because these devices have an additional kernel partition
# at the start.
if [ -n "$deviceinfo_cgpt_kpart" ]; then
elif [ -n "$deviceinfo_cgpt_kpart" ]; then
partition_dev="$(echo "$partition" | sed -E 's/p?3$//')"
if has_unallocated_space "$partition_dev"; then
echo "Resize root partition ($partition)"
parted -f -s "$partition_dev" resizepart 3 100%
partprobe
ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi
else
echo "Unable to resize root partition: failed to find qualifying partition"
fi
}
@@ -625,7 +665,7 @@ show_splash() {
# shellcheck disable=SC2154,SC2059
/usr/bin/pbsplash -s /usr/share/pbsplash/pmos-logo-text.svg \
-b "Linux $(uname -r) | $deviceinfo_codename" \
-m "$(printf "$1")" &
-m "$(printf "$1")" >/dev/null &
}
set_framebuffer_mode() {
@@ -57,6 +57,8 @@ echo "This is a security hole! Only use it for debugging, and"
echo "uninstall the debug-shell hook afterwards!"
echo "---"
reconfigure_logging "for debug-shell"
if tty -s; then
echo "Exit the shell to continue booting:"
pmos_shell
@@ -1,5 +1,5 @@
pkgname=postmarketos-mkinitfs-hook-debug-shell
pkgver=0.4.5
pkgver=0.4.6
pkgrel=0
pkgdesc="Root shell in the initramfs (security hole, for debugging only)"
url="https://postmarketos.org"
@@ -17,6 +17,6 @@ package() {
}
sha512sums="
90829cc17d62932730720d6a4d205c9e0093303f6d09865a4d4e83e08677cf4005cf38b02cde546082d60cf97264ddf60b4d76893d0f87e3bda4729bc04a171a 20-debug-shell.sh
c4042dd9d9f9d7d604bfd39016e626e22af898e3ba48beed9d5a50aa62571412c510aec90b16b218938f85df1f09caf7d955c6b9c8e893959242fd9007c9264b 20-debug-shell.sh
845d2eb6ab72c5c1472d65305241ca21dbc26784684e9ae99a180a255f8f7f62123b363d73c642df1f9687106340078311a68a76c123f16829b941bff9151735 20-debug-shell.files
"
@@ -0,0 +1,26 @@
# Maintainer: Caleb Connolly <caleb@connolly.tech>
pkgname=postmarketos-mkinitfs-hook-kernelmodules
pkgver=1.0.0
pkgrel=0
pkgdesc="Includes all kernel modules in the initramfs and bind-mounts /lib/modules during boot"
url="https://postmarketos.org"
arch="noarch"
license="GPL-2.0-or-later"
options="!check" # No tests
source="
install_kernel.sh
lib_modules.files
"
builddir="$srcdir/"
package() {
install -Dm644 "$srcdir"/install_kernel.sh \
"$pkgdir"/usr/share/mkinitfs/hooks/sysroot/10-install_kernel.sh
install -Dm644 "$srcdir"/lib_modules.files \
"$pkgdir"/usr/share/mkinitfs/files/lib_modules.files
}
sha512sums="
97d3e08415b3ee1425555d5fd11e123e4cbe9afff1624a1c28caa74c6592f9d29bb209693a3f42fef1a8f60d4373be0f9350ce8951ef462cea1faa3afcaac352 install_kernel.sh
36d7a7e727a41c4dc6390a77a0ef7a08b5d3d34d605881d7128e1bdd34c6704dc4fa7b7d03e3646fc2c569afc9ef16a2da3671ca995be3835620338ae3f5e882 lib_modules.files
"
@@ -0,0 +1,8 @@
#!/bin/sh
echo "Remounting /sysroot RW"
mount -o remount,rw /sysroot
echo "Installing kernel modules to sysroot"
cp -af /lib/modules/* /sysroot/lib/modules/
echo "All done!"
mount -o remount,ro /sysroot
@@ -0,0 +1,2 @@
/lib/modules/*
/usr/share/mkinitfs/hooks/sysroot/10-install_kernel.sh:/hooks/sysroot/10-install_kernel.sh