main/postmarketos-mkinitfs: load file system modules dynamically (MR 3166)

At the moment, mkinitfs loads some file system modules always (ext4),
some dynamically (brtfs) and some not at all (f2fs, vfat), expecting
them to be built-in.

To support generic kernels (e.g. from Alpine) properly, use the
partition type detection for both boot and root partition and always
load the necessary modules before mounting.
This commit is contained in:
Minecrell 2022-05-28 12:57:34 +02:00 committed by Oliver Smith
parent a0a0b369d5
commit 16c9892a8f
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
3 changed files with 31 additions and 11 deletions

View file

@ -2,7 +2,7 @@
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=postmarketos-mkinitfs
pkgver=1.4.1
pkgrel=4
pkgrel=5
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://postmarketos.org"
depends="
@ -69,7 +69,7 @@ check() {
sha512sums="
f827acb0a10c0e5c1631f1b712e91fde7eb4ade0f1174eb2ef1754018bf4518ea1ad3229fd335c25fb0c6fe46ae20890f5cf43e58c8143ae17b5ab9bb36f0199 postmarketos-mkinitfs-1.4.1.tar.gz
08a3e79c6fa7d3839d43515b8da7817cb36f4ab014552fd0164957c232bb16fde337e57c47c9734d396a5fca3328fbf49ebabe4728c6071c80b04dad14886bba 00-default.modules
d16dc495afcab64e8ae70b8de06444aac3d655ca59c544717ea779d160d597a0a32da62e55e7493b0c7626e1e7fcefa3f94b917ae16ac7d2990a3038934a6fac init.sh
ef099d394406462268fe9e2d28a5355ef09a30fa7283d58e2c567088bd767fb8079399426ccaabe48dbc7774cf9cd7a5b853d850a978ae05e0d74909cee5b207 init_functions.sh
1297ca5349326406a9db64a1dac47a822c257d781d1ecc6215b5aca7e2d22fa95396448318d6163dc8b172e2ce1d32ee846d32d796234fa4507016d39d3c4a82 00-default.modules
ccdceaa710d97d6f57d8d66bfcbec448486d08083341712303f62123039f729229b88528308e411a308a2b90b81b60de89fe91143a6facbb11cbc9b4055eeaec init.sh
b6f433aa5a758e58ae4745f2b11f691f4d3ffbef35d9002bc2721ba797b3e7653e9449b6a1b503c47d725f644e0d7c0e5426f8a575f4cc437c21cfc6e2f4cdf3 init_functions.sh
"

View file

@ -16,7 +16,7 @@ create_device_nodes
setup_log
setup_firmware_path
# shellcheck disable=SC2154,SC2086
[ -d /lib/modules ] && modprobe -a ${deviceinfo_modules_initfs} ext4 usb_f_rndis
[ -d /lib/modules ] && modprobe -a ${deviceinfo_modules_initfs} usb_f_rndis
setup_mdev
setup_dynamic_partitions "${deviceinfo_super_partitions:=}"

View file

@ -213,6 +213,11 @@ find_boot_partition() {
|| findfs LABEL="pmOS_boot"
}
get_partition_type() {
partition="$1"
blkid "$partition" | sed 's/^.*TYPE="\([a-zA-z0-9_]*\)".*$/\1/'
}
# $1: path
# $2: set to "rw" for read-write
# Mount the boot partition. It gets mounted twice, first at /boot (ro), then at
@ -234,6 +239,22 @@ mount_boot_partition() {
echo "Mount boot partition ($partition) to $1 (read-only)"
fi
type="$(get_partition_type "$partition")"
case "$type" in
ext*)
echo "Detected ext filesystem"
modprobe ext4
# ext2 might be handled by the ext2 or ext4 kernel module
# so let mount detect that automatically by omitting -t
;;
vfat)
echo "Detected vfat filesystem"
modprobe vfat
mount_opts="-t vfat $mount_opts"
;;
*) echo "WARNING: Detected unsupported '$type' filesystem ($partition)." ;;
esac
# shellcheck disable=SC2086
mount $mount_opts "$partition" "$1"
}
@ -338,11 +359,6 @@ unlock_root_partition() {
fi
}
get_partition_type() {
partition="$1"
blkid "$partition" | sed 's/^.*TYPE="\([a-zA-z0-9_]*\)".*$/\1/'
}
resize_root_filesystem() {
if [ "$ROOT_PARTITION_RESIZED" = 1 ]; then
show_splash /splash-resizefs.ppm.gz
@ -352,10 +368,12 @@ resize_root_filesystem() {
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)
@ -380,10 +398,12 @@ mount_root_partition() {
case "$type" in
ext4)
echo "Detected ext4 filesystem"
modprobe ext4
mount -t ext4 -o ro "$partition" /sysroot
;;
f2fs)
echo "Detected f2fs filesystem"
modprobe f2fs
mount -t f2fs -o ro "$partition" /sysroot
;;
btrfs)
@ -391,7 +411,7 @@ mount_root_partition() {
modprobe btrfs
mount -t btrfs -o ro "$partition" /sysroot
;;
*) echo "WARNING: Detected '$type' filesystem ($partition)." ;;
*) echo "WARNING: Detected unsupported '$type' filesystem ($partition)." ;;
esac
if ! [ -e /sysroot/usr ]; then
echo "ERROR: unable to mount root partition!"