[21205] in Athena Bugs

home help back first fref pref prev next nref lref last post

Re: linux 9.1.18: kernel

daemon@ATHENA.MIT.EDU (Greg Hudson)
Mon Dec 16 23:43:37 2002

From: Greg Hudson <ghudson@MIT.EDU>
To: aatharuv@mit.edu
Cc: bugs@mit.edu
In-Reply-To: <200212170420.XAA01816@gasrd.mit.edu>
Content-Type: multipart/mixed; boundary="=-1oyFEsg3jXQp6NSHVql9"
Date: 16 Dec 2002 23:43:33 -0500
Message-Id: <1040100213.10794.203.camel@error-messages.mit.edu>
Mime-Version: 1.0


--=-1oyFEsg3jXQp6NSHVql9
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I've attached a modified /sbin/mkinitrd which uses a ramdisk instead of
a loop device.  Copying this over /sbin/mkinitrd should make a kernel
install work.  That should be a reasonable workaround for users, since
it's the workaround I plan to use in the release.


--=-1oyFEsg3jXQp6NSHVql9
Content-Disposition: attachment; filename=mkinitrd
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-sh; name=mkinitrd; charset=ISO-8859-1

#!/bin/bash

# mkinitrd
#
# Written by Erik Troan <ewt@redhat.com>
#
# Contributors:
#	Elliot Lee <sopwith@cuc.edu>
#	Miguel de Icaza <miguel@nuclecu.unam.mx>
#	Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
#	Michael K. Johnson <johnsonm@redhat.com>
#	Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr>
#	Jakub Jelinek <jakub@redhat.com>
#	Carlo Arenas Belon (carenas@chasqui.lared.net.pe>
#	Keith Owens <kaos@ocs.com.au>
#	Bernhard Rosenkraenzer <bero@redhat.com>
#	Matt Wilson <msw@redhat.com>
#       Trond Eivind Glomsr=F8d <teg@redhat.com>
#       Jeremy Katz <katzj@redhat.com>
#       Preston Brown <pbrown@redhat.com>


PATH=3D/sbin:$PATH
export PATH

VERSION=3D3.3.10

compress=3D1
target=3D""
kernel=3D""
force=3D""
verbose=3D""
MODULES=3D""
img_vers=3D""
modulefile=3D/etc/modules.conf

if [ `uname -m` =3D "ia64" ]; then
  IMAGESIZE=3D4000
else
  IMAGESIZE=3D3000
fi
PRESCSIMODS=3D"scsi_mod sd_mod unknown"
fstab=3D"/etc/fstab"

usage () {
    echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preloa=
d <module>]" >&2
    echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-lvm-mo=
dules] [--with=3D<module>]" >&2
    echo "       [--image-version] [--fstab=3D<fstab>] [--nocompress] <init=
rd-image>" >&2
    echo "       <kernel-version>" >&2
    echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" >&=
2
    exit 1
}

findmodule() {
    skiperrors=3D""

    if [ $1 =3D=3D "--skiperrors" ]; then
	skiperrors=3D--skiperrors
	shift
    fi

    modName=3D$1
    if [ $(echo $modName | cut -b1) =3D "-" ]; then
	skiperrors=3D--skiperrors
	modName=3D$(echo $modName | cut -b2-)
    fi

    if [ "$modName" =3D "i2o_block" ]; then
	findmodule i2o_pci
	findmodule i2o_core
	modName=3D"i2o_block"
    fi

    if [ "$modName" =3D "pluto" ]; then
	findmodule fc4
	findmodule soc
	modName=3D"pluto"
    fi

    if [ "$modName" =3D "fcal" ]; then
	findmodule fc4
	findmodule socal
	modName=3D"fcal"
    fi

    if [ "$modName" =3D "ext3" ]; then
	findmodule $skiperrors jbd
	modName=3D"ext3"
    fi

    if [ "$modName" =3D "xfs" ]; then
	findmodule $skiperrors pagebuf
	findmodule $skiperrors xfs_support
	modName=3D"xfs"
    fi

    if [ "$modName" =3D "ppa" ]; then
	findmodule parport
	findmodule parport_pc
	modName=3D"ppa"
    fi

    fmPath=3D`(cd /lib/modules/$kernel; echo find . -name $modName.o | /sbi=
n/nash --quiet)`

    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" =3D "$modName" ]; then
		return;
	    fi
	done;
   =20
	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=3D"$MODULES $fmPath"
    fi
}

