Skip to content

Commit

Permalink
Add a --hostonly-nics option
Browse files Browse the repository at this point in the history
Currently when network is enabled, dracut will install all network
drivers that are currently loaded, but some time only one NIC is needed
for the initramfs.

So for strict hostonly mode, add a --hostonly-nics option, user can
provide a list of NICs to be enabled, and only needed drivers for
specifed NICs will be installed so save space.

Signed-off-by: Kairui Song <[email protected]>
  • Loading branch information
ryncsn authored and haraldh committed Oct 26, 2020
1 parent e4483e5 commit 1e92f72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Creates initial ramdisk images for preloading modules
--hostonly-i18n Install only needed keyboard and font files according
to the host configuration (default).
--no-hostonly-i18n Install all keyboard and font files available.
--hostonly-nics [LIST]
Only enable listed NICs in the initramfs.
--persistent-policy [POLICY]
Use [POLICY] to address disks and partitions.
POLICY can be any directory name found in /dev/disk.
Expand Down Expand Up @@ -424,6 +426,7 @@ rearrange_params()
--long kernel-image: \
--long no-hostonly-i18n \
--long hostonly-i18n \
--long hostonly-nics: \
--long no-machineid \
--long version \
-- "$@")
Expand Down Expand Up @@ -587,6 +590,8 @@ while :; do
hostonly_cmdline_l="yes" ;;
--hostonly-i18n)
i18n_install_all_l="no" ;;
--hostonly-nics)
hostonly_nics_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
--no-hostonly-i18n)
i18n_install_all_l="yes" ;;
--no-hostonly-cmdline)
Expand Down Expand Up @@ -755,6 +760,7 @@ unset NPATH
(( ${#fstab_lines_l[@]} )) && fstab_lines+=( "${fstab_lines_l[@]}" )
(( ${#install_items_l[@]} )) && install_items+=" ${install_items_l[@]} "
(( ${#install_optional_items_l[@]} )) && install_optional_items+=" ${install_optional_items_l[@]} "
(( ${#hostonly_nics_l[@]} )) && hostonly_nics+=" ${hostonly_nics_l[@]} "

# these options override the stuff in the config file
(( ${#dracutmodules_l[@]} )) && dracutmodules="${dracutmodules_l[@]}"
Expand Down
18 changes: 15 additions & 3 deletions modules.d/90kernel-network-modules/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ depends() {
installkernel() {
# Include wired net drivers, excluding wireless
local _arch=${DRACUT_ARCH:-$(uname -m)}
local _net_drivers='eth_type_trans|register_virtio_device|usbnet_open'
local _net_symbols='eth_type_trans|register_virtio_device|usbnet_open'
local _unwanted_drivers='/(wireless|isdn|uwb|net/ethernet|net/phy|net/team)/'
local _net_drivers

if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
_s390drivers="=drivers/s390/net"
dracut_instmods -o -P ".*${_unwanted_drivers}.*" -s "$_net_symbols" "=drivers/s390/net"
fi

dracut_instmods -o -P ".*${_unwanted_drivers}.*" -s "$_net_drivers" "=drivers/net" ${_s390drivers:+"$_s390drivers"}
if [[ $hostonly_mode == 'strict' ]] && [[ $hostonly_nics ]]; then
for _nic in $hostonly_nics; do
_net_drivers=$(get_dev_module /sys/class/net/$_nic)
if ! [[ $_net_drivers ]]; then
derror "--hostonly-nics contains invalid NIC '$_nic'"
continue
fi
hostonly="" instmods $_net_drivers
done
return 0
fi

dracut_instmods -o -P ".*${_unwanted_drivers}.*" -s "$_net_symbols" "=drivers/net"
#instmods() will take care of hostonly
instmods \
=drivers/net/phy \
Expand Down

0 comments on commit 1e92f72

Please sign in to comment.