dracut/0016-feat-squash-add-module-95squash-erofs.patch
Pavel Valena a3b408b277 Upgrade to dracut 103
- enable dracut-cpio binary
- feat(fips-crypto-policies): make c-p follow FIPS mode automatically
- fix(fips-crypto-policies): make it depend on fips dracut module

Resolves: RHEL-59678,RHEL-65204

From-source-git-commit: ff3186be9d5871c6ec216019463199bb78cc1b32
2024-11-01 18:42:50 +01:00

129 lines
3.8 KiB
Diff

From fcc73940a1e21fa79b7133e12ed0f8ed13645a54 Mon Sep 17 00:00:00 2001
From: Philipp Rudo <prudo@redhat.com>
Date: Tue, 23 Jul 2024 17:42:33 +0200
Subject: [PATCH 16/32] feat(squash): add module 95squash-erofs
Allow squashing the image in 99squash using erofs. Keep squashfs as
default to not change existing systems. I.e. only use erofs if the user
explicitly include 95squash-erofs or when the prereqs for squashfs are
missing.
Signed-off-by: Philipp Rudo <prudo@redhat.com>
(cherry picked from commit e185d6ae1cc38af90f741d3d6c677458d69a345f)
Resolves: RHEL-43460
---
modules.d/95squash-erofs/module-setup.sh | 45 ++++++++++++++++++++++++
modules.d/99squash/init-squash.sh | 12 +++++--
modules.d/99squash/module-setup.sh | 4 ++-
3 files changed, 58 insertions(+), 3 deletions(-)
create mode 100755 modules.d/95squash-erofs/module-setup.sh
diff --git a/modules.d/95squash-erofs/module-setup.sh b/modules.d/95squash-erofs/module-setup.sh
new file mode 100755
index 00000000..71c2b672
--- /dev/null
+++ b/modules.d/95squash-erofs/module-setup.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+check() {
+ require_binaries mkfs.erofs || return 1
+ require_kernel_modules erofs || return 1
+
+ return 255
+}
+
+depends() {
+ echo "squash"
+ return 0
+}
+
+erofs_install() {
+ hostonly="" instmods "erofs"
+}
+
+erofs_installpost() {
+ local _img="$squashdir/erofs-root.img"
+ local -a _erofs_args
+
+ _erofs_args+=("--exclude-path=$squashdir")
+ _erofs_args+=("-E" "fragments")
+
+ if [[ -n $squash_compress ]]; then
+ if mkfs.erofs "${_erofs_args[@]}" -z "$squash_compress" "$_img" "$initdir" &> /dev/null; then
+ return
+ fi
+ dwarn "mkfs.erofs doesn't support compressor '$squash_compress', failing back to default compressor."
+ fi
+
+ if ! mkfs.erofs "${_erofs_args[@]}" "$_img" "$initdir" &> /dev/null; then
+ dfatal "Failed making squash image"
+ exit 1
+ fi
+}
+
+install() {
+ if [[ $DRACUT_SQUASH_POST_INST ]]; then
+ erofs_installpost
+ else
+ dstdir="$squashdir" erofs_install
+ fi
+}
diff --git a/modules.d/99squash/init-squash.sh b/modules.d/99squash/init-squash.sh
index 42a9a86f..31a39cfd 100755
--- a/modules.d/99squash/init-squash.sh
+++ b/modules.d/99squash/init-squash.sh
@@ -13,15 +13,23 @@ grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \
grep -q '^tmpfs /run tmpfs' /proc/self/mounts \
|| (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run)
+if [ -e /erofs-root.img ]; then
+ _fs=erofs
+ _img=erofs-root.img
+else
+ _fs=squashfs
+ _img=squashfs-root.img
+fi
+
# Load required modules
modprobe loop
-modprobe squashfs
+modprobe "$_fs"
modprobe overlay
# Mount the squash image
mount -t ramfs ramfs /squash
mkdir -p /squash/root /squash/overlay/upper /squash/overlay/work
-mount -t squashfs -o ro,loop /squashfs-root.img /squash/root
+mount -t "$_fs" -o ro,loop /"$_img" /squash/root
# Setup new root overlay
mkdir /newroot
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
index 015944c2..5cbbec63 100755
--- a/modules.d/99squash/module-setup.sh
+++ b/modules.d/99squash/module-setup.sh
@@ -18,7 +18,7 @@ depends() {
squash_get_handler() {
local _module _handler
- for _module in squash-squashfs; do
+ for _module in squash-squashfs squash-erofs; do
if dracut_module_included "$_module"; then
_handler="$_module"
break
@@ -28,6 +28,8 @@ squash_get_handler() {
if [ -z "$_handler" ]; then
if check_module "squash-squashfs"; then
_handler="squash-squashfs"
+ elif check_module "squash-erofs"; then
+ _handler="squash-erofs"
else
dfatal "No valid handler for found"
return 1
--
2.42.0