inst() {
    if [ "$#" !=3D "2" ];then
        echo "usage: inst <file> <destination>"
        return
    fi=20
    [ -n "$verbose" ] && echo "$1 -> $2"
    cp $1 $2
}

while [ $# -gt 0 ]; do
    case $1 in
	--fstab*)
	    if echo $1 | grep '=3D' >/dev/null ; then
	    	fstab=3D`echo $1 | sed 's/^--fstab=3D//'`
	    else
		fstab=3D$2
		shift
	    fi		   =20
	    ;;

	--with*)
	    if echo $1 | grep '=3D' >/dev/null ; then
	    	modname=3D`echo $1 | sed 's/^--with=3D//'`
	    else
		modname=3D$2
		shift
	    fi		   =20

	    basicmodules=3D"$basicmodules $modname"
	    ;;

	--version)
	    echo "mkinitrd: version $VERSION"
	    exit 0
	    ;;

	-v)
	    verbose=3D-v
	    ;;

	--nocompress)
	    compress=3D""
	    ;;

	--ifneeded)
	    ifneeded=3D1
	    ;;

	-f)
	    force=3D1
	    ;;
	--preload*)
	    if echo $1 | grep '=3D' >/dev/null ; then
	    	modname=3D`echo $1 | sed 's/^--preload=3D//'`
	    else
		modname=3D$2
		shift
	    fi		   =20
	    PREMODS=3D"$PREMODS $modname"
	    ;;
	--omit-scsi-modules)
	    PRESCSIMODS=3D""
	    noscsi=3D1;
	    ;;
	--omit-raid-modules)
	    noraid=3D1;
	    ;;
	--omit-lvm-modules)
	    nolvm=3D1
	    ;;
	--image-version)
	    img_vers=3Dyes
	    ;;
	*)
	    if [ -z "$target" ]; then
		target=3D$1
	    elif [ -z "$kernel" ]; then
		kernel=3D$1
	    else
		usage
	    fi
	    ;;
    esac

    shift
done

if [ -z "$target" -o -z "$kernel" ]; then
    usage
fi

if [ -n "$img_vers" ]; then
    target=3D"$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

if [ $(id -u) !=3D 0 ]; then
    echo "mkinitrd must be run as root"
    exit 1
fi

# find a temporary directory which doesn't use tmpfs
TMPDIR=3D""
for t in /tmp /var/tmp /root ${PWD}; do
    if [ ! -d $t ]; then continue; fi
    if ! echo access -w $t | /sbin/nash --quiet; then continue; fi

    fs=3D$(df -T $t 2>/dev/null | tail -1 | awk '{printf $2}')
    if [ "$fs" !=3D "tmpfs" ]; then=20
	TMPDIR=3D$t
	break
    fi
done

if [ -z "$TMPDIR" ]; then
    echo "no temporary directory could be found" >&2
    exit 1
fi

if [ $TMPDIR =3D "/root" -o $TMPDIR =3D "${PWD}" ]; then=20
    echo "WARNING: using $TMPDIR for temporary files" >&2
fi

for n in $PREMODS; do
	findmodule $n
done

if [ -z "$noscsi" ]; then
    if [ ! -f $modulefile ]; then
        modulefile=3D/etc/conf.modules
    fi

    if [ -f $modulefile ]; then
	scsimodules=3D`grep scsi_hostadapter $modulefile | grep -v '^[ 	]*#' | LC_=
ALL=3DC sort -u | awk '{ print $3 }'`

	if [ -n "$scsimodules" ]; then
	    for n in $PRESCSIMODS; do
		findmodule $n
	    done

	    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
fi

# If we have ide devices and module ide, do the right thing
ide=3D/proc/ide/ide*
if [ -n "$ide" ]; then
    findmodule -ide-mod
    findmodule -ide-probe-mod
    findmodule -ide-disk
