* [PATCH 1/6] mkinitrd-dracut.sh: Introduce -i -k parameters
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
@ 2013-09-27 18:18 ` Thomas Renninger
2013-09-27 18:18 ` [PATCH 2/6] mkinitrd-dracut.sh: Enhance param parsing: Allow multiple arguments per param Thomas Renninger
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:18 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
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.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 50 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 41 insertions(+), 9 deletions(-)
mode change 100644 => 100755 mkinitrd-dracut.sh
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
old mode 100644
new mode 100755
index ffea2d1..ace7725
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/6] mkinitrd-dracut.sh: Enhance param parsing: Allow multiple arguments per param
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2013-09-27 18:18 ` [PATCH 1/6] mkinitrd-dracut.sh: Introduce -i -k parameters Thomas Renninger
@ 2013-09-27 18:18 ` Thomas Renninger
2013-09-27 18:18 ` [PATCH 3/6] mkinitrd-dracut.sh: Implement --quiet|-q option Thomas Renninger
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:18 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
Currently --with parameter had to be passed as: --with="mod1 mod2".
Now one can pass: --with "mod1 mod2" or even --with mod1 mod2.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 43 +++++++++++++++++++++++++------------------
1 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
index ace7725..d8e92f3 100755
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/6] mkinitrd-dracut.sh: Implement --quiet|-q option
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
2013-09-27 18:18 ` [PATCH 1/6] mkinitrd-dracut.sh: Introduce -i -k parameters Thomas Renninger
2013-09-27 18:18 ` [PATCH 2/6] mkinitrd-dracut.sh: Enhance param parsing: Allow multiple arguments per param Thomas Renninger
@ 2013-09-27 18:18 ` Thomas Renninger
2013-09-27 18:18 ` [PATCH 4/6] mkinitrd-dracut.sh: Allow mkinitrd call without passing any parameters Thomas Renninger
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:18 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
Dracut 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.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
index d8e92f3..803abc0 100755
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/6] mkinitrd-dracut.sh: Allow mkinitrd call without passing any parameters
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
` (2 preceding siblings ...)
2013-09-27 18:18 ` [PATCH 3/6] mkinitrd-dracut.sh: Implement --quiet|-q option Thomas Renninger
@ 2013-09-27 18:18 ` Thomas Renninger
2013-09-27 18:18 ` [PATCH 5/6] mkinitrd-dracut.sh: Also allow -d to specify the root_fs and -s dummy Thomas Renninger
2013-09-27 18:19 ` [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths Thomas Renninger
5 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:18 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
Before 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.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
index 803abc0..eeb6dda 100755
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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 )
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/6] mkinitrd-dracut.sh: Also allow -d to specify the root_fs and -s dummy
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
` (3 preceding siblings ...)
2013-09-27 18:18 ` [PATCH 4/6] mkinitrd-dracut.sh: Allow mkinitrd call without passing any parameters Thomas Renninger
@ 2013-09-27 18:18 ` Thomas Renninger
2013-09-27 18:19 ` [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths Thomas Renninger
5 siblings, 0 replies; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:18 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
-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.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
index eeb6dda..f7b53f1 100755
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 6/6] mkinitrd-dracut.sh: Build host images for default_kernel_images and -i/-k paths
[not found] ` <1380305940-64410-1-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
` (4 preceding siblings ...)
2013-09-27 18:18 ` [PATCH 5/6] mkinitrd-dracut.sh: Also allow -d to specify the root_fs and -s dummy Thomas Renninger
@ 2013-09-27 18:19 ` Thomas Renninger
[not found] ` <1380305940-64410-7-git-send-email-trenn-l3A5Bk7waGM@public.gmane.org>
5 siblings, 1 reply; 10+ messages in thread
From: Thomas Renninger @ 2013-09-27 18:19 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA, Thomas Renninger
default_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.
Signed-off-by: Thomas Renninger <trenn-l3A5Bk7waGM@public.gmane.org>
---
mkinitrd-dracut.sh | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/mkinitrd-dracut.sh b/mkinitrd-dracut.sh
index f7b53f1..a1519ea 100755
--- a/mkinitrd-dracut.sh
+++ b/mkinitrd-dracut.sh
@@ -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
--
1.7.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread