From 6377c723aa23cc272eb148c9038fae4f037bc540 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Fri, 30 Jan 2015 13:50:49 -0600 Subject: [PATCH] Allow elements to add drivers to dracut It is reasonable that elements may need to include additional kernel modules in a dracut ramdisk. This is done with the --add-drivers option to dracut, but previously the value passed was hard-coded. This change allows an element to put a file containing its desired drivers in a dracut-drivers.d directory, and the list there will be added to the list of drivers added. This functions in essentially the same way as the binary-deps.d directory that already exists for including additional executables in a ramdisk. Change-Id: Ie892b908d36c175a469f7cde7dd803ad4b1942b6 --- elements/dracut-ramdisk/README.rst | 12 ++++++++ .../dracut-drivers.d/base-drivers | 3 ++ .../post-install.d/01-ensure-drivers | 29 +++++++++++++++++++ .../post-install.d/99-build-dracut-ramdisk | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 elements/dracut-ramdisk/dracut-drivers.d/base-drivers create mode 100755 elements/dracut-ramdisk/post-install.d/01-ensure-drivers diff --git a/elements/dracut-ramdisk/README.rst b/elements/dracut-ramdisk/README.rst index 8a759ff7..3597dd27 100644 --- a/elements/dracut-ramdisk/README.rst +++ b/elements/dracut-ramdisk/README.rst @@ -6,3 +6,15 @@ Build Dracut-based ramdisks This is an alternative to the `ramdisk` element that uses Dracut to provide the base system functionality instead of Busybox. + +For elements that need additional drivers in the ramdisk image, +a dracut-drivers.d feature is included that works in a similar +fashion to the binary-deps.d feature. The element needing to +add drivers should create a dracut-drivers.d directory and +populate it with a single file listing all of the kernel modules +it needs added to the ramdisk. Comments are not supported in this +file. Note that these modules must be installed in the chroot first. + +By default, the virtio, virtio_net, and virtio_blk modules are +included so that ramdisks are able to function properly in a +virtualized environment. diff --git a/elements/dracut-ramdisk/dracut-drivers.d/base-drivers b/elements/dracut-ramdisk/dracut-drivers.d/base-drivers new file mode 100644 index 00000000..b9ac2b5d --- /dev/null +++ b/elements/dracut-ramdisk/dracut-drivers.d/base-drivers @@ -0,0 +1,3 @@ +virtio +virtio_net +virtio_blk diff --git a/elements/dracut-ramdisk/post-install.d/01-ensure-drivers b/elements/dracut-ramdisk/post-install.d/01-ensure-drivers new file mode 100755 index 00000000..160b4cfc --- /dev/null +++ b/elements/dracut-ramdisk/post-install.d/01-ensure-drivers @@ -0,0 +1,29 @@ +#!/bin/bash + +set -eu +set -o pipefail + +if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then + set -x +fi + +TARGET_DIR="/tmp/in_target.d/" + +EXTRA_DRIVERS= + +for _FILE in $(ls ${TARGET_DIR}/dracut-drivers.d/) ; do + _FILE="${TARGET_DIR}/dracut-drivers.d/${_FILE}" + if [ -s $_FILE ]; then + for _LINE in $(cat $_FILE) ; do + EXTRA_DRIVERS="${EXTRA_DRIVERS} $_LINE" + done + fi +done + +if [ "$EXTRA_DRIVERS" = "" ]; then + echo "No extra drivers found" +else + DRIVERS_OUTPUT="/etc/dib_dracut_drivers" + echo "Creating extra drivers record at: ${DRIVERS_OUTPUT}" + echo "$EXTRA_DRIVERS" >${DRIVERS_OUTPUT} +fi diff --git a/elements/dracut-ramdisk/post-install.d/99-build-dracut-ramdisk b/elements/dracut-ramdisk/post-install.d/99-build-dracut-ramdisk index 8033ac35..a4ef693a 100755 --- a/elements/dracut-ramdisk/post-install.d/99-build-dracut-ramdisk +++ b/elements/dracut-ramdisk/post-install.d/99-build-dracut-ramdisk @@ -66,7 +66,7 @@ dracut -N \ --kernel-cmdline "rd.shell rd.debug rd.neednet=1 rd.driver.pre=ahci" \ --include "$TMP_MOUNT_PATH/" / \ --kver "${KERNEL_VERSION}" \ - --add-drivers "virtio virtio_net virtio_blk" \ + --add-drivers "$(cat /etc/dib_dracut_drivers)" \ -o "dash plymouth" \ /tmp/ramdisk