From: Harald Hoyer Date: Fri, 24 Jul 2009 11:14:52 +0000 (+0200) Subject: add dracut-catimages X-Git-Tag: 0.7~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5494f08cc526bb06552cfc7d67ce9b2f81c326c6;p=thirdparty%2Fdracut.git add dracut-catimages Usage: ./dracut-catimages [OPTION]... [...] 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 --- diff --git a/Makefile b/Makefile index 12770e2d8..af0a4f00e 100644 --- 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 index 000000000..66b03fe68 --- /dev/null +++ b/dracut-catimages @@ -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 . +# + + +dwarning() { + echo "Warning: $@" >&2 +} + +dinfo() { + [[ $beverbose ]] && echo "$@" >&2 +} + +derror() { + echo "Error: $@" >&2 +} + +usage() { +# 80x25 linebreak here ^ + echo "Usage: $0 [OPTION]... [...] +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