Introduce tri-state hostonly mode
Add a new option --hostonly-mode which accept an <mode> parameter, so we have a tri-state hostonly mode: * generic: by passing "--no-hostonly" or not passing anything. "--hostonly-mode" has no effect in such case. * sloppy: by passing "--hostonly --hostonly-mode sloppy". This is also the default mode when only "--hostonly" is given. * strict: by passing "--hostonly --hostonly-mode strict". Sloppy mode is the original hostonly mode, the new introduced strict mode will allow modules to ignore more drivers or do some extra job to save memory and disk space, while making the image less portable. Also introduced a helper function "optional_hostonly" to make it easier for modules to leverage new hostonly mode. To force install modules only in sloppy hostonly mode, use the form: hostonly="$(optional_hostonly)" instmods <modules> Signed-off-by: Kairui Song <kasong@redhat.com>master
parent
6ccb58a5b6
commit
a695250ec7
|
@ -267,6 +267,18 @@ inst_fsck_help() {
|
||||||
(($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper || :
|
(($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper || :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
|
||||||
|
# If hosotnly mode is set to "strict", hostonly restrictions will still
|
||||||
|
# be applied, else will ignore hostonly mode and try to install all
|
||||||
|
# given modules.
|
||||||
|
optional_hostonly() {
|
||||||
|
if [[ $hostonly_mode = "strict" ]]; then
|
||||||
|
printf -- "$hostonly"
|
||||||
|
else
|
||||||
|
printf ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
mark_hostonly() {
|
mark_hostonly() {
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
echo "$i" >> "$initdir/lib/dracut/hostonly-files"
|
echo "$i" >> "$initdir/lib/dracut/hostonly-files"
|
||||||
|
|
32
dracut.sh
32
dracut.sh
|
@ -147,6 +147,21 @@ Creates initial ramdisk images for preloading modules
|
||||||
-H, --hostonly Host-Only mode: Install only what is needed for
|
-H, --hostonly Host-Only mode: Install only what is needed for
|
||||||
booting the local host instead of a generic host.
|
booting the local host instead of a generic host.
|
||||||
-N, --no-hostonly Disables Host-Only mode
|
-N, --no-hostonly Disables Host-Only mode
|
||||||
|
--hostonly-mode <mode>
|
||||||
|
Specify the hostonly mode to use. <mode> could be
|
||||||
|
one of "sloppy" or "strict". "sloppy" mode is used
|
||||||
|
by default.
|
||||||
|
In "sloppy" hostonly mode, extra drivers and modules
|
||||||
|
will be installed, so minor hardware change won't make
|
||||||
|
the image unbootable (eg. changed keyboard), and the
|
||||||
|
image is still portable among similar hosts.
|
||||||
|
With "strict" mode enabled, anything not necessary
|
||||||
|
for booting the local host in its current state will
|
||||||
|
not be included, and modules may do some extra job
|
||||||
|
to save more space. Minor change of hardware or
|
||||||
|
environment could make the image unbootable.
|
||||||
|
DO NOT use "strict" mode unless you know what you
|
||||||
|
are doing.
|
||||||
--hostonly-cmdline Store kernel command line arguments needed
|
--hostonly-cmdline Store kernel command line arguments needed
|
||||||
in the initramfs
|
in the initramfs
|
||||||
--no-hostonly-cmdline Do not store kernel command line arguments needed
|
--no-hostonly-cmdline Do not store kernel command line arguments needed
|
||||||
|
@ -352,6 +367,7 @@ rearrange_params()
|
||||||
--long host-only \
|
--long host-only \
|
||||||
--long no-hostonly \
|
--long no-hostonly \
|
||||||
--long no-host-only \
|
--long no-host-only \
|
||||||
|
--long hostonly-mode: \
|
||||||
--long hostonly-cmdline \
|
--long hostonly-cmdline \
|
||||||
--long no-hostonly-cmdline \
|
--long no-hostonly-cmdline \
|
||||||
--long no-hostonly-default-device \
|
--long no-hostonly-default-device \
|
||||||
|
@ -540,6 +556,8 @@ while :; do
|
||||||
hostonly_l="yes" ;;
|
hostonly_l="yes" ;;
|
||||||
-N|--no-hostonly|--no-host-only)
|
-N|--no-hostonly|--no-host-only)
|
||||||
hostonly_l="no" ;;
|
hostonly_l="no" ;;
|
||||||
|
--hostonly-mode)
|
||||||
|
hostonly_mode_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
|
||||||
--hostonly-cmdline)
|
--hostonly-cmdline)
|
||||||
hostonly_cmdline_l="yes" ;;
|
hostonly_cmdline_l="yes" ;;
|
||||||
--hostonly-i18n)
|
--hostonly-i18n)
|
||||||
|
@ -726,6 +744,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
|
||||||
[[ $prefix = "/" ]] && unset prefix
|
[[ $prefix = "/" ]] && unset prefix
|
||||||
[[ $hostonly_l ]] && hostonly=$hostonly_l
|
[[ $hostonly_l ]] && hostonly=$hostonly_l
|
||||||
[[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
|
[[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
|
||||||
|
[[ $hostonly_mode_l ]] && hostonly_mode=$hostonly_mode_l
|
||||||
[[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes"
|
[[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes"
|
||||||
[[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
|
[[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
|
||||||
[[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
|
[[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
|
||||||
|
@ -850,6 +869,19 @@ esac
|
||||||
[[ $hostonly = yes ]] && hostonly="-h"
|
[[ $hostonly = yes ]] && hostonly="-h"
|
||||||
[[ $hostonly != "-h" ]] && unset hostonly
|
[[ $hostonly != "-h" ]] && unset hostonly
|
||||||
|
|
||||||
|
case $hostonly_mode in
|
||||||
|
'')
|
||||||
|
[[ $hostonly ]] && hostonly_mode="sloppy" ;;
|
||||||
|
sloppy|strict)
|
||||||
|
if [[ ! $hostonly ]]; then
|
||||||
|
unset hostonly_mode
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
[[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
|
[[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
|
||||||
|
|
||||||
readonly TMPDIR="$(realpath -e "$tmpdir")"
|
readonly TMPDIR="$(realpath -e "$tmpdir")"
|
||||||
|
|
Loading…
Reference in New Issue