From 83bb0893edc1c12bbaca20267134b01df2836e1c Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 13 Mar 2013 14:47:24 +0100 Subject: [PATCH] dracut.sh: Add --noimageifnotneeded parameter Do not create an image in host-only mode, if no kernel driver is needed and no $initdir/etc/cmdline/*.conf is generated. --- 50-dracut.install | 19 ++++++++++++++++++- dracut-bash-completion.sh | 2 +- dracut.sh | 12 ++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/50-dracut.install b/50-dracut.install index 9e99899..6b63da9 100755 --- a/50-dracut.install +++ b/50-dracut.install @@ -2,10 +2,27 @@ # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh +if [[ -f /etc/kernel/cmdline ]]; then + readarray -t BOOT_OPTIONS < /etc/kernel/cmdline +fi + +if ! [[ "${BOOT_OPTIONS[@]}" ]]; then + readarray -t BOOT_OPTIONS < /proc/cmdline +fi + +unset noimageifnotneeded + +for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do + if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then + noimageifnotneeded="yes" + break + fi +done + ret=0 case "$1" in add) - dracut "$3"/initrd "$2" + dracut ${noimageifnotneeded+--noimageifnotneeded} "$3"/initrd "$2" ret=$? ;; remove) diff --git a/dracut-bash-completion.sh b/dracut-bash-completion.sh index da067c5..38e2ebd 100644 --- a/dracut-bash-completion.sh +++ b/dracut-bash-completion.sh @@ -33,7 +33,7 @@ _dracut() { --lvmconf --nolvmconf --debug --profile --verbose --quiet --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma --xz --no-compress --gzip --list-modules --show-modules --keep - --printsize --regenerate-all' + --printsize --regenerate-all --noimageifnotneeded' [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers --omit-drivers --modules --omit --drivers --filesystems --install diff --git a/dracut.sh b/dracut.sh index 2582f74..69f5282 100755 --- a/dracut.sh +++ b/dracut.sh @@ -330,6 +330,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \ --long keep \ --long printsize \ --long regenerate-all \ + --long noimageifnotneeded \ -- "$@") if (( $? != 0 )); then @@ -408,6 +409,7 @@ while :; do --keep) keep="yes";; --printsize) printsize="yes";; --regenerate-all) regenerate_all="yes";; + --noimageifnotneeded) noimageifnotneeded="yes";; --) shift; break;; @@ -1020,6 +1022,16 @@ if [[ $no_kernel != yes ]]; then dinfo "*** Installing kernel module dependencies and firmware ***" dracut_kernel_post dinfo "*** Installing kernel module dependencies and firmware done ***" + + if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then + if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \ + [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then + for i in ${initdir}/etc/cmdline.d/*.conf; do + # We need no initramfs image and do not generate one. + [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0 + done + fi + fi fi if [[ $kernel_only != yes ]]; then -- 2.7.4