198 lines
8.4 KiB
Diff
198 lines
8.4 KiB
Diff
|
From b8b7e0245bb3c645b45d4a31847ed227a8431ec8 Mon Sep 17 00:00:00 2001
|
||
|
From: Philipp Rudo <prudo@redhat.com>
|
||
|
Date: Mon, 22 Jul 2024 16:46:47 +0200
|
||
|
Subject: [PATCH 15/24] feat(dracut-init.sh): allow changing the destination
|
||
|
directory for inst et al
|
||
|
|
||
|
When using 99squash dracut actually builds two separate initrds. The
|
||
|
"normal" one, that gets squashed into a squashfs image, and a
|
||
|
"minimalistic" one, whose only task is to mount and switch_root to the
|
||
|
squashfs image.
|
||
|
|
||
|
This is currently done the following way:
|
||
|
1. Skipp install() for 99squash during the "normal" installation phase.
|
||
|
2. Trigger a special postinstall hook in 99squash that moves the content
|
||
|
of $initdir to $squashdir and installs the "minimalistic" initrd to
|
||
|
$initdir.
|
||
|
3. Strip the binaries in $initdir (of which $squashdir is a sub
|
||
|
directory of).
|
||
|
4. Squash the content of $squashdir into the squashfs image and remove
|
||
|
$squashdir.
|
||
|
|
||
|
The problem with this approach is that the steps 2 and 4 specific to
|
||
|
99squash but need to be done in dracut.sh. Thus a lot of special
|
||
|
handling for 99squash is needed in dracut.sh. This will get even more
|
||
|
complex once support for different filesystem images, e.g. erofs, are
|
||
|
implemented.
|
||
|
|
||
|
In order to be able to move most of the functionality into 99squash
|
||
|
itself a new approach will be chosen, i.e.
|
||
|
1. During the installation phase install the "normal" initrd into
|
||
|
$initdir and the "minimalistic" initrd into $squashdir.
|
||
|
2. Strip the binaries in $initdir.
|
||
|
3. Trigger a special postinstall hook in 99squash that squashes the
|
||
|
content of $initdir (excluding $squashdir) into the squashfs image,
|
||
|
removes the content of $intidir (excluding $suqashdir) and, moves the
|
||
|
content of $squashdir into $initdir.
|
||
|
|
||
|
With that the only special handling remaining in dracut.sh is triggering
|
||
|
the postinstall hook.
|
||
|
|
||
|
However, in inst et al. the destination directory is hard coded to
|
||
|
$initdir. Thus allow setting a different destination directory in inst
|
||
|
et al. to get the new approach to work. For the time being only do that
|
||
|
for the functions required by 99squash.
|
||
|
|
||
|
Signed-off-by: Philipp Rudo <prudo@redhat.com>
|
||
|
|
||
|
(cherry picked from commit 5ab4470cf136c2d9983564b84b49fd700d4b8514)
|
||
|
|
||
|
Related: RHEL-43460
|
||
|
---
|
||
|
dracut-init.sh | 40 +++++++++++++++++++++++++---------------
|
||
|
1 file changed, 25 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/dracut-init.sh b/dracut-init.sh
|
||
|
index 863df0cb..58e657b5 100755
|
||
|
--- a/dracut-init.sh
|
||
|
+++ b/dracut-init.sh
|
||
|
@@ -240,34 +240,36 @@ inst_dir() {
|
||
|
}
|
||
|
|
||
|
inst() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
local _ret _hostonly_install
|
||
|
if [[ $1 == "-H" ]]; then
|
||
|
_hostonly_install="-H"
|
||
|
shift
|
||
|
fi
|
||
|
- [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
|
||
|
- if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
|
||
|
+ [[ -e ${dstdir}/"${2:-$1}" ]] && return 0 # already there
|
||
|
+ if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
|
||
|
return 0
|
||
|
else
|
||
|
_ret=$?
|
||
|
- derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
|
||
|
+ derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
|
||
|
return $_ret
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
inst_simple() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
local _ret _hostonly_install
|
||
|
if [[ $1 == "-H" ]]; then
|
||
|
_hostonly_install="-H"
|
||
|
shift
|
||
|
fi
|
||
|
- [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
|
||
|
- [[ -e $1 ]] || return 1 # no source
|
||
|
- if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
|
||
|
+ [[ -e ${dstdir}/"${2:-$1}" ]] && return 0 # already there
|
||
|
+ [[ -e $1 ]] || return 1 # no source
|
||
|
+ if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
|
||
|
return 0
|
||
|
else
|
||
|
_ret=$?
|
||
|
- derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
|
||
|
+ derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
|
||
|
return $_ret
|
||
|
fi
|
||
|
}
|
||
|
@@ -290,16 +292,17 @@ inst_symlink() {
|
||
|
}
|
||
|
|
||
|
inst_multiple() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
local _ret _hostonly_install
|
||
|
if [[ $1 == "-H" ]]; then
|
||
|
_hostonly_install="-H"
|
||
|
shift
|
||
|
fi
|
||
|
- if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
|
||
|
+ if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
|
||
|
return 0
|
||
|
else
|
||
|
_ret=$?
|
||
|
- derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
|
||
|
+ derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${dstdir:+-D "$dstdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
|
||
|
return $_ret
|
||
|
fi
|
||
|
}
|
||
|
@@ -566,6 +569,8 @@ inst_rules_wildcard() {
|
||
|
|
||
|
# make sure that library links are correct and up to date
|
||
|
build_ld_cache() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
+
|
||
|
for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
|
||
|
[[ -f $f ]] && inst_simple "${f#"$dracutsysrootdir"}"
|
||
|
done
|
||
|
@@ -1047,13 +1052,15 @@ for_each_module_dir() {
|
||
|
}
|
||
|
|
||
|
dracut_kernel_post() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
+
|
||
|
for _f in modules.builtin modules.builtin.alias modules.builtin.modinfo modules.order; do
|
||
|
[[ -e $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
|
||
|
done
|
||
|
|
||
|
# generate module dependencies for the initrd
|
||
|
- if [[ -d $initdir/lib/modules/$kernel ]] \
|
||
|
- && ! depmod -a -b "$initdir" "$kernel"; then
|
||
|
+ if [[ -d $dstdir/lib/modules/$kernel ]] \
|
||
|
+ && ! depmod -a -b "$dstdir" "$kernel"; then
|
||
|
dfatal "\"depmod -a $kernel\" failed."
|
||
|
exit 1
|
||
|
fi
|
||
|
@@ -1067,6 +1074,7 @@ instmods() {
|
||
|
# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
|
||
|
# -c check
|
||
|
# -s silent
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
local _optional="-o"
|
||
|
local _silent
|
||
|
local _ret
|
||
|
@@ -1092,7 +1100,7 @@ instmods() {
|
||
|
fi
|
||
|
|
||
|
$DRACUT_INSTALL \
|
||
|
- ${initdir:+-D "$initdir"} \
|
||
|
+ ${dstdir:+-D "$dstdir"} \
|
||
|
${dracutsysrootdir:+-r "$dracutsysrootdir"} \
|
||
|
${loginstall:+-L "$loginstall"} \
|
||
|
${hostonly:+-H} \
|
||
|
@@ -1106,7 +1114,7 @@ instmods() {
|
||
|
if ((_ret != 0)) && [[ -z $_silent ]]; then
|
||
|
derror "FAILED: " \
|
||
|
"$DRACUT_INSTALL" \
|
||
|
- ${initdir:+-D "$initdir"} \
|
||
|
+ ${dstdir:+-D "$dstdir"} \
|
||
|
${dracutsysrootdir:+-r "$dracutsysrootdir"} \
|
||
|
${loginstall:+-L "$loginstall"} \
|
||
|
${hostonly:+-H} \
|
||
|
@@ -1123,14 +1131,16 @@ instmods() {
|
||
|
|
||
|
if [[ "$(ln --help)" == *--relative* ]]; then
|
||
|
ln_r() {
|
||
|
- ln -sfnr "${initdir}/$1" "${initdir}/$2"
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
+ ln -sfnr "${dstdir}/$1" "${dstdir}/$2"
|
||
|
}
|
||
|
else
|
||
|
ln_r() {
|
||
|
+ local dstdir="${dstdir:-"$initdir"}"
|
||
|
local _source=$1
|
||
|
local _dest=$2
|
||
|
[[ -d ${_dest%/*} ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
|
||
|
- ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
|
||
|
+ ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${dstdir}/${_dest}"
|
||
|
}
|
||
|
fi
|
||
|
|
||
|
--
|
||
|
2.42.0
|
||
|
|