]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
add dracut-catimages
authorHarald Hoyer <harald@redhat.com>
Fri, 24 Jul 2009 11:14:52 +0000 (13:14 +0200)
committerHarald Hoyer <harald@redhat.com>
Sat, 25 Jul 2009 09:09:35 +0000 (11:09 +0200)
Usage: ./dracut-catimages [OPTION]... <initramfs> <base image>
[<image>...]
Creates initial ramdisk image by concatenating several images from the
command
line and /boot/dracut/

  -f, --force           Overwrite existing initramfs file.
  -i, --imagedir        Directory with additional images to add
                        (default: /boot/dracut/)
  -o, --overlaydir      Overlay directory, which contains files that
                        will be used to create an additional image
  --nooverlay           Do not use the overlay directory
  --noimagedir          Do not use the additional image directory
  -h, --help            This message
  --debug               Output debug information of the build process
  -v, --verbose         Verbose output during the build process

Makefile
dracut-catimages [new file with mode: 0755]

index 12770e2d862949a78e3f33e4edba75265da9dcea..af0a4f00e02d0ff0dd569fc776e42062b49bafa0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ install:
        mkdir -p $(DESTDIR)$(mandir)/man8
        install -m 0755 dracut $(DESTDIR)$(sbindir)/dracut
        install -m 0755 dracut-gencmdline $(DESTDIR)$(sbindir)/dracut-gencmdline
+       install -m 0755 dracut-catimages $(DESTDIR)$(sbindir)/dracut-catimages
        install -m 0755 modules.d/99base/switch_root $(DESTDIR)$(sbindir)/switch_root
        install -m 0644 dracut.conf $(DESTDIR)$(sysconfdir)/dracut.conf
        install -m 0755 dracut-functions $(DESTDIR)$(pkglibdir)/dracut-functions
diff --git a/dracut-catimages b/dracut-catimages
new file mode 100755 (executable)
index 0000000..66b03fe
--- /dev/null
@@ -0,0 +1,124 @@
+#!/bin/bash --norc
+
+# Copyright 2009 Red Hat, Inc.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+dwarning() {
+    echo "Warning: $@" >&2
+}
+
+dinfo() {
+    [[ $beverbose ]] && echo "$@" >&2
+}
+
+derror() {
+    echo "Error: $@" >&2
+}
+
+usage() {
+#                                                       80x25 linebreak here ^
+       echo "Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
+Creates initial ramdisk image by concatenating several images from the command
+line and /boot/dracut/
+
+  -f, --force           Overwrite existing initramfs file.
+  -i, --imagedir        Directory with additional images to add 
+                        (default: /boot/dracut/)
+  -o, --overlaydir      Overlay directory, which contains files that
+                        will be used to create an additional image
+  --nooverlay           Do not use the overlay directory
+  --noimagedir          Do not use the additional image directory
+  -h, --help            This message
+  --debug               Output debug information of the build process
+  -v, --verbose         Verbose output during the build process
+"
+}
+
+
+imagedir=/boot/dracut/
+overlay=/var/lib/dracut/overlay
+
+while (($# > 0)); do
+    case $1 in
+       -f|--force) force=yes;;
+       -i|--imagedir) imagedir=$2;shift;;
+       -o|--overlaydir) overlay=$2;shift;;
+       --nooverlay) no_overlay=yes;shift;;
+       --noimagedir) no_imagedir=yes;shift;;
+       -h|--help) usage; exit 1 ;;
+       --debug) debug="yes";;
+       -v|--verbose) beverbose="yes";;
+       -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
+       *) break ;;
+    esac
+    shift
+done
+
+outfile=$1; shift
+
+if [ -z "$outfile" ]; then
+    derror "No output file specified."
+    usage
+    exit 1
+fi
+
+baseimage=$1; shift
+
+if [ -z "$baseimage" ]; then
+    derror "No base image specified."
+    usage
+    exit 1
+fi
+
+if [ -f $outfile -a -z "$force" ]; then
+    derror "Will not override existing initramfs ($outfile) without --force"
+    exit 1
+fi
+
+if [ -z "$no_imagedir" -a ! -d "$imagedir" ]; then
+    derror "Image directory $overlay is not a directory"
+    exit 1
+fi
+
+if [ -z "$no_overlay" -a ! -d "$overlay" ]; then
+    derror "Overlay $overlay is not a directory"
+    exit 1
+fi
+
+if [ -z "$no_overlay" ]; then
+    ofile="$imagedir/90-overlay.img"
+    dinfo "Creating image $ofile from directory $overlay"
+    ( cd "$overlay"; find . |cpio --quiet -H newc -o  |gzip -9 > "$ofile"; )
+fi
+
+if [ -z "$no_imagedir" ]; then
+    images=$(for i in $imagedir/*.img;do [ -f $i ] || continue; echo $i; done)
+fi
+
+images="$images $@"
+
+dinfo "Using base image $baseimage"
+cat $baseimage > $outfile
+
+for i in $images; do 
+    dinfo "Appending $i"
+    cat $i >> $outfile
+done
+
+dinfo "Created $outfile"
+
+exit 0