postmarketos-initramfs: unify with minimal initramfs (MR 5636)
We previously forked the initramfs into a minimal variant for highly space constrained devices, to allow the normal variant to gain additional functionality like the debug-shell (With OSK). Initially the hope was that only a handful of devices would need the minimal variant, but in practise this has not been the case. Trying to maintain two diverging forks of the initramfs is absoutely unsustainable and (to be frank) a bit silly. Based on discussion with craftyguy and newbyte, let's re-architect the initramfs to run in two stages, with the second stage being part of initramfs-extra. By itself this doesn't make a lot of sense, since requiring the boot partition be mounted for the debug-shell to be useful is a major downgrade. However this can be used in tandem with pending support for a new deviceinfo_create_initfs_extra variable, this is default false in mkinitfs which finally gets rid of initramfs-extra entirely for devices that don't need it. Signed-off-by: Caleb Connolly <caleb@postmarketos.org> Co-authored-by: Clayton Craft <clayton@craftyguy.net>
This commit is contained in:
parent
1a9eb8973e
commit
cb8414a20d
8 changed files with 362 additions and 207 deletions
|
|
@ -4,19 +4,10 @@
|
|||
/etc/deviceinfo
|
||||
/etc/unudhcpd.conf
|
||||
/sbin/blkid
|
||||
/usr/bin/iskey
|
||||
/sbin/modprobe
|
||||
/usr/bin/unudhcpd
|
||||
/usr/sbin/kpartx
|
||||
/usr/share/deviceinfo/deviceinfo
|
||||
/usr/share/initramfs/init.sh:/init
|
||||
/usr/share/initramfs/init_functions.sh:/init_functions.sh
|
||||
/usr/share/initramfs/init.sh:/init
|
||||
/usr/share/initramfs/mdev.conf:/etc/mdev.conf
|
||||
/usr/share/misc/source_deviceinfo
|
||||
/usr/bin/buffyboard
|
||||
/usr/share/consolefonts/ter-128n.psf.gz
|
||||
/usr/share/libinput/*.quirks
|
||||
/bin/udevadm
|
||||
/sbin/udevd
|
||||
/etc/udev/rules.d
|
||||
/usr/lib/udev/rules.d
|
||||
/usr/lib/udev/scsi_id
|
||||
|
|
|
|||
|
|
@ -1,9 +1,23 @@
|
|||
/bin/udevadm
|
||||
/etc/udev/rules.d
|
||||
/usr/lib/udev/rules.d
|
||||
/usr/lib/udev/scsi_id
|
||||
/sbin/btrfs
|
||||
/sbin/dmsetup
|
||||
/sbin/e2fsck
|
||||
/sbin/fsck.vfat
|
||||
# Full fat modprobe for compressed modules
|
||||
/sbin/modprobe
|
||||
/sbin/switch_root
|
||||
/sbin/udevd
|
||||
/usr/bin/buffyboard
|
||||
/usr/bin/iskey
|
||||
/usr/lib/libz.so.1
|
||||
/usr/sbin/fsck.f2fs
|
||||
/usr/sbin/parted
|
||||
/usr/sbin/resize.f2fs
|
||||
/usr/sbin/resize2fs
|
||||
/usr/share/consolefonts/ter-128n.psf.gz
|
||||
/usr/share/initramfs/init_2nd.sh:/init_2nd.sh
|
||||
/usr/share/initramfs/init_functions_2nd.sh:/init_functions_2nd.sh
|
||||
/usr/share/libinput/*.quirks
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# Maintainer: Caleb Connolly <caleb@postmarketos.org>
|
||||
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
|
||||
pkgname=postmarketos-initramfs
|
||||
pkgver=3.3.5
|
||||
pkgrel=3
|
||||
pkgver=3.4.0
|
||||
pkgrel=0
|
||||
pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
|
||||
url="https://postmarketos.org"
|
||||
options="!check" # no tests
|
||||
|
|
@ -42,6 +42,9 @@ source="
|
|||
00-initramfs-extra-base.files
|
||||
init.sh
|
||||
init_functions.sh
|
||||
init_2nd.sh
|
||||
init_functions_2nd.sh
|
||||
mdev.conf
|
||||
unudhcpd.conf
|
||||
"
|
||||
arch="noarch"
|
||||
|
|
@ -59,12 +62,22 @@ package() {
|
|||
install -Dm644 "$srcdir/unudhcpd.conf" \
|
||||
"$pkgdir/etc/unudhcpd.conf"
|
||||
|
||||
install -Dm644 "$srcdir"/mdev.conf \
|
||||
-t "$pkgdir"/usr/share/initramfs/
|
||||
|
||||
|
||||
install -Dm644 "$srcdir/init_functions.sh" \
|
||||
"$pkgdir/usr/share/initramfs/init_functions.sh"
|
||||
|
||||
install -Dm644 "$srcdir/init_functions_2nd.sh" \
|
||||
"$pkgdir/usr/share/initramfs/init_functions_2nd.sh"
|
||||
|
||||
install -Dm755 "$builddir/init.sh" \
|
||||
"$pkgdir/usr/share/initramfs/init.sh"
|
||||
|
||||
install -Dm755 "$srcdir/init_2nd.sh" \
|
||||
"$pkgdir/usr/share/initramfs/init_2nd.sh"
|
||||
|
||||
install -Dm644 "$srcdir"/00-initramfs-base.dirs \
|
||||
-t "$pkgdir"/usr/share/mkinitfs/dirs/
|
||||
mkdir -p "$pkgdir"/etc/mkinitfs/dirs
|
||||
|
|
@ -90,9 +103,12 @@ package() {
|
|||
sha512sums="
|
||||
20bc7a21f4f59548b8179c5cb1fc2b3db64eb355988bce992db3bc4075d65b4135ff9dd7d754215d0402978811494449cce476a26cda6bb2f0f8b53ae8e36bd7 00-default.modules
|
||||
9c0e8f6f61d5da191e03a1aa9d5d0ceb5baf1eae6dbb9bfb0af59817783525119ac8394b135f303f7b6434a3eab0b49185fb90379e06823db847a4999c75ce33 00-initramfs-base.dirs
|
||||
0f4c14b63ba22bbf6466f3b9b3c46e2a8cdd9f53600e3d5536288af1f37ae1b10efd0d038ed0669b3c128eb056758e7f1dbbcc6ef5768a27775776f8f11b2fdc 00-initramfs-base.files
|
||||
c4ce6c9ef5b1aa8fce0937676eb68f0172474cb86f2ab9d839f327b1c58f22ed6ae2a48133dd1c04ede33324ce82f78863f68ab6e62f88b716964b3b84f0ae9e 00-initramfs-extra-base.files
|
||||
7ea2c318e3b63b84ba8eb09e31dd74cdd9c86f5f4d8970ab54bb9213930e913c09728b60d429828007ea2dbb0472fd50dc3daae2efbe307babf854e4d8ecb238 init.sh
|
||||
6ccfbf84dd0315bfe2d9556ddfaaa2533ac4d1ab2055bb04e321cf945ae3ecbf6dc2c5e14a836cbc62f28da9eec1136a25d49764b330019bd04b918c8d36e6c6 init_functions.sh
|
||||
c0233d22858a5901db64e1d2fe1f6d39a2e2cfd1b94a10932483f55fed9461e9b8aa2d73b154b9d99a7a8b49ee02abfbddfe917ce0c6d7576601ba2668589c01 00-initramfs-base.files
|
||||
3db48f5db0e21ce2edb3192cbc8deeedf5f8d2bf2cba55cdb02ac30d5f4d6f640de06902f04eb9850ee08f7e302a750ea6fc0cb1c9118e7ec385858837680932 00-initramfs-extra-base.files
|
||||
e7f18ea6f5b7a60f07d7d0605a70f8e141dad524893570fa8502049ffa6f9d093fc80563f14be0a7fd64b6de14dede2806591488d08289c5308db8c2b04fa729 init.sh
|
||||
586517bf1b9c30b77342ba388f0a46beac72bb63b1f79ea6e8b62a6745991d7bdf6551d5f93f8f62eddd102adc0752cef4fd427549e2bb0dd2a9f6c2d65d11d5 init_functions.sh
|
||||
379cd465a1b18168f83b67c3d0033658f565262607ac34ecf8016ddfae89b644b71f267b04aaa6dea42fec92267af486d7f5ced8e6dfe9309ff00dd4cdb981ad init_2nd.sh
|
||||
d40d6472df8fd653b9fe2c8b9436fecd7dadf2f0d380c0931f97448bedb1f52c8872fe8fdb6aea45f8b52f5926ca20db97a0f2e99091422aedc1aa0a0b58bb03 init_functions_2nd.sh
|
||||
675e7d5bee39b2df7d322117f8dcaccc274d61beaf4d50ead19bbf2109446d64b1c0aa0c5b4f9846eb6c1c403418f28f6364eff4537ba41120fbfcbc484b7da7 mdev.conf
|
||||
ba3275a9af788c7c782322a22a0f144d5e50e3498ea6886486a29331f23ae89cd32d500a3635cfa7cab369afba92edc18aeca64ccbf0cd589061cce23d15b46c unudhcpd.conf
|
||||
"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Export all variables so they're available in /init_2nd.sh
|
||||
set -a
|
||||
|
||||
IN_CI="false"
|
||||
LOG_PREFIX="[pmOS-rd]"
|
||||
|
||||
|
|
@ -26,90 +29,43 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
|||
mount_proc_sys_dev
|
||||
setup_log
|
||||
setup_firmware_path
|
||||
modprobe libcomposite
|
||||
# Run udev early, before splash, to make sure any relevant display drivers are
|
||||
# loaded in time
|
||||
setup_udev
|
||||
|
||||
setup_usb_network
|
||||
start_unudhcpd
|
||||
|
||||
# Jump straight to the 2nd stage init if available
|
||||
# (no separate -extra) or no-op otherwise
|
||||
jump_init_2nd
|
||||
|
||||
echo "Loading initramfs-extra..."
|
||||
|
||||
# We need mdev to find the boot partition
|
||||
setup_mdev
|
||||
|
||||
if [ "$IN_CI" = "false" ]; then
|
||||
setup_framebuffer
|
||||
show_splash "Loading..."
|
||||
fi
|
||||
|
||||
setup_dynamic_partitions "${deviceinfo_super_partitions:=}"
|
||||
|
||||
run_hooks /hooks
|
||||
|
||||
if [ "$IN_CI" = "true" ]; then
|
||||
echo "PMOS: CI tests done, disabling console and looping forever"
|
||||
dmesg -n 1
|
||||
fail_halt_boot
|
||||
fi
|
||||
|
||||
setup_usb_network
|
||||
start_unudhcpd
|
||||
|
||||
if grep -q "pmos.debug-shell" /proc/cmdline; then
|
||||
debug_shell
|
||||
fi
|
||||
|
||||
check_keys
|
||||
load_modules /lib/modules/initramfs.load
|
||||
|
||||
# Discover the partitions if they're "subpartitions"
|
||||
# (where the whole disk image is flashed to a partition)
|
||||
mount_subpartitions
|
||||
|
||||
# Poll for the boot partition to become available or crash
|
||||
wait_boot_partition
|
||||
mount_boot_partition /boot
|
||||
extract_initramfs_extra /boot/initramfs-extra
|
||||
run_hooks /hooks-extra
|
||||
|
||||
wait_root_partition
|
||||
delete_old_install_partition
|
||||
resize_root_partition
|
||||
unlock_root_partition
|
||||
resize_root_filesystem
|
||||
mount_root_partition
|
||||
# Kill mdev, since it's replaced by udev in the
|
||||
# second stage init
|
||||
kill mdev 2>/dev/null
|
||||
|
||||
# Mount boot partition into sysroot, so we do not depend on /etc/fstab, as
|
||||
# not all old installations have a proper /etc/fstab file. See #2800
|
||||
umount /boot
|
||||
mount_boot_partition /sysroot/boot "rw"
|
||||
# Now we can jump to the 2nd stage init
|
||||
jump_init_2nd
|
||||
|
||||
init="/sbin/init"
|
||||
setup_bootchart2
|
||||
|
||||
# Switch root
|
||||
run_hooks /hooks-cleanup
|
||||
|
||||
echo "Switching root"
|
||||
|
||||
# Restore stdout and stderr to their original values if they
|
||||
# were stashed
|
||||
if [ -e "/proc/1/fd/3" ]; then
|
||||
exec 1>&3 2>&4
|
||||
elif ! grep -q "pmos.debug-shell" /proc/cmdline; then
|
||||
echo "$LOG_PREFIX Disabling console output again (use 'pmos.debug-shell' to keep it enabled)"
|
||||
exec >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Make it clear that we're at the end of the initramfs
|
||||
show_splash "Starting..."
|
||||
|
||||
# Re-enable kmsg ratelimiting (might have been disabled for logging)
|
||||
echo ratelimit > /proc/sys/kernel/printk_devkmsg
|
||||
|
||||
killall mdev udevd syslogd 2>/dev/null
|
||||
|
||||
# Kill any getty shells that might be running
|
||||
for pid in $(pidof sh); do
|
||||
if ! [ "$pid" = "1" ]; then
|
||||
kill -9 "$pid"
|
||||
fi
|
||||
done
|
||||
|
||||
# shellcheck disable=SC2093
|
||||
exec switch_root /sysroot "$init"
|
||||
|
||||
echo "$LOG_PREFIX ERROR: switch_root failed!" > /dev/kmsg
|
||||
echo "$LOG_PREFIX Looping forever. Install and use the debug-shell hook to debug this." > /dev/kmsg
|
||||
echo "$LOG_PREFIX For more information, see <https://postmarketos.org/debug-shell>" > /dev/kmsg
|
||||
# Somehow init_2nd.sh is missing
|
||||
echo "$LOG_PREFIX ERROR: /init_2nd.sh not found!"
|
||||
echo "$LOG_PREFIX For more information, see <https://postmarketos.org/debug-shell>"
|
||||
fail_halt_boot
|
||||
|
|
|
|||
96
main/postmarketos-initramfs/init_2nd.sh
Normal file
96
main/postmarketos-initramfs/init_2nd.sh
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# This is the "real" init.sh script, it's either jumped to immediately
|
||||
# from init.sh, or loaded from initramfs-extra on the boot partition
|
||||
# on space constrained devices with deviceinfo_create_initfs_extra="true".
|
||||
|
||||
# The set -a in init.sh only exports variables, not functions
|
||||
. /init_functions.sh
|
||||
. /init_functions_2nd.sh
|
||||
|
||||
# Run udev early, before splash, to make sure any relevant display drivers are
|
||||
# loaded in time
|
||||
setup_udev
|
||||
|
||||
# Splash is already running if we're loaded from initramfs-extra
|
||||
if [ "$deviceinfo_create_initfs_extra" != "true" ] && [ "$IN_CI" = "false" ]; then
|
||||
setup_framebuffer
|
||||
show_splash "Loading..."
|
||||
fi
|
||||
|
||||
setup_dynamic_partitions "${deviceinfo_super_partitions:=}"
|
||||
|
||||
run_hooks /hooks
|
||||
|
||||
if [ "$IN_CI" = "true" ]; then
|
||||
echo "PMOS: CI tests done, disabling console and looping forever"
|
||||
dmesg -n 1
|
||||
fail_halt_boot
|
||||
fi
|
||||
|
||||
if grep -q "pmos.debug-shell" /proc/cmdline; then
|
||||
debug_shell
|
||||
fi
|
||||
|
||||
check_keys
|
||||
|
||||
# If running from initramfs-extra this will be a no-op since it was
|
||||
# called before to mount the boot partition
|
||||
mount_subpartitions
|
||||
|
||||
run_hooks /hooks-extra
|
||||
|
||||
wait_root_partition
|
||||
delete_old_install_partition
|
||||
resize_root_partition
|
||||
unlock_root_partition
|
||||
resize_root_filesystem
|
||||
mount_root_partition
|
||||
|
||||
# Mount boot partition into sysroot if needed since some
|
||||
# old installations don't have a proper /etc/fstab file. See #2800
|
||||
if ! cat /sysroot/etc/fstab | grep -v "#" | grep -q "/boot" ; then
|
||||
wait_boot_partition
|
||||
mount_boot_partition /sysroot/boot "rw"
|
||||
fi
|
||||
|
||||
init="/sbin/init"
|
||||
setup_bootchart2
|
||||
|
||||
# Switch root
|
||||
run_hooks /hooks-cleanup
|
||||
|
||||
echo "Switching root"
|
||||
|
||||
# Restore stdout and stderr to their original values if they
|
||||
# were stashed
|
||||
if [ -e "/proc/1/fd/3" ]; then
|
||||
exec 1>&3 2>&4
|
||||
elif ! grep -q "pmos.debug-shell" /proc/cmdline; then
|
||||
echo "$LOG_PREFIX Disabling console output again (use 'pmos.debug-shell' to keep it enabled)"
|
||||
exec >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Make it clear that we're at the end of the initramfs
|
||||
show_splash "Starting..."
|
||||
|
||||
# Re-enable kmsg ratelimiting (might have been disabled for logging)
|
||||
echo ratelimit > /proc/sys/kernel/printk_devkmsg
|
||||
|
||||
killall udevd syslogd 2>/dev/null
|
||||
|
||||
# Kill any getty shells that might be running
|
||||
for pid in $(pidof sh); do
|
||||
if ! [ "$pid" = "1" ]; then
|
||||
kill -9 "$pid"
|
||||
fi
|
||||
done
|
||||
|
||||
# shellcheck disable=SC2093
|
||||
exec switch_root /sysroot "$init"
|
||||
|
||||
echo "$LOG_PREFIX ERROR: switch_root failed!" > /dev/kmsg
|
||||
echo "$LOG_PREFIX Looping forever. Install and use the debug-shell hook to debug this." > /dev/kmsg
|
||||
echo "$LOG_PREFIX For more information, see <https://postmarketos.org/debug-shell>" > /dev/kmsg
|
||||
fail_halt_boot
|
||||
|
|
@ -1,18 +1,22 @@
|
|||
#!/bin/sh
|
||||
# This file will be in /init_functions.sh inside the initramfs.
|
||||
ROOT_PARTITION_UNLOCKED=0
|
||||
ROOT_PARTITION_RESIZED=0
|
||||
PMOS_BOOT=""
|
||||
PMOS_ROOT=""
|
||||
SUBPARTITION_DEV=""
|
||||
|
||||
# NOTE!!! The file is sourced again in init_2nd.sh, avoid
|
||||
# clobbering variables by not setting them if they have
|
||||
# a value already!
|
||||
PMOS_BOOT="${PMOS_BOOT:-}"
|
||||
PMOS_ROOT="${PMOS_ROOT:-}"
|
||||
SUBPARTITION_DEV="${SUBPARTITION_DEV:-}"
|
||||
|
||||
CONFIGFS="/config/usb_gadget"
|
||||
CONFIGFS_ACM_FUNCTION="acm.usb0"
|
||||
HOST_IP="${unudhcpd_host_ip:-172.16.42.1}"
|
||||
|
||||
deviceinfo_getty=""
|
||||
deviceinfo_name=""
|
||||
deviceinfo_codename=""
|
||||
deviceinfo_getty="${deviceinfo_getty:-}"
|
||||
deviceinfo_name="${deviceinfo_name:-}"
|
||||
deviceinfo_codename="${deviceinfo_codename:-}"
|
||||
deviceinfo_create_initfs_extra="${deviceinfo_create_initfs_extra:-}"
|
||||
|
||||
# Redirect stdout and stderr to logfile
|
||||
setup_log() {
|
||||
|
|
@ -101,19 +105,32 @@ setup_firmware_path() {
|
|||
echo -n /lib/firmware/postmarketos >$SYS
|
||||
}
|
||||
|
||||
setup_udev() {
|
||||
if ! command -v udevd > /dev/null || ! command -v udevadm > /dev/null; then
|
||||
echo "ERROR: udev not found!"
|
||||
# shellcheck disable=SC3043
|
||||
load_modules() {
|
||||
local file="$1"
|
||||
local modules="$2"
|
||||
[ -f "$file" ] && modules="$modules $(grep -v ^\# "$file")"
|
||||
# shellcheck disable=SC2086
|
||||
modprobe -a $modules
|
||||
}
|
||||
|
||||
setup_mdev() {
|
||||
# Start mdev daemon
|
||||
mdev -d
|
||||
}
|
||||
|
||||
jump_init_2nd() {
|
||||
if ! [ -e /init_2nd.sh ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# This is the same series of steps performed by the udev,
|
||||
# udev-trigger and udev-settle RC services. See also:
|
||||
# - https://git.alpinelinux.org/aports/tree/main/eudev/setup-udev
|
||||
# - https://git.alpinelinux.org/aports/tree/main/udev-init-scripts/APKBUILD
|
||||
udevd -d --resolve-names=never
|
||||
udevadm trigger --type=devices --action=add
|
||||
udevadm settle
|
||||
local _reason="(Second stage already loaded)"
|
||||
if [ "$deviceinfo_create_initfs_extra" = "true" ]; then
|
||||
_reason="(Loaded initramfs-extra)"
|
||||
fi
|
||||
|
||||
echo "Jumping to /init_2nd.sh $_reason"
|
||||
exec /init_2nd.sh
|
||||
}
|
||||
|
||||
get_uptime_seconds() {
|
||||
|
|
@ -142,6 +159,10 @@ setup_dynamic_partitions() {
|
|||
}
|
||||
|
||||
mount_subpartitions() {
|
||||
# skip if ran already (unmerged -extra)
|
||||
if [ -n "$PMOS_ROOT" ] && [ -n "$PMOS_BOOT" ]; then
|
||||
return
|
||||
fi
|
||||
try_parts="/dev/disk/by-partlabel/userdata /dev/disk/by-partlabel/system* /dev/mapper/system*"
|
||||
android_parts=""
|
||||
for x in $try_parts; do
|
||||
|
|
@ -507,75 +528,6 @@ has_unallocated_space() {
|
|||
head -n1 | grep -qi "free space"
|
||||
}
|
||||
|
||||
resize_root_partition() {
|
||||
partition=$(find_root_partition)
|
||||
|
||||
# Do not resize the installer partition
|
||||
if [ "$(blkid --label pmOS_install)" = "$partition" ]; then
|
||||
echo "Resize root partition: skipped (on-device installer)"
|
||||
return
|
||||
fi
|
||||
|
||||
# Only resize the partition if it's inside the device-mapper, which means
|
||||
# that the partition is stored as a subpartition inside another one.
|
||||
# In this case we want to resize it to use all the unused space of the
|
||||
# external partition.
|
||||
if [ -z "${partition##"/dev/mapper/"*}" ] || [ -z "${partition##"/dev/dm-"*}" ]; then
|
||||
# Get physical device
|
||||
if [ -n "$SUBPARTITION_DEV" ]; then
|
||||
partition_dev="$SUBPARTITION_DEV"
|
||||
else
|
||||
partition_dev=$(dmsetup deps -o blkdevname "$partition" | \
|
||||
awk -F "[()]" '{print "/dev/"$2}')
|
||||
fi
|
||||
if has_unallocated_space "$partition_dev"; then
|
||||
echo "Resize root partition ($partition)"
|
||||
# unmount subpartition, resize and remount it
|
||||
kpartx -d "$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
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
# Resize the root partition (non-subpartitions) on Chrome OS devices.
|
||||
# Match $deviceinfo_cgpt_kpart not being empty instead of cmdline
|
||||
# because it does not make sense here as all these devices use the same
|
||||
# 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
|
||||
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
|
||||
}
|
||||
|
||||
unlock_root_partition() {
|
||||
command -v cryptsetup >/dev/null || return
|
||||
partition="$(find_root_partition)"
|
||||
|
|
@ -594,38 +546,6 @@ unlock_root_partition() {
|
|||
fi
|
||||
}
|
||||
|
||||
resize_root_filesystem() {
|
||||
if [ "$ROOT_PARTITION_RESIZED" = 1 ]; then
|
||||
show_splash "Resizing filesystem during initial boot..."
|
||||
partition="$(find_root_partition)"
|
||||
touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323
|
||||
type="$(get_partition_type "$partition")"
|
||||
case "$type" in
|
||||
ext4)
|
||||
echo "Resize 'ext4' root filesystem ($partition)"
|
||||
modprobe ext4
|
||||
resize2fs -f "$partition"
|
||||
;;
|
||||
f2fs)
|
||||
echo "Resize 'f2fs' root filesystem ($partition)"
|
||||
modprobe f2fs
|
||||
resize.f2fs "$partition"
|
||||
;;
|
||||
btrfs)
|
||||
echo "Resize 'btrfs' root filesystem ($partition)"
|
||||
modprobe btrfs
|
||||
resize_root_filesystem_tmp_btrfs="$(mktemp -d)"
|
||||
mount -t btrfs "$partition" "$resize_root_filesystem_tmp_btrfs"
|
||||
btrfs filesystem resize max "$resize_root_filesystem_tmp_btrfs"
|
||||
umount "$resize_root_filesystem_tmp_btrfs"
|
||||
unset resize_root_filesystem_tmp_btrfs
|
||||
;;
|
||||
*) echo "WARNING: Can not resize '$type' filesystem ($partition)." ;;
|
||||
esac
|
||||
show_splash "Loading..."
|
||||
fi
|
||||
}
|
||||
|
||||
mount_root_partition() {
|
||||
# Don't mount root if it is already mounted
|
||||
if mountpoint -q /sysroot; then
|
||||
|
|
@ -801,6 +721,7 @@ setup_usb_network() {
|
|||
[ -e "$_marker" ] && return
|
||||
touch "$_marker"
|
||||
echo "Setup usb network"
|
||||
modprobe libcomposite
|
||||
# Run all usb network setup functions (add more below!)
|
||||
setup_usb_network_android
|
||||
setup_usb_network_configfs
|
||||
|
|
@ -931,6 +852,7 @@ debug_shell() {
|
|||
initrd: $INITRAMFS_PKG_VERSION
|
||||
|
||||
Run 'pmos_continue_boot' to continue booting.
|
||||
Read the initramfs log with 'cat /pmOS_init.log'.
|
||||
EOF
|
||||
|
||||
# Add pmos_logdump message only if relevant
|
||||
|
|
@ -1005,7 +927,9 @@ debug_shell() {
|
|||
# Getty on the display
|
||||
hide_splash
|
||||
# Spawn buffyboard if the device might not have a physical keyboard
|
||||
if echo "handset tablet convertible" | grep "${deviceinfo_chassis:-handset}" >/dev/null; then
|
||||
# buffyboard is only available with merged initramfs-extra!
|
||||
if command -v buffyboard 2>/dev/null && \
|
||||
echo "handset tablet convertible" | grep "${deviceinfo_chassis:-handset}" >/dev/null; then
|
||||
modprobe uinput
|
||||
# Set a large font for the framebuffer
|
||||
setfont "/usr/share/consolefonts/ter-128n.psf.gz" -C "/dev/$active_console"
|
||||
|
|
|
|||
125
main/postmarketos-initramfs/init_functions_2nd.sh
Normal file
125
main/postmarketos-initramfs/init_functions_2nd.sh
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#!/bin/sh
|
||||
# Additional functions that depend on initramfs-extra
|
||||
# Functions are notated with the reason they're only in
|
||||
# initramfs-extra
|
||||
|
||||
ROOT_PARTITION_RESIZED=0
|
||||
|
||||
# udevd is too big
|
||||
setup_udev() {
|
||||
if ! command -v udevd > /dev/null || ! command -v udevadm > /dev/null; then
|
||||
echo "ERROR: udev not found!"
|
||||
return
|
||||
fi
|
||||
|
||||
# This is the same series of steps performed by the udev,
|
||||
# udev-trigger and udev-settle RC services. See also:
|
||||
# - https://git.alpinelinux.org/aports/tree/main/eudev/setup-udev
|
||||
# - https://git.alpinelinux.org/aports/tree/main/udev-init-scripts/APKBUILD
|
||||
udevd -d --resolve-names=never
|
||||
udevadm trigger --type=devices --action=add
|
||||
udevadm settle
|
||||
}
|
||||
|
||||
# parted is too big
|
||||
resize_root_partition() {
|
||||
partition=$(find_root_partition)
|
||||
|
||||
# Do not resize the installer partition
|
||||
if [ "$(blkid --label pmOS_install)" = "$partition" ]; then
|
||||
echo "Resize root partition: skipped (on-device installer)"
|
||||
return
|
||||
fi
|
||||
|
||||
# Only resize the partition if it's inside the device-mapper, which means
|
||||
# that the partition is stored as a subpartition inside another one.
|
||||
# In this case we want to resize it to use all the unused space of the
|
||||
# external partition.
|
||||
if [ -z "${partition##"/dev/mapper/"*}" ] || [ -z "${partition##"/dev/dm-"*}" ]; then
|
||||
# Get physical device
|
||||
if [ -n "$SUBPARTITION_DEV" ]; then
|
||||
partition_dev="$SUBPARTITION_DEV"
|
||||
else
|
||||
partition_dev=$(dmsetup deps -o blkdevname "$partition" | \
|
||||
awk -F "[()]" '{print "/dev/"$2}')
|
||||
fi
|
||||
if has_unallocated_space "$partition_dev"; then
|
||||
echo "Resize root partition ($partition)"
|
||||
# unmount subpartition, resize and remount it
|
||||
kpartx -d "$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
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
# Resize the root partition (non-subpartitions) on Chrome OS devices.
|
||||
# Match $deviceinfo_cgpt_kpart not being empty instead of cmdline
|
||||
# because it does not make sense here as all these devices use the same
|
||||
# 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
|
||||
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
|
||||
}
|
||||
|
||||
# resize2fs and resize.f2fs are too big
|
||||
resize_root_filesystem() {
|
||||
if [ "$ROOT_PARTITION_RESIZED" = 1 ]; then
|
||||
show_splash "Resizing filesystem during initial boot..."
|
||||
partition="$(find_root_partition)"
|
||||
touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323
|
||||
type="$(get_partition_type "$partition")"
|
||||
case "$type" in
|
||||
ext4)
|
||||
echo "Resize 'ext4' root filesystem ($partition)"
|
||||
modprobe ext4
|
||||
resize2fs -f "$partition"
|
||||
;;
|
||||
f2fs)
|
||||
echo "Resize 'f2fs' root filesystem ($partition)"
|
||||
modprobe f2fs
|
||||
resize.f2fs "$partition"
|
||||
;;
|
||||
btrfs)
|
||||
echo "Resize 'btrfs' root filesystem ($partition)"
|
||||
modprobe btrfs
|
||||
resize_root_filesystem_tmp_btrfs="$(mktemp -d)"
|
||||
mount -t btrfs "$partition" "$resize_root_filesystem_tmp_btrfs"
|
||||
btrfs filesystem resize max "$resize_root_filesystem_tmp_btrfs"
|
||||
umount "$resize_root_filesystem_tmp_btrfs"
|
||||
unset resize_root_filesystem_tmp_btrfs
|
||||
;;
|
||||
*) echo "WARNING: Can not resize '$type' filesystem ($partition)." ;;
|
||||
esac
|
||||
show_splash "Loading..."
|
||||
fi
|
||||
}
|
||||
33
main/postmarketos-initramfs/mdev.conf
Normal file
33
main/postmarketos-initramfs/mdev.conf
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# This is an mdev config for the postmarketOS initramfs
|
||||
#
|
||||
|
||||
# Devices:
|
||||
# Syntax: %s %d:%d %s
|
||||
# devices user:group mode
|
||||
|
||||
$MODALIAS=.* 0:0 0660 @modprobe -q -b "$MODALIAS"
|
||||
|
||||
# null does already exist; therefore ownership has to be changed with command
|
||||
null 0:0 0666 @chmod 666 $MDEV
|
||||
zero 0:0 0666
|
||||
full 0:0 0666
|
||||
|
||||
random 0:0 0666
|
||||
urandom 0:0 0444
|
||||
hwrandom 0:0 0660
|
||||
|
||||
console 0:0 0600
|
||||
|
||||
kmem 0:0 0640
|
||||
mem 0:0 0640
|
||||
|
||||
# Set up /dev/disk/by-* symlinks
|
||||
dasd.* 0:0 0660 */lib/mdev/persistent-storage
|
||||
mmcblk.* 0:0 0660 */lib/mdev/persistent-storage
|
||||
nbd.* 0:0 0660 */lib/mdev/persistent-storage
|
||||
nvme.* 0:0 0660 */lib/mdev/persistent-storage
|
||||
sd[a-z].* 0:0 0660 */lib/mdev/persistent-storage
|
||||
sr[0-9]+ 0:0 0660 */lib/mdev/persistent-storage
|
||||
vd[a-z].* 0:0 0660 */lib/mdev/persistent-storage
|
||||
xvd[a-z].* 0:0 0660 */lib/mdev/persistent-storage
|
||||
Loading…
Add table
Add a link
Reference in a new issue