main/postmarketos-initramfs: run fsck and mount sysroot as rw (MR 5238)
This moves the responsibility to auto-repair filesystems to the initramfs. (I think we don't do this at all right now). We don't try to mount broken partitions at all, we tell the user that the system is broken and fail_to_boot. The flow is now: 1. mount the boot partition (read-only) for initramfs-extra 2. initramfs-extra is extracted (with the needed fsck executables) 3. fsck the root partition 4. mount root partition (read-write) 5. fsck the boot partition 6. mount the boot partition (read-write) This helps with the systemd bringup, as we want to make use of systemd-firstboot, which sets /etc and enabled services up. As this service is responsible of setting up /etc, it is run before /etc/fstab is read and before / is remounted read-write.
This commit is contained in:
parent
d769cafbf0
commit
59fd336bbc
3 changed files with 63 additions and 7 deletions
|
@ -2,7 +2,9 @@
|
|||
/sbin/btrfs
|
||||
/sbin/dmsetup
|
||||
/sbin/e2fsck
|
||||
/sbin/fsck.vfat
|
||||
/sbin/switch_root
|
||||
/usr/sbin/fsck.f2fs
|
||||
/usr/sbin/parted
|
||||
/usr/sbin/resize2fs
|
||||
/usr/sbin/resize.f2fs
|
||||
/usr/sbin/resize2fs
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
|
||||
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
|
||||
pkgname=postmarketos-initramfs
|
||||
pkgver=3.2.1
|
||||
pkgver=3.3.0
|
||||
pkgrel=0
|
||||
pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
|
||||
url="https://postmarketos.org"
|
||||
|
@ -17,6 +17,7 @@ depends="
|
|||
cryptsetup
|
||||
device-mapper
|
||||
devicepkg-utils>=0.2.0
|
||||
dosfstools
|
||||
e2fsprogs
|
||||
e2fsprogs-extra
|
||||
f2fs-tools
|
||||
|
@ -90,8 +91,8 @@ sha512sums="
|
|||
20bc7a21f4f59548b8179c5cb1fc2b3db64eb355988bce992db3bc4075d65b4135ff9dd7d754215d0402978811494449cce476a26cda6bb2f0f8b53ae8e36bd7 00-default.modules
|
||||
9c0e8f6f61d5da191e03a1aa9d5d0ceb5baf1eae6dbb9bfb0af59817783525119ac8394b135f303f7b6434a3eab0b49185fb90379e06823db847a4999c75ce33 00-initramfs-base.dirs
|
||||
929a8e6cca6b2b4ac6af89fc3912e80315f51c9bf6e9479124ccb7ebe9e99c6c1cafb98d3aa01b0a76a2f6e0071ba3eb86c7a2169a15c2e1788d69458bea3471 00-initramfs-base.files
|
||||
8a4adad3785af474b36a09a05f6a3b2c4b4f43aac331a53b903abfa51ea12be1e3d1d807b7a6e66a1346815f3b0044daf8cd62e21e2dc75d2db13ee265a72985 00-initramfs-extra-base.files
|
||||
f0f00a35f06b7d0a46c67df753ecef880ac92a725a8301649068069d2d477ae3278b3c548ea3f378b4c23eafb39551f5e3ca6a63478486d50a298132140b5b69 00-initramfs-extra-base.files
|
||||
e85386077d590cd0db0745e8b58f3323a408cb6a94bca0e4395c43e4db18b0beef29324ed2bfeab6511d0e3b297c067e5a37f420a6877d9c28c285f2416ca420 init.sh
|
||||
e0954014d73e7a61376a2463978a4b44d17bbb2319072382a3412a8214e9c3e45266266d8eebd37634b1b18a71094055464a7c81b973501378dcf05aa5c2f4c0 init_functions.sh
|
||||
aa9591e2c35577bc3c1e9bafa7904b3dff97c42992a763113fff20754e82d521cc690733a1606d6808d556b5a271b5ad8fdc0d2aa475fcb3921433dca0ce178b init_functions.sh
|
||||
ba3275a9af788c7c782322a22a0f144d5e50e3498ea6886486a29331f23ae89cd32d500a3635cfa7cab369afba92edc18aeca64ccbf0cd589061cce23d15b46c unudhcpd.conf
|
||||
"
|
||||
|
|
|
@ -341,6 +341,57 @@ get_partition_type() {
|
|||
blkid "$partition" | sed 's/^.*TYPE="\([a-zA-z0-9_]*\)".*$/\1/'
|
||||
}
|
||||
|
||||
# $1: partition
|
||||
check_filesystem() {
|
||||
local partition=""
|
||||
local status=""
|
||||
local type=""
|
||||
|
||||
partition="$1"
|
||||
type="$(get_partition_type "$partition")"
|
||||
case "$type" in
|
||||
btrfs)
|
||||
echo "Check 'btrfs' root filesystem ($partition)"
|
||||
if ! btrfs check --readonly "$partition" ; then
|
||||
status="fail"
|
||||
fi
|
||||
;;
|
||||
ext*)
|
||||
echo "Auto-repair and check 'ext' filesystem ($partition)"
|
||||
e2fsck -p "$partition"
|
||||
if [ $? -ge 4 ]; then
|
||||
status="fail"
|
||||
fi
|
||||
;;
|
||||
f2fs)
|
||||
echo "Auto-repair and check 'f2fs' filesystem ($partition)"
|
||||
fsck.f2fs -p "$partition"
|
||||
status=$?
|
||||
if [ $? -gt 4 ]; then
|
||||
status="fail"
|
||||
fi
|
||||
;;
|
||||
vfat)
|
||||
echo "Auto-repair and check 'vfat' filesystem ($partition)"
|
||||
fsck.vfat -p "$partition"
|
||||
if [ $? -gt 4 ]; then
|
||||
status="fail"
|
||||
fi
|
||||
|
||||
;;
|
||||
*) echo "WARNING: fsck not supported for '$type' filesystem ($partition)." ;;
|
||||
esac
|
||||
|
||||
if [ "$status" = "fail" ]; then
|
||||
show_splash "WARNING: filesystem needs manual repair (fsck) ($partition)\\nhttps://postmarketos.org/troubleshooting\\n\\nBoot anyways by pressing Volume-Up or Left-Shift..."
|
||||
while ! iskey KEY_LEFTSHIFT KEY_VOLUMEUP ; do
|
||||
:
|
||||
done
|
||||
fi
|
||||
|
||||
show_splash "Loading..."
|
||||
}
|
||||
|
||||
# $1: path
|
||||
# $2: set to "rw" for read-write
|
||||
# Mount the boot partition. It gets mounted twice, first at /boot (ro), then at
|
||||
|
@ -356,6 +407,7 @@ mount_boot_partition() {
|
|||
fi
|
||||
|
||||
if [ "$2" = "rw" ]; then
|
||||
check_filesystem "$partition"
|
||||
echo "Mount boot partition ($partition) to $1 (read-write)"
|
||||
else
|
||||
mount_opts="$mount_opts,ro"
|
||||
|
@ -580,14 +632,15 @@ mount_root_partition() {
|
|||
partition="$(find_root_partition)"
|
||||
rootfsopts=""
|
||||
|
||||
check_filesystem "$partition"
|
||||
# shellcheck disable=SC2013
|
||||
for x in $(cat /proc/cmdline); do
|
||||
[ "$x" = "${x#pmos_rootfsopts=}" ] && continue
|
||||
# Prepend a comma because this will be appended to "ro" below
|
||||
# Prepend a comma because this will be appended to "rw" below
|
||||
rootfsopts=",${x#pmos_rootfsopts=}"
|
||||
done
|
||||
|
||||
echo "Mount root partition ($partition) to /sysroot (read-only) with options ${rootfsopts#,}"
|
||||
echo "Mount root partition ($partition) to /sysroot (read-write) with options ${rootfsopts#,}"
|
||||
type="$(get_partition_type "$partition")"
|
||||
echo "Detected $type filesystem"
|
||||
|
||||
|
@ -600,7 +653,7 @@ mount_root_partition() {
|
|||
if ! modprobe "$type"; then
|
||||
echo "INFO: unable to load module '$type' - maybe it's built in"
|
||||
fi
|
||||
if ! mount -t "$type" -o ro"$rootfsopts" "$partition" /sysroot; then
|
||||
if ! mount -t "$type" -o rw"$rootfsopts" "$partition" /sysroot; then
|
||||
echo "ERROR: unable to mount root partition!"
|
||||
show_splash "ERROR: unable to mount root partition\\nhttps://postmarketos.org/troubleshooting"
|
||||
fail_halt_boot
|
||||
|
|
Loading…
Reference in a new issue