Compare commits

..
Author SHA1 Message Date
Luca Weiss 464244460d 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 20:00:58 +01:00
10 changed files with 68 additions and 178 deletions

No files matched your search

-26
View File
@@ -1,26 +0,0 @@
# 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,11 +2,6 @@
/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.4.2
pkgver=1.3.0
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
77ee384c6b4a74f5c8cc901cebcfca1a60c98885354582ad18d932ae2736376ccd408a0e711f6ac5f043f63194d17b01119e736b8dddec96034cf4ec9e93c341 00-initramfs-base.files
3bc73f3a0d1de210444d9c45fab51fd4520e38b43ffbb76368f8ff854b990aa2f21c6356840c5a48eb9808e834eb885a6d581639a60707c26abf66fc20b70db9 00-initramfs-base.files
8a4adad3785af474b36a09a05f6a3b2c4b4f43aac331a53b903abfa51ea12be1e3d1d807b7a6e66a1346815f3b0044daf8cd62e21e2dc75d2db13ee265a72985 00-initramfs-extra-base.files
40a061b240d9e2d0668e559c74c5386ba7f021b342fccda377bff6bf5754b6ad740816dc997cc8307298890e22cfd8ddec9854fb5376b4835ba9efa226495fa6 init.sh
405c049d5bb1a09152c786036e9d755772ec376683d09c53b35f4f5ca36990518b86f7791e84801a2ce2166774092f46faf2129eb4e0d377785c22447fc43e45 init_functions.sh
911f1b9becbcd25a0f96a7c0b96c1add920d7e50a041719f2947c13729c543fa87e4332ae329ad8f74a7dabd53e5ed56a6f3bba89f2275587bf9f970fd652989 init.sh
71442e33dbb81f4aa8220838a52af6033b453e9010f40109f91775f1b0d19a5738fff1329397eaa05ab42edcc80fe9d335700cfeab0366901f6560e5963d4ea7 init_functions.sh
"
+1 -2
View File
@@ -12,6 +12,7 @@ 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
@@ -41,7 +42,6 @@ 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,7 +52,6 @@ setup_bootchart2
# Switch root
killall telnetd mdev udevd msm-fb-refresher 2>/dev/null
reconfigure_logging ""
# shellcheck disable=SC2093
exec switch_root /sysroot "$init"
+61 -101
View File
@@ -3,37 +3,23 @@
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() {
# 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
# Bail out if PMOS_NO_OUTPUT_REDIRECT is set
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"
}
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && return
# 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
# 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"
# Pipe to /dev/null and delete the original stdout/stderr
exec >/dev/null 6>&-
exec 2>/dev/null 7>&-
# Start redirect, print the first line again
exec >/pmOS_init.log 2>&1
echo "### postmarketOS initramfs ###"
}
mount_proc_sys_dev() {
@@ -49,12 +35,12 @@ mount_proc_sys_dev() {
# /dev/pts (needed for telnet)
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
}
# 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
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
}
setup_firmware_path() {
@@ -125,19 +111,16 @@ setup_dynamic_partitions() {
}
mount_subpartitions() {
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
# Do not create subpartition mappings if pmOS_boot
# already exists (e.g. installed on an sdcard)
[ -n "$(find_boot_partition)" ] && return
attempt_start=$(get_uptime_seconds)
wait_seconds=10
echo "Trying to mount subpartitions for $wait_seconds seconds..."
while [ -z "$(find_boot_partition)" ]; do
partitions="$android_parts $(grep -v "loop\|ram" < /proc/diskstats |\
partitions="$(grep -v "loop\|ram" < /proc/diskstats |\
sed 's/\(\s\+[0-9]\+\)\+\s\+//;s/ .*//;s/^/\/dev\//')"
for partition in $partitions; do
echo "$partitions" | while read -r partition; do
case "$(kpartx -l "$partition" 2>/dev/null | wc -l)" in
2)
echo "Mount subpartitions of $partition"
@@ -164,22 +147,7 @@ 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
@@ -193,14 +161,13 @@ find_root_partition() {
# shellcheck disable=SC2013
if [ "$ROOT_PARTITION_UNLOCKED" = 0 ]; then
for x in $(cat /proc/cmdline); do
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
[ "$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=}"
done
# On-device installer: before postmarketOS is installed,
@@ -211,61 +178,61 @@ find_root_partition() {
# p2: (reserved space) <--- pmos_root
# p3: pmOS_install
# Details: https://postmarketos.org/on-device-installer
if [ -n "$PMOS_ROOT" ]; then
next="$(echo "$PMOS_ROOT" | sed 's/2$/3/')"
if [ -n "$DEVICE" ]; then
next="$(echo "$DEVICE" | 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
PMOS_ROOT="$next"
DEVICE="$next"
fi
fi
fi
[ -n "$PMOS_ROOT" ] && echo "$PMOS_ROOT" && return
# 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
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"
# 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"
}
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
path="/dev/disk/by-uuid/${x#pmos_boot_uuid=}"
[ -e "$path" ] && PMOS_BOOT="$path" && echo "$path"
findfs UUID="${x#pmos_boot_uuid=}"
return
done
# shellcheck disable=SC2013
for x in $(cat /proc/cmdline); do
[ "$x" = "${x#pmos_boot=}" ] && continue
path="${x#pmos_boot=}"
[ -e "$path" ] && PMOS_BOOT="$path" && echo "$path"
echo "${x#pmos_boot=}"
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
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"
findfs LABEL="pmOS_i_boot" \
|| findfs LABEL="pmOS_inst_boot" \
|| findfs LABEL="pmOS_boot"
}
get_partition_type() {
@@ -384,24 +351,22 @@ 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.
elif grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
if 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
@@ -409,19 +374,14 @@ resize_root_partition() {
# partitioning methods. This also resizes third partition instead of
# second, because these devices have an additional kernel partition
# at the start.
elif [ -n "$deviceinfo_cgpt_kpart" ]; then
if [ -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
}
@@ -665,7 +625,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")" >/dev/null &
-m "$(printf "$1")" &
}
set_framebuffer_mode() {
@@ -57,8 +57,6 @@ 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.6
pkgver=0.4.5
pkgrel=0
pkgdesc="Root shell in the initramfs (security hole, for debugging only)"
url="https://postmarketos.org"
@@ -17,6 +17,6 @@ package() {
}
sha512sums="
c4042dd9d9f9d7d604bfd39016e626e22af898e3ba48beed9d5a50aa62571412c510aec90b16b218938f85df1f09caf7d955c6b9c8e893959242fd9007c9264b 20-debug-shell.sh
90829cc17d62932730720d6a4d205c9e0093303f6d09865a4d4e83e08677cf4005cf38b02cde546082d60cf97264ddf60b4d76893d0f87e3bda4729bc04a171a 20-debug-shell.sh
845d2eb6ab72c5c1472d65305241ca21dbc26784684e9ae99a180a255f8f7f62123b363d73c642df1f9687106340078311a68a76c123f16829b941bff9151735 20-debug-shell.files
"
@@ -1,26 +0,0 @@
# 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
"
@@ -1,8 +0,0 @@
#!/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
@@ -1,2 +0,0 @@
/lib/modules/*
/usr/share/mkinitfs/hooks/sysroot/10-install_kernel.sh:/hooks/sysroot/10-install_kernel.sh