dracut: Make mkinintrd-dracut.sh SUSE mkinitrd compatible
Hi,
these patches implement most important SuSE specific /sbin/mkinitrd paramters:
<none> : Before gives a "usage" error -> now scans /boot for kernels
and builds corresponding inirtrds for them
-i -k : Pass a list of kernels and initrd targets
(not sure it was worth the hassle to be able to pass)
-b : Boot directory to search for kernel images
-d : Change root file system. Not tested whether dracut's behavior
matches exactly what our mkinitrd does.
If any of these parameters (including <none>) would have been called before, mkinitrd-dracut.sh would have bailed out with a "usage error" and an error code.
Or the other way around: Any valid mkinitrd-dracut.sh not resulting in an error, should work exactly the same way it did before.
Therefore I hope these can get in if the code is ok.
Thanks,
Thomas
[PATCH 1/6] mkinitrd-dracut.sh: Introduce -i -k parameters [PATCH 2/6] mkinitrd-dracut.sh: Enhance param parsing: Allow [PATCH 3/6] mkinitrd-dracut.sh: Implement --quiet|-q option [PATCH 4/6] mkinitrd-dracut.sh: Allow mkinitrd call without passing [PATCH 5/6] mkinitrd-dracut.sh: Also allow -d to specify the root_fs [PATCH 6/6] mkinitrd-dracut.sh: Build host images for
A message that is not in the archive (sent off-list or not yet received): 1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org
PATCH 1/6 mkinitrd-dracut.sh: Introduce -i -k parameters
In SUSE, one can pass a list of kernel files via -k parameter. For each an initrd is generated as passed via -i parameters.
Make the dracut mkinitrd wrapper compatible to those. For now only one kernel file and initrd target can be specified. This will get enhanced with a follow-up patch.
--- mkinitrd-dracut.sh | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 41 insertions(+), 9 deletions(-) mode change 100644 => 100755 mkinitrd-dracut.sh
mkinitrd-dracut.sh +41 -9
@@ -1,6 +1,8 @@ #!/bin/bash --norc kver=$(uname -r) +boot_dir="/boot" + error() { echo "$@" >&2; } usage () {
@@ -80,10 +82,27 @@ while (($# > 0)); do --looppath*) ;; --dsdt*) ;; --bootchart) ;; - *) if [[ ! $target ]]; then - target=$1 - elif [[ ! $kernel ]]; then - kernel=$1 + -b) read_arg boot_dir "$@" || shift + if [ ! -d $boot_dir ];then + error "Boot directory $boot_dir does not exist" + exit 1 + fi + ;; + -k) # Would be nice to get a list of images here + read_arg kernel_images "$@" || shift + for kernel_image in $kernel_images;do + kernels="$kernels ${kernel_image#*-}" + done + ;; + -i) read_arg initrd_images "$@" || shift + for initrd_image in $initrd_images;do + targets="$targets $boot_dir/$initrd_images" + done + ;; + *) if [[ ! $targets ]]; then + targets=$1 + elif [[ ! $kernels ]]; then + kernels=$1 else usage fi;;
@@ -91,11 +110,24 @@ while (($# > 0)); do shift done -[[ $target && $kernel ]] || usage -[[ $img_vers ]] && target="$target-$kernel" +[[ $targets && $kernels ]] || usage + +# We can have several targets/kernels, transform the list to an array +targets=( $targets ) +[[ $kernels ]] && kernels=( $kernels ) -if [[ $basicmodules ]]; then +for ((i=0 ; $i<${#targets[@]} ; i++)); do + + if [[ $img_vers ]];then + target="${targets[$i]}-${kernels[$i]}" + else + target="${targets[$i]}" + fi + kernel="${kernels[$i]}" + + if [[ $basicmodules ]]; then dracut $dracut_args --add-drivers "$basicmodules" "$target" "$kernel" -else + else dracut $dracut_args "$target" "$kernel" -fi + fi +done
Signature · 1 line
1.7.6.1
PATCH 2/6 mkinitrd-dracut.sh: Enhance param parsing: Allow multiple arguments per param
In reply to a message not in the archiveCurrently --with parameter had to be passed as: --with="mod1 mod2". Now one can pass: --with "mod1 mod2" or even --with mod1 mod2.
--- mkinitrd-dracut.sh | 43 +++++++++++++++++++++++++------------------ 1 files changed, 25 insertions(+), 18 deletions(-)
mkinitrd-dracut.sh +25 -18
@@ -26,36 +26,43 @@ read_arg() { # $1 = arg name # $2 = arg value # $3 = arg parameter - local rematch='^[^=]*=(.*)$' + param="$1" + local rematch='^[^=]*=(.*)$' result if [[ $2 =~ $rematch ]]; then - read "$1" <<< "${BASH_REMATCH[1]}" - elif [[ $3 != -* ]]; then - # Only read next arg if it not an arg itself. - read "$1" <<< "$3" - # There is no way to shift our callers args, so - # return 1 to indicate they should do it instead. - return 1 + read "$param" <<< "${BASH_REMATCH[1]}" + else + for ((i=3; $i <= $#; i++)); do + # Only read next arg if it not an arg itself. + if [[ ${@:$i:1} = -* ]];then + break + fi + result="$result ${@:$i:1}" + # There is no way to shift our callers args, so + # return "no of args" to indicate they should do it instead. + done + read "$1" <<< "$result" + return $(($i - 3)) fi } while (($# > 0)); do case ${1%%=*} in - --with-usb) read_arg usbmodule "$@" || shift + --with-usb) read_arg usbmodule "$@" || shift $? basicmodules="$basicmodules ${usbmodule:-usb-storage}" unset usbmodule;; - --with-avail) read_arg modname "$@" || shift + --with-avail) read_arg modname "$@" || shift $? basicmodules="$basicmodules $modname";; - --with) read_arg modname "$@" || shift + --with) read_arg modname "$@" || shift $? basicmodules="$basicmodules $modname";; --version) echo "mkinitrd: dracut compatibility wrapper" exit 0;; -v|--verbose) dracut_args="${dracut_args} -v";; -f|--force) dracut_args="${dracut_args} -f";; - --preload) read_arg modname "$@" || shift + --preload) read_arg modname "$@" || shift $? basicmodules="$basicmodules $modname";; --image-version) img_vers=yes;; - --rootfs) read_arg rootfs "$@" || shift + --rootfs) read_arg rootfs "$@" || shift $? dracut_args="${dracut_args} --filesystems $rootfs";; --nocompress) dracut_args="$dracut_args --no-compress";; --help) usage -n;;
@@ -82,24 +89,24 @@ while (($# > 0)); do --looppath*) ;; --dsdt*) ;; --bootchart) ;; - -b) read_arg boot_dir "$@" || shift + -b) read_arg boot_dir "$@" || shift $? if [ ! -d $boot_dir ];then error "Boot directory $boot_dir does not exist" exit 1 fi ;; -k) # Would be nice to get a list of images here - read_arg kernel_images "$@" || shift + read_arg kernel_images "$@" || shift $? for kernel_image in $kernel_images;do kernels="$kernels ${kernel_image#*-}" done ;; - -i) read_arg initrd_images "$@" || shift + -i) read_arg initrd_images "$@" || shift $? for initrd_image in $initrd_images;do - targets="$targets $boot_dir/$initrd_images" + targets="$targets $boot_dir/$initrd_image" done ;; - *) if [[ ! $targets ]]; then + *) if [[ ! $targets ]]; then targets=$1 elif [[ ! $kernels ]]; then kernels=$1
Signature · 1 line
1.7.6.1
PATCH 3/6 mkinitrd-dracut.sh: Implement --quiet|-q option
In reply to a message not in the archiveDracut is rather verbose. This optional parameter is to limit the output to the essential: For each generated initrd show the kernel, target and possibly additional options passed to dracut.
--- mkinitrd-dracut.sh | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-)
mkinitrd-dracut.sh +18 -3
@@ -2,6 +2,7 @@ kver=$(uname -r) boot_dir="/boot" +quiet=0 error() { echo "$@" >&2; }
@@ -89,6 +90,7 @@ while (($# > 0)); do --looppath*) ;; --dsdt*) ;; --bootchart) ;; + --quiet|-q) quiet=1;; -b) read_arg boot_dir "$@" || shift $? if [ ! -d $boot_dir ];then error "Boot directory $boot_dir does not exist"
@@ -123,6 +125,7 @@ done targets=( $targets ) [[ $kernels ]] && kernels=( $kernels ) +echo "Creating: target|kernel|dracut args|basicmodules " for ((i=0 ; $i<${#targets[@]} ; i++)); do if [[ $img_vers ]];then
@@ -132,9 +135,21 @@ for ((i=0 ; $i<${#targets[@]} ; i++)); do fi kernel="${kernels[$i]}" - if [[ $basicmodules ]]; then - dracut $dracut_args --add-drivers "$basicmodules" "$target" "$kernel" + # Duplicate code: No way found how to redirect output based on $quiet + if [[ $quiet == 1 ]];then + echo "$target|$kernel|$dracut_args|$basicmodules" + if [[ $basicmodules ]]; then + dracut $dracut_args --add-drivers "$basicmodules" "$target" \ + "$kernel" &>/dev/null + else + dracut $dracut_args "$target" "$kernel" &>/dev/null + fi else - dracut $dracut_args "$target" "$kernel" + if [[ $basicmodules ]]; then + dracut $dracut_args --add-drivers "$basicmodules" "$target" \ + "$kernel" + else + dracut $dracut_args "$target" "$kernel" + fi fi done
Signature · 1 line
1.7.6.1
PATCH 4/6 mkinitrd-dracut.sh: Allow mkinitrd call without passing any parameters
In reply to a message not in the archiveBefore this gave a "usage" error.
Now boot_dir (by default /boot) is scanned for available kernels and sane initrd default targets get defined and the corresponding initramfs files are generated.
--- mkinitrd-dracut.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 63 insertions(+), 1 deletions(-)
mkinitrd-dracut.sh +63 -1
@@ -46,6 +46,67 @@ read_arg() { fi } +# Taken over from SUSE mkinitrd +default_kernel_images() { + local regex kernel_image kernel_version version_version initrd_image + local qf='%{NAME}-%{VERSION}-%{RELEASE}\n' + + case "$(uname -m)" in + s390|s390x) + regex='image' + ;; + ppc|ppc64) + regex='vmlinux' + ;; + i386|x86_64) + regex='vmlinuz' + ;; + arm*) + regex='[uz]Image' + ;; + aarch64) + regex='Image' + ;; + *) regex='vmlinu.' + ;; + esac + + # user mode linux + if grep -q UML /proc/cpuinfo; then + regex='linux' + fi + + kernel_images="" + initrd_images="" + for kernel_image in $(ls $boot_dir \ + | sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \ + | grep -v kdump$ ) ; do + + # Note that we cannot check the RPM database here -- this + # script is itself called from within the binary kernel + # packages, and rpm does not allow recursive calls. + + [ -L "$boot_dir/$kernel_image" ] && continue + [ "${kernel_image%%.gz}" != "$kernel_image" ] && continue + kernel_version=$(/usr/bin/get_kernel_version \ + $boot_dir/$kernel_image 2> /dev/null) + initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|") + if [ "$kernel_image" != "$initrd_image" -a \ + -n "$kernel_version" -a \ + -d "/lib/modules/$kernel_version" ]; then + kernel_images="$kernel_images $boot_dir/$kernel_image" + initrd_images="$initrd_images $boot_dir/$initrd_image" + fi + done + for kernel_image in $kernel_images;do + kernels="$kernels ${kernel_image#*-}" + done + for initrd_image in $initrd_images;do + targets="$targets $initrd_image" + done + +} + while (($# > 0)); do case ${1%%=*} in --with-usb) read_arg usbmodule "$@" || shift $?
@@ -119,7 +180,8 @@ while (($# > 0)); do shift done -[[ $targets && $kernels ]] || usage +[[ $targets && $kernels ]] || default_kernel_images +[[ $targets && $kernels ]] || (error "No kernel found in $boot_dir" && usage) # We can have several targets/kernels, transform the list to an array targets=( $targets )
Signature · 1 line
1.7.6.1
PATCH 5/6 mkinitrd-dracut.sh: Also allow -d to specify the root_fs and -s dummy
In reply to a message not in the archive-d is the SUSE mkinitrd version option to pass the rootfs.
-s is to enable splash which may not be needed, but some callers rely on it, not to return an error.
Make this wrapper compatible to it.
--- mkinitrd-dracut.sh | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
mkinitrd-dracut.sh +2 -1
@@ -124,7 +124,7 @@ while (($# > 0)); do --preload) read_arg modname "$@" || shift $? basicmodules="$basicmodules $modname";; --image-version) img_vers=yes;; - --rootfs) read_arg rootfs "$@" || shift $? + --rootfs|-d) read_arg rootfs "$@" || shift $? dracut_args="${dracut_args} --filesystems $rootfs";; --nocompress) dracut_args="$dracut_args --no-compress";; --help) usage -n;;
@@ -151,6 +151,7 @@ while (($# > 0)); do --looppath*) ;; --dsdt*) ;; --bootchart) ;; + -s) ;; --quiet|-q) quiet=1;; -b) read_arg boot_dir "$@" || shift $? if [ ! -d $boot_dir ];then
Signature · 1 line
1.7.6.1
PATCH 6/6 mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths
In reply to a message not in the archivedefault_kernel_images and -i/-k paths are new (SuSE) code paths and would have resulted in usage errors before.
There we want to build host only images for faster building and smaller images.
Also force creation (overriding) of initrd images in these code paths.
--- mkinitrd-dracut.sh | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
mkinitrd-dracut.sh +11 -3
@@ -3,6 +3,8 @@ kver=$(uname -r) boot_dir="/boot" quiet=0 +host_only=0 +force=0 error() { echo "$@" >&2; }
@@ -104,7 +106,8 @@ default_kernel_images() { for initrd_image in $initrd_images;do targets="$targets $initrd_image" done - + host_only=1 + force=1 } while (($# > 0)); do
@@ -119,8 +122,8 @@ while (($# > 0)); do --version) echo "mkinitrd: dracut compatibility wrapper" exit 0;; - -v|--verbose) dracut_args="${dracut_args} -v";; - -f|--force) dracut_args="${dracut_args} -f";; + -v|--verbose) dracut_args="${dracut_args} -v --keep";; + -f|--force) force=1;; --preload) read_arg modname "$@" || shift $? basicmodules="$basicmodules $modname";; --image-version) img_vers=yes;;
@@ -164,6 +167,8 @@ while (($# > 0)); do for kernel_image in $kernel_images;do kernels="$kernels ${kernel_image#*-}" done + host_only=1 + force=1 ;; -i) read_arg initrd_images "$@" || shift $? for initrd_image in $initrd_images;do
@@ -188,6 +193,9 @@ done targets=( $targets ) [[ $kernels ]] && kernels=( $kernels ) +[[ $host_only == 1 ]] && dracut_args="${dracut_args} -H" +[[ $force == 1 ]] && dracut_args="${dracut_args} -f" + echo "Creating: target|kernel|dracut args|basicmodules " for ((i=0 ; $i<${#targets[@]} ; i++)); do
Signature · 1 line
1.7.6.1
A message that is not in the archive (sent off-list or not yet received): 1380305940-64410-7-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org
Re: [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths
Quoted 36 lines · Thomas Renninger
default_kernel_imagesand -i/-k paths are new (SuSE) code paths and would have resulted in usage errors before.There we want to build host only images for faster building and smaller images.
Also force creation (overriding) of initrd images in these code paths.Signed-off-by Thomas Renninger <[email protected]>--- mkinitrd-dracut.sh | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)mkinitrd-dracut.sh +4
-1@@ -3,6 +3,8 @@ kver=$(uname -r) boot_dir="/boot" quiet=0 +host_only=0 +force=0 error() { echo "$@" >&2; }@@ -104,7 +106,8 @@ default_kernel_images() { for initrd_image in $initrd_images;do targets="$targets $initrd_image" done - + host_only=1 + force=1 } while (($# > 0)); do
mkinitrd-dracut.sh while (($# > 0)); do · line 125
Quoted 6 lines
mkinitrd-dracut.sh +1
-2@@ -119,8 +122,8 @@ while (($# > 0)); do --version) echo "mkinitrd: dracut compatibility wrapper" exit 0;; - -v|--verbose) dracut_args="${dracut_args} -v";; - -f|--force) dracut_args="${dracut_args} -f";; + -v|--verbose) dracut_args="${dracut_args} -v --keep";;
do you really want to keep the entire files in /var/tmp/<tmpdir> for --verbose?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths
Quoted 1 line · Harald Hoyer
On 09/27/2013 08:19 PM, Thomas Renninger wrote:
...
Quoted 7 lines
Quoted 7 lines
mkinitrd-dracut.sh +0
-0@@ -119,8 +122,8 @@ while (($# > 0)); do --version) echo "mkinitrd: dracut compatibility wrapper" exit 0;;
Quoted 6 lines
mkinitrd-dracut.sh while (($# > 0)); do · line 125
Quoted 3 lines
mkinitrd-dracut.sh +1
-2- -v|--verbose) dracut_args="${dracut_args} -v";; - -f|--force) dracut_args="${dracut_args} -f";; + -v|--verbose) dracut_args="${dracut_args} -v --keep";;do you really want to keep the entire files in /var/tmp/<tmpdir> for --verbose?
No, that was not intended.
What about the rest? If it is ok, I would re-post this series.
Thanks,
Thomas
Re: [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths
Quoted 16 lines · Thomas Renninger
Quoted 1 line · Harald Hoyer
On 09/27/2013 08:19 PM, Thomas Renninger wrote:
...
Quoted 7 lines
Quoted 7 lines
mkinitrd-dracut.sh +0
-0@@ -119,8 +122,8 @@ while (($# > 0)); do --version) echo "mkinitrd: dracut compatibility wrapper" exit 0;;Quoted 6 lines
mkinitrd-dracut.sh while (($# > 0)); do · line 125
Quoted 3 lines
mkinitrd-dracut.sh +1
-2- -v|--verbose) dracut_args="${dracut_args} -v";; - -f|--force) dracut_args="${dracut_args} -f";; + -v|--verbose) dracut_args="${dracut_args} -v --keep";;do you really want to keep the entire files in /var/tmp/<tmpdir> for --verbose?
Quoted 6 lines
No, that was not intended.
What about the rest? If it is ok, I would re-post this series.Thanks,
Thomas
Pushed all + removed the "--keep"