fi

# If we use LVM, include lvm-mod
if [ -z "$nolvm" ]; then
    if  $(grep '^VG:' /proc/lvm/global  >/dev/null 2>&1) ; then
	findmodule -lvm-mod
    fi
fi

# If we have dasd devices, include the necessary modules (S/390)
dasd=3D/proc/dasd/dev*
if [ -n "$dasd" ]; then
    findmodule -dasd_mod
    findmodule -dasd_eckd_mod
    findmodule -dasd_fba_mod
fi

if [ -z "$noraid" ]; then
    # load appropriate raid devices if necessary, this means that the
    # /etc/raidtab *must* be up to date for raided root to work.
    #if grep '^/dev/md' $fstab | grep -v noauto >/dev/null 2>&1 ; then
	for number in $(grep '^[ 	]*raid-level' /etc/raidtab 2>/dev/null |
			  awk '{print $2}' | LC_ALL=3DC sort -u) ; do
	    case $number in
	    [014])
		findmodule -md
		findmodule raid$number
		startraid=3D1
		;;
	    5)
		findmodule -md
		findmodule -xor
		findmodule raid$number
		startraid=3D1
		;;
	    *)
		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
rootdev=3D$(awk '{ if ($2 =3D=3D "/") { print $1; }}' $fstab)
if echo $rootdev | cut -d/ -f3 | grep loop >/dev/null; then
    key=3D"^# $(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 mkinitrd man page for more information"=
 2>&2
	exit 1
    fi

    line=3D$(grep "$key" $fstab)
    loopDev=3D$(echo $line | awk '{print $3}')
    loopFs=3D$(echo $line | awk '{print $4}')
    loopFile=3D$(echo $line | awk '{print $5}')

    basicmodules=3D"$basicmodules -loop"
    if [ "$loopFs" =3D "vfat" -o "$loopFs" =3D "msdos" ]; then
	basicmodules=3D"$basicmodules -fat"
    fi
    basicmodules=3D"$basicmodules -${loopFs}"
# check if the root fs is on a logical volume
elif ! echo $rootdev | cut -c1-6 |grep "LABEL=3D" >/dev/null ; then
    major=3D`ls -l "$rootdev" | sed -e "s/.* \\([0-9]\+\\), *[0-9]\+.*/\\1/=
"`
    [ "$major" -ne 58 ] || root_lvm=3D1
fi

rootfs=3D$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 =3D=3D "/") { print $3; }}' $f=
stab)

# in case the root filesystem is modular
findmodule -${rootfs}

for n in $basicmodules; do=20
    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=3D`mktemp -d ${TMPDIR}/initrd.XXXXXX`
IMAGE=3D`mktemp ${TMPDIR}/initrd.img.XXXXXX`
MNTPOINT=3D`mktemp -d ${TMPDIR}/initrd.mnt.XXXXXX`
RCFILE=3D$MNTIMAGE/linuxrc

if [ -z "$MNTIMAGE" -o -z "$IMAGE" -o -z "$MNTPOINT" ]; then
    echo "Error creating temporaries.  Try again" >&2
    exit 1
fi

dd if=3D/dev/zero of=3D$IMAGE bs=3D1k count=3D$IMAGESIZE 2> /dev/null

for devnum in 0 1 2 3 4 5 6 7 8; do
    if ! mount | grep -q /dev/ram${devnum} ; then break; fi
done

if [ "$devnum" =3D "8" ]; then
    rm -rf $MNTPOINT $IMAGE
    echo "All of your ramdisk devices are mounted!" >&2
    exit 1
fi

RAMDEV=3D/dev/ram${devnum}

mke2fs $RAMDEV $IMAGESIZE >/dev/null 2>/dev/null
tune2fs -i0 $RAMDEV >/dev/null

if [ -n "$verbose" ]; then
    echo "Using ramdisk device $RAMDEV"
fi

mkdir -p $MNTPOINT
mount -t ext2 $RAMDEV $MNTPOINT || {
	echo "Can't get a loopback device"
	exit 1
}

