[readonly/geninitrd/BUSYBOX: 1/113] Initial revision

draenog draenog at pld-linux.org
Sat Nov 2 19:10:06 CET 2013


commit bb529f94f115f82ca4491ef7cc237ab33f6ff29f
Author: Jacek Konieczny <jajcus at pld-linux.org>
Date:   Thu Nov 9 09:26:54 2000 +0000

    Initial revision
    
    
    svn-id: @1152

 Makefile            |  20 +++
 TODO                |   1 +
 geninitrd           | 442 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 geninitrd.8         | 118 ++++++++++++++
 geninitrd.sysconfig |  17 ++
 5 files changed, 598 insertions(+)
---
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..fcefc18
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,20 @@
+VERSION=1.0
+FILES=Makefile geninitrd.sysconfig geninitrd geninitrd.8
+
+mandir=/usr/share/man
+sysconfdir=/etc/sysconfig
+
+install:
+	install -d $(BUILDROOT)/{sbin,$(mandir)/man8,$(sysconfdir)}
+	sed 's/%VERSIONTAG%/$(VERSION)/' < geninitrd > $(BUILDROOT)/sbin/geninitrd
+	chmod 755 $(BUILDROOT)/sbin/geninitrd
+	install -m644 geninitrd.8 $(BUILDROOT)/$(mandir)/man8/geninitrd.8
+	install -m644 geninitrd.sysconfig $(BUILDROOT)/$(sysconfdir)/geninitrd
+
+release:
+	-rm -f *.tar.gz
+	-rm -rf geninitrd-$(VERSION)
+	mkdir geninitrd-$(VERSION)
+	cp $(FILES)  geninitrd-$(VERSION)
+	tar czvf geninitrd-$(VERSION).tar.gz geninitrd-$(VERSION)
+	-rm -rf geninitrd-$(VERSION)
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..8c9a72c
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+- change all "sed" and "grep" into "awk"
diff --git a/geninitrd b/geninitrd
new file mode 100755
index 0000000..7a0d8d4
--- /dev/null
+++ b/geninitrd
@@ -0,0 +1,442 @@
+#!/bin/sh
+
+# geninitrd
+#
+#	by Jacek Konieczny <jajcus at pld.org.pl>
+#
+# based on geninitrd written by Erik Troan <ewt at redhat.com>
+# and contributors:
+#	Elliot Lee <sopwith at cuc.edu>
+#	Miguel de Icaza <miguel at nuclecu.unam.mx>
+#	Christian 'Dr. Disk' Hechelmann <drdisk at ds9.au.s.shuttle.de>
+#	Michael K. Johnson <johnsonm at redhat.com>
+#	Pierre Habraken <Pierre.Habraken at ujf-grenoble.fr>
+#	Jakub Jelinek <jj at ultra.linux.cz>
+#	Carlo Arenas Belon (carenas at chasqui.lared.net.pe>
+#
+PATH=/sbin:$PATH
+export PATH
+
+VERSION=%VERSIONTAG%
+
+. /etc/rc.d/init.d/functions
+
+COMPRESS="yes"
+FS="rom"
+PROBESCSI="yes"
+PROBEIDE="yes"
+PROBERAID="yes"
+
+if [ -f /etc/sysconfig/initrd ] ; then
+	. /etc/sysconfig/initrd
+fi
+
+target=""
+kernel=""
+force=""
+verbose=""
+MODULES=""
+img_vers=""
+modulefile=/etc/modules.conf
+if [ `uname -m` = "ia64" ]; then
+  IMAGESIZE=3000
+else
+  IMAGESIZE=1500
+fi
+PRESCSIMODS="scsi_mod sd_mod unknown"
+PREIDEMODS="ide-mod ide-probe-mod ide-disk"
+fstab="/etc/fstab"
+
+usage () {
+    echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]" >&2
+    echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-ide-modules] [--with=<module>]" >&2
+    echo "       [--image-version] [--fstab=<fstab>] [--nocompress] [--fs=rom|ext2]" >&2
+    echo "       <initrd-image> <kernel-version>" >&2
+    echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" >&2
+    exit 1
+}
+
+findmodule() {
+    skiperrors=""
+    modName=$2
+    if [ $(echo $modName | cut -b1) = "-" ]; then
+	skiperrors=1
+	modName=$(echo $modName | cut -b2-)
+    fi
+
+    if [ "$modName" = "pluto" ]; then
+	findmodule "" fc4
+	findmodule "" soc
+    fi
+    if [ "$modName" = "fcal" ]; then
+	findmodule "" fc4
+	findmodule "" socal
+    fi
+    if [ -n "$1" ]; then
+	fmPath="$1"/"$modName".o
+    else
+	fmPath=`(cd /lib/modules/$kernel; echo */$modName.o)`
+    fi
+
+    if [ "$1" = "fs" ] && [ ! -f /lib/modules/$kernel/$fmPath ]; then
+	fmPath="$1"/"${modName}fs".o
+    fi
+
+    if [ ! -f /lib/modules/$kernel/$fmPath ]; then
+	if [ -n "$skiperrors" ]; then
+	    return
+	fi
+
+        # ignore the absence of the scsi modules
+	for n in $PRESCSIMODS; do
+	    if [ "$n" = "$modName" ]; then
+		return;
+	    fi
+	done;
+    
+        # ignore the absence of the ide modules
+	for n in $PREIDEMODS; do
+	    if [ "$n" = "$modName" ]; then
+		return;
+	    fi
+	done;
+    
+	echo "No module $modName found for kernel $kernel" >&2
+	exit 1
+    fi
+
+    # only need to add each module once
+    if echo $MODULES | grep $fmPath >/dev/null 2>&1 ; then : ; else
+	MODULES="$MODULES $fmPath"
+    fi
+}
+
+inst() {
+    if [ "$#" != "2" ];then
+        echo "usage: inst <file> <destination>"
+        return
+    fi 
+    [ -n "$verbose" ] && echo "$1 -> $2"
+    cp $1 $2
+}
+
+
+while [ $# -gt 0 ]; do
+    case $1 in
+	--fstab*)
+	    if echo $1 | grep '=' >/dev/null ; then
+	    	fstab=`echo $1 | sed 's/^--with=//'`
+	    else
+		fstab=$2
+		shift
+	    fi		    
+	    ;;
+
+	--with*)
+	    if echo $1 | grep '=' >/dev/null ; then
+	    	modname=`echo $1 | sed 's/^--with=//'`
+	    else
+		modname=$2
+		shift
+	    fi		    
+
+	    BASICMODULES="$BASICMODULES $modname"
+	    ;;
+
+	--version)
+	    echo "geninitrd: version $VERSION"
+	    exit 0
+	    ;;
+
+	-v)
+	    verbose=-v
+	    ;;
+
+	--nocompress)
+	    COMPRESS="no"
+	    ;;
+
+	--ifneeded)
+	    ifneeded=1
+	    ;;
+
+	-f)
+	    force=1
+	    ;;
+	--preload)
+	    if echo $1 | grep '=' >/dev/null ; then
+	    	modname=`echo $1 | sed 's/^--preload=//'`
+	    else
+		modname=$2
+		shift
+	    fi		    
+	    PREMODS="$PREMODS $modname"
+	    ;;
+	--omit-scsi-modules)
+	    PRESCSIMODS=""
+	    PROBESCSI="no";
+	    ;;
+	--omit-raid-modules)
+	    PROBERAID="no";
+	    ;;
+	--omit-ide-modules)
+	    PROBEIDE="no";
+	    ;;
+	--with-fs)
+	    if echo $1 | grep '=' >/dev/null ; then
+	    	FS=`echo $1 | sed 's/^--fs=//'`
+	    else
+		FS=$2
+		shift
+	    fi		    
+	    ;;
+	--image-version)
+	    img_vers=yes
+	    ;;
+	*)
+	    if [ -z "$target" ]; then
+		target=$1
+	    elif [ -z "$kernel" ]; then
+		kernel=$1
+	    else
+		usage
+	    fi
+	    ;;
+    esac
+
+    shift
+done
+
+if [ "$FS" != "ext2" -a "$FS" != "rom" ] ; then
+    echo "Only ext2 and rom fs are supported!"
+fi
+
+if [ -z "$target" -o -z "$kernel" ]; then
+    usage
+fi
+
+if [ -n "$img_vers" ]; then
+    target="$target-$kernel"
+fi
+
+if [ -z "$force" -a -f $target ]; then
+    echo "$target already exists." >&2
+    exit 1
+fi
+
+if [ ! -d /lib/modules/$kernel ]; then
+    echo "/lib/modules/$kernel is not a directory." >&2
+    exit 1
+fi
+
+for n in $PREMODS; do
+	findmodule "" $n
+done
+
+rootdev=$(awk '{ if ($2 == "/") { print $1; }}' $fstab)
+if is_yes "$PROBSCSI" && echo "$rootdev" | grep -q "^/dev/sd" ; then
+
+    for n in $PRESCSIMODS; do
+	    findmodule scsi $n
+    done
+
+    if [ ! -f $modulefile ]; then
+        modulefile=/etc/conf.modules
+    fi
+    if [ -f $modulefile ]; then
+	scsimodules=`grep scsi_hostadapter $modulefile | grep -v '^[ 	]*#' | LC_ALL=C sort -u | awk '{ print $3 }'`
+	for n in $scsimodules; do
+    # for now allow scsi modules to come from anywhere.  There are some
+    # RAID controllers with drivers in block/
+	    findmodule "" $n
+	done
+    fi
+fi
+
+if is_yes "$PROBEIDE" && echo "$rootdev" | grep -q "^/dev/hd" ; then
+    for n in $PREIDEMODS; do
+	    findmodule block $n
+    done
+fi
+
+if is_yes "$PROBERAID" ; then
+    # load appropriate raid devices if necessary
+    if grep '^/dev/md' $fstab | grep -v noauto >/dev/null 2>&1 ; then
+	for number in $(grep '^[ 	]*raid-level' /etc/raidtab |
+			  awk '{print $2}' | LC_ALL=C sort -u) ; do
+	    case $number in
+	    [0145])
+		findmodule "" raid$number
+		;;
+	    *)
+		echo "raid level $number (in /etc/raidtab) not recognized" >&2
+		;;
+	    esac
+	done
+    fi
+fi
+
+# check to see if we need to set up a loopback filesystem
+if echo $rootdev | cut -d/ -f3 | grep loop >/dev/null; then
+    key="^# $(echo $rootdev | cut -d/ -f3 | tr '[a-z]' '[A-Z]'):"
+    if ! grep "$key" $fstab > /dev/null; then
+	echo "The root filesystem is on a $rootdev, but there is no magic entry in $fstab" 1>&2
+	echo "for this device. Consult the geninitrd man page for more information" 2>&2
+	exit 1
+    fi
+
+    line=$(grep "$key" $fstab)
+    loopDev=$(echo $line | awk '{print $3}')
+    loopFs=$(echo $line | awk '{print $4}')
+    loopFile=$(echo $line | awk '{print $5}')
+
+    BASICMODULES="$BASICMODULES -loop"
+    findmodule fs "-$loopFs"
+    BASICMODULES="$BASICMODULES -${loopFs}"
+else # Check for other filesystems
+    rootFs=`awk '{if ($2 == "/") {print $3}}' $fstab`
+    findmodule fs "-$rootFs"
+fi
+
+for n in $BASICMODULES; do 
+    findmodule "" $n
+done
+
+if [ -n "$ifneeded" -a -z "$MODULES" ]; then
+    if [ -n "$verbose" ]; then
+	echo "No modules are needed -- not building initrd image."
+    fi
+    exit 0
+fi
+
+if [ -n "$verbose" ]; then
+    echo "Using modules: $MODULES"
+fi
+
+MNTIMAGE=/tmp/initrd.$$
+IMAGE=/tmp/initrd.img-$$
+MNTPOINT=/tmp/initrd.mnt-$$
+RCFILE=$MNTIMAGE/linuxrc
+
+if [ -f $MNTIMAGE ]; then
+    echo "$MNTIMAGE already exists.  Remove it and try again" >&2
+    exit 1
+fi
+
+if [ -f $IMAGE ]; then
+    echo "$IMAGE already exists. Remove it and try again" >&2
+    exit 1
+fi
+
+if [ "$FS" = "ext2" ] ; then
+	dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGESIZE 2> /dev/null
+
+	if [ -e /dev/.devfsd ]; then
+		LOOPDEV=/dev/loop/
+	else
+		LOOPDEV=/dev/loop
+	fi
+
+	for devnum in 0 1 2 3 4 5 6 7 8; do
+	    if losetup ${LOOPDEV}${devnum} $IMAGE 2>/dev/null ; then break; fi
+	done
+
+	if [ "$devnum" = "8" ]; then
+	    rm -rf $MNTPOINT $IMAGE
+	    echo "All of your loopback devices are in use!" >&2
+	    exit 1
+	fi
+
+	LODEV=${LOOPDEV}${devnum}
+
+	# We have to "echo y |" so that it doesn't complain about $IMAGE not
+	# being a block device
+	echo y | mke2fs $LODEV $IMAGESIZE >/dev/null 2>/dev/null
+
+	if [ -n "$verbose" ]; then
+	    echo "Using loopback device $LODEV"
+	fi
+
+	mkdir -p $MNTPOINT
+	mount -t ext2 $LODEV $MNTPOINT || {
+		echo "Can't get a loopback device"
+		exit 1
+	}
+else
+	mkdir -p $MNTPOINT
+fi
+
+mkdir -p $MNTIMAGE
+mkdir -p $MNTIMAGE/lib
+mkdir -p $MNTIMAGE/bin
+mkdir -p $MNTIMAGE/etc
+mkdir -p $MNTIMAGE/dev
+mkdir -p $MNTIMAGE/loopfs
+
+# We don't need this directory, so let's save space
+rm -rf $MNTPOINT/lost+found
+
+inst /bin/ash.static "$MNTIMAGE/bin/sh"
+inst /sbin/insmod.static "$MNTIMAGE/bin/insmod"
+
+for MODULE in $MODULES; do
+    cp $verbose -a /lib/modules/$kernel/$MODULE $MNTIMAGE/lib
+done
+
+# mknod'ing the devices instead of copying them works both with and
+# without devfs...
+mknod $MNTIMAGE/dev/console c 5 1
+mknod $MNTIMAGE/dev/null c 1 3
+mknod $MNTIMAGE/dev/ram b 1 1
+mknod $MNTIMAGE/dev/systty c 4 0
+for i in 1 2 3 4; do
+    mknod $MNTIMAGE/dev/tty$i c 4 1
+done
+
+echo "#!/bin/sh" > $RCFILE
+echo "" >> $RCFILE
+
+for MODULE in $MODULES; do
+    module=`echo $MODULE | sed "s|.*/||" | sed "s/.o$//"`
+
+    options=`sed -n -e "s/^options[ 	][ 	]*$module[ 	][ 	]*//p" $modulefile`
+
+    if [ -n "$verbose" ]; then
+        echo "Loading module $module with options $options"
+    fi
+    echo "echo \"Loading $module module\"" >> $RCFILE
+    echo "insmod /lib/$module.o $options" >> $RCFILE
+done
+
+if [ -n "$loopDev" ]; then
+    if [ ! -d /initrd ]; then
+	mkdir /initrd
+    fi
+
+    cp -a $loopDev $MNTIMAGE/dev
+    cp -a $rootdev $MNTIMAGE/dev
+    echo "echo Mounting device containing loopback root filesystem" >> $RCFILE
+    echo "mount -t $loopFs $loopDev /loopfs" >> $RCFILE
+    echo "echo Setting up loopback device $rootdev" >> $RCFILE
+    echo "losetup $rootdev /loopfs$loopFile" >> $RCFILE
+fi
+
+chmod +x $RCFILE
+
+(cd $MNTIMAGE; tar cf - .) | (cd $MNTPOINT; tar xf -)
+
+if [ "$FS" = "ext2" ] ; then
+	mount $MNTPOINT
+	losetup -d $LODEV
+else
+	genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
+	
+fi
+
+if is_yes "$COMPRESS" ; then
+    gzip -9 < $IMAGE > $target
+else
+    cp -a $IMAGE $target
+fi
+rm -rf $MNTIMAGE $MNTPOINT $IMAGE
+
diff --git a/geninitrd.8 b/geninitrd.8
new file mode 100644
index 0000000..cc1abb5
--- /dev/null
+++ b/geninitrd.8
@@ -0,0 +1,118 @@
+.TH MKINITRD 8 "Sat Mar 27 1999"
+.UC 4
+.SH NAME
+mkinitrd \- creates initial ramdisk images for preloading modules
+.SH SYNOPSIS
+\fBmkinitrd\fR [-fv] [--with=\fImodule\fR] [--preload=\fImodule\fR] 
+         [--omit-scsi-modules] [--omit-raid-modules]
+	 [--omit-ide-modules] [--version] [--fstab=\fIfstab\fR]
+	 [--fs=rom|ext2] \fIimage\fR \fIkernel-version\fR
+.SH DESCRIPTION
+\fBmkinitrd\fR creates filesystem images which are suitable for use
+as Linux initial ramdisk (initrd) images. Such images are often
+used for preloading the block device modules (such as IDE, SCSI or RAID)
+which are needed to access the root filesystem. \fBmkinitrd\fR
+automatically loads all \fIscsi_hostadapter\fR entries in
+\fI/etc/conf.modules\fR when it finds that root fs is mounted on SCSI device,
+which makes it simple to build and use kernels using modular SCSI devices.
+It will also load IDE and RAID modules when needed.
+
+Any module options specified in \fI/etc/conf.modules\fR are passed
+to the modules as they are loaded by the initial ramdisk.
+
+If the root filesystem is modular, initrd will automatically add the
+filesystem's modules to the initrd image.
+
+If the root device is on a loop device (such as /dev/loop0), \fBmkinitrd\fR
+will attempt to build an initrd which sets up the loopback file properly.
+To do this, the fstab must contain a comment of the form:
+
+    # LOOP0: /dev/hda1 vfat /linux/rootfs
+
+LOOP0 must be the name of the loop device which needs to be configured, in
+all capital lettes. The parameters after the color are the device which 
+contains the filesystem with the loopback image on it, the filesystem which
+is on the device, and the full path to the loopback image.
+
+.SH OPTIONS
+.TP
+\fB-f\fR
+Allows \fBmkinitrd\fR to overwrite an existing image file.
+
+.TP
+\fB-\-fstab=\fR\fIfstab\fR
+Use \fIfstab\fR to automatically determine what type of filesystem the
+root device is on. Normally, \fB/etc/fstab\fR is used.
+
+.TP
+\fB-\-ifneeded
+Only builds the image if their are modules that need to be loaded at boot
+time.
+
+.TP
+\fB-\-omit-scsi-modules 
+Do not load any scsi modules, including 'scsi_mod' and 'sd_mod'
+modules, even if they seem to be needed.
+
+.TP
+\fB-\-omit-ide-modules 
+Do not load any ide modules, including 'ide-mod' and 'ide-disk-mod'
+modules, even if they seem to be needed.
+
+.TP
+\fB-\-omit-raid-modules 
+Do not load any raid modules, even if /etc/fstab and /etc/raidtab expect them.
+
+.TP
+\fB-\-preload=\fR\fImodule\fR
+Load the module \fImodule\fR in the initial ramdisk image. The module gets
+loaded before any SCSI modules which are specified in \fI/etc/conf.modules\fR.
+This option may be used as many times as necessary.
+
+.TP
+\fB-v\fR
+Prints out verbose information while creating the image (normally
+the \fBmkinitrd\fR runs silently). 
+
+.TP
+\fB-\-version\fR
+Prints the version of \fBmkinitrd\fR that's being used and then exits.
+
+.TP
+\fB-\-with=\fR\fImodule\fR
+Load the modules \fImodule\fR in the initial ramdisk image. The module
+gets loaded after any SCSI modules which are specified in 
+\fI/etc/conf.modules\fR. This option may be used as many times as 
+necessary.
+
+.TP
+\fB-\-fs=\fBext2\fR|\fBrom\fR
+Filesystem type to be used for the image. Only the romfs should always be
+kompiled into kernel.
+
+.SH FILES
+.PD 0
+.TP 20
+\fI/etc/sysconfig/mkinitrd\fR
+Configuraton file with default options. Putting proper options there 
+helps automatic creation of initrd eg. on kernel upgrade
+
+.TP 20
+\fI/dev/loop*\fR
+A block loopback device is used to create the image, which makes this
+script useless on systems without block loopback support available.
+
+.TP 20
+\fI/etc/conf.modules\fR
+Specified SCSI modules to be loaded and module options to be used.
+.PD
+.SH "SEE ALSO"
+.BR fstab (5),
+.BR insmod (1),
+.BR kerneld (8),
+.BR lilo (8)
+
+.SH AUTHOR
+.nf
+Erik Troan <ewt at redhat.com>
+.fi
diff --git a/geninitrd.sysconfig b/geninitrd.sysconfig
new file mode 100644
index 0000000..0b36b29
--- /dev/null
+++ b/geninitrd.sysconfig
@@ -0,0 +1,17 @@
+## Basic modules to be loaded
+#BASICMODULES=""
+
+## Should initrd be compresses?
+#COMPRESS=yes
+
+## What filesystem to use (rom or ext2) (PLD has only romfs in kernel)?
+#FS=rom
+
+## Do install SCSI modules (if / is on SCSI partition)?
+#PROBESCSI=yes
+
+## Do install IDE modules (if / is on IDE partition)?
+#PROBEIDE=yes
+
+## Do install RAID modules (if RAID is used)?
+#PROBERAID=yes
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/readonly/geninitrd.git/commitdiff/0999a53e93eedcf489380684b998ce04aaddf11c



More information about the pld-cvs-commit mailing list