mkdir -p $MNTIMAGE
mkdir -p $MNTIMAGE/lib
mkdir -p $MNTIMAGE/bin
mkdir -p $MNTIMAGE/etc
mkdir -p $MNTIMAGE/dev
mkdir -p $MNTIMAGE/loopfs
mkdir -p $MNTIMAGE/proc
mkdir -p $MNTIMAGE/sysroot
ln -s bin $MNTIMAGE/sbin

# We don't need this directory, so let's save space
rm -rf $MNTPOINT/lost+found

inst /sbin/nash "$MNTIMAGE/bin/nash"
inst /sbin/insmod.static "$MNTIMAGE/bin/insmod"
ln -s /bin/nash $MNTIMAGE/sbin/modprobe

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 $i
done

# FIXME -- this won't work if you're using devfs
if [ -n "$root_lvm" ]; then
    pvs=3D$(/sbin/lvmdiskscan |grep "0x8E" | /bin/awk {'print $3;'})
    for pv in $pvs; do
	cp -a $pv $MNTIMAGE/$pv
    done

    inst /sbin/vgwrapper "$MNTIMAGE/bin/vgwrapper"
    ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgscan"
    ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgchange"

    mknod $MNTIMAGE/dev/lvm b 109 0
fi

echo "#!/bin/nash" > $RCFILE
echo "" >> $RCFILE

for MODULE in $MODULES; do
    text=3D""
    module=3D`echo $MODULE | sed "s|.*/||" | sed "s/.o$//"`

    options=3D`sed -n -e "s/^options[ 	][ 	]*$module[ 	][ 	]*//p" $modulefi=
le 2>/dev/null`

    if [ -n "$verbose" ]; then
	if [ -n "$options" ]; then
	    text=3D" with options $options"
	fi
        echo "Loading module $module$text"
    fi
    echo "echo \"Loading $module module\"" >> $RCFILE
    echo "insmod /lib/$module.o $options" >> $RCFILE
done

echo "echo Mounting /proc filesystem" >> $RCFILE
echo "mount -t proc /proc /proc" >> $RCFILE

if [ -n "$loopDev" ]; then
    mkdir /initrd
    cp -a $loopDev $MNTIMAGE/dev
    cp -a $rootdev $MNTIMAGE/dev
    echo "echo Mounting device containing loopback root filesystem" >> $RCF=
ILE
    echo "mount -t $loopFs $loopDev /loopfs" >> $RCFILE
    echo "echo Setting up loopback device $rootdev" >> $RCFILE
    echo "losetup $rootdev /loopfs$loopFile" >> $RCFILE
elif [ -n "$root_lvm" ]; then
    echo "echo Scanning logical volumes" >> $RCFILE
    echo "vgscan" >> $RCFILE
    echo "echo Activating logical volumes" >> $RCFILE
    echo "vgchange -ay" >> $RCFILE
else
    echo "echo Creating root device" >> $RCFILE
    echo "mkrootdev /dev/root" >> $RCFILE
    rootdev=3D/dev/root
fi

if [ -n "$startraid" ]; then
    cp -a /dev/md0 $MNTIMAGE/dev
    echo "raidautorun /dev/md0" >> $RCFILE
fi

echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $RCFILE

echo "echo Mounting root filesystem" >> $RCFILE
echo "mount --ro -t $rootfs $rootdev /sysroot" >> $RCFILE

echo "umount /proc" >> $RCFILE
echo "pivot_root /sysroot /sysroot/initrd" >> $RCFILE

chmod +x $RCFILE

(cd $MNTIMAGE; tar cf - .) | (cd $MNTPOINT; tar xf -)

umount $MNTPOINT
dd if=3D$RAMDEV of=3D$IMAGE bs=3D1k count=3D$IMAGESIZE 2> /dev/null

if [ -n "$compress" ]; then
    gzip -9 < $IMAGE > $target
else
    cp -a $IMAGE $target
fi
rm -rf $MNTIMAGE $MNTPOINT $IMAGE

--=-1oyFEsg3jXQp6NSHVql9--

home help back first fref pref prev next nref lref last post