⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkinitrd.iscsi

📁 ISCSI user client software.Client would be used to access the IPSAN server.
💻 ISCSI
字号:
#!/bin/bash# This is a wrapper script around mkinitrd for additional things which needs# to be done for iSCSI network boot.# NOTE: This has not been tested and may not work if root is on a # loop device, lvm or raid device.compress=1iscsipkgdir="" if [ -f /etc/SuSE-release ]; then    WRAPPER_IMAGESIZE=14000else    if [ `uname -m` = "ia64" ]; then        WRAPPER_IMAGESIZE=4000    else        WRAPPER_IMAGESIZE=5000    fifiiscsi_driver_version=$(iscsid -v| awk -F" " '{print $3}')usage () {    if [ ! -f /etc/SuSE-release ]; then        echo "usage: `basename $0` <iscsi-pkg-dir> --preload=<module> <initrd-pkg-name> <current-kernel-version>" >&2        echo "" >&2        echo "       (ex: `basename $0` /temp/iscsi-pkg-dir --preload=e100 /boot/initrd-2.2.5-15.img 2.2.5-15)" >&2    else        echo "usage: `basename $0` <iscsi-pkg-dir> --preload=<module> <initrd-pkg-name> <boot-dir> <current-kernel-image>" >&2        echo "" >&2        echo "       (ex: `basename $0` /temp/iscsi-pkg-dir --preload=e100 initrd-2.2.5-15.img /boot vmlinuz-2.2.5.15)" >&2    fi    exit 1}while [ $# -gt 0 ]; do    case $1 in         *)             if [ -z "$iscsipkgdir" ]; then                iscsipkgdir=$1            else                usage            fi            ;;    esac    shift    breakdoneinitrd_arguments=$*while [ $# -gt 0 ]; do    case $1 in	--fstab*)	    if echo $1 | grep -q '=' ; then	    	fstab=`echo $1 | sed 's/^--fstab=//'`	    else		fstab=$2		shift	    fi		    	    ;;	--with*)	    if echo $1 | grep -q '=' ; then	    	modname=`echo $1 | sed 's/^--with=//'`	    else		modname=$2		shift	    fi		    	    basicmodules="$basicmodules $modname"	    ;;	--builtin*)	    if echo $1 | grep -q '=' ; then	    	modname=`echo $1 | sed 's/^--builtin=//'`	    else		modname=$2		shift	    fi		    	    builtins="$builtins $modname"	    ;;	--version)	    echo "mkinitrd: version $VERSION"	    exit 0	    ;;	-v)	    verbose=-v	    ;;	--nocompress)	    compress=""	    ;;	--nopivot)	    pivot=""	    ;;	--ifneeded)	    # legacy	    ;;	-f)	    force=1	    ;;	--preload*)	    if echo $1 | grep -q '=' ; then	    	modname=`echo $1 | sed 's/^--preload=//'`	    else		modname=$2		shift	    fi		    	    PREMODS="$PREMODS $modname"	    ;;	--omit-scsi-modules)	    PRESCSIMODS=""	    noscsi=1;	    ;;	--omit-raid-modules)	    noraid=1;	    ;;	--omit-lvm-modules)	    nolvm=1	    ;;	--image-version)	    img_vers=yes	    ;;	--with-usb)	    withusb=yes	    ;;	*)            if [ -f /etc/SuSE-release ]; then	        if [ -z "$target" ]; then		    target=$1		elif [ -z "$bootdir" ]; then		    bootdir=$1		elif [ -z "$image" ]; then		    image=$1	        elif [ -z "$iscsipkgdir" ]; then		    iscsipkgdir=$1                else                    usage                fi            else   	        if [ -z "$target" ]; then		    target=$1	        elif [ -z "$kernel" ]; then		    kernel=$1	        elif [ -z "$iscsipkgdir" ]; then		    iscsipkgdir=$1	        else		    usage                fi	    fi	    ;;    esac    shiftdoneif [ ! -f /etc/SuSE-release ]; then    if [ -z "$target" -o -z "$kernel" -o -z "$iscsipkgdir" ]; then        usage    fielse        if [ -z "$target" -o -z "$image" -o -z "$iscsipkgdir" ]; then        usage    fifiif [ -f $target ]; then    echo "$target already exists." >&2    exit 1fi# make sure iscsi goes into initrd image with relevant scsi modules if [ -f /etc/redhat-release ] ; then    while read var      do      echo $var >> /etc/modules.conf.$$    done < /etc/modules.conf    echo "alias scsi_hostadapter iscsi" >> /etc/modules.conf.$$    cp /etc/modules.conf.$$ /etc/modules.conf    cd /lib/modules/`uname -r`/misc    ln -s iscsi_sfnet.ko iscsi.o    if [[ $iscsi_driver_version > "4:0.1.10" ]]; then	ln -s scsi_transport_iscsi.ko scsi_transport_iscsi.o    fi    cd -    mkinitrd $initrd_arguments    if [ $? -ne 0 ]	then	echo ""	echo mkinitrd failed, exiting ...	echo ""	exit 1    fi# Revert back the changes we did to /etc/modules.conf    sed '$d' </etc/modules.conf >/etc/modules.conf.$$    cp /etc/modules.conf.$$ /etc/modules.conf    rm /etc/modules.conf.$$fi    if [ -f /etc/SuSE-release ]; then    default=`grep "INITRD_MODULES=" /etc/sysconfig/kernel | awk -F'=' '{print $2}'`    for i in $default ; do      	i=$(echo $i | sed -e "s/\"//g")	if [ $i = "scsi_mod" ] ; then	    if [ $scsi_mod="scsi_mod" ] ; then		continue	    fi	    scsi_mod="scsi_mod"	    MOD="$MOD $PREMODS"	fi	if [ $i = "sd_mod" ] ; then	    if [ ! $scsi_mod ] ; then ## load scsi_mod before loading sd_mod ##		scsi_mod="scsi_mod"		MOD="$MOD $PREMODS scsi_mod"	    fi	fi	MOD="$MOD $i"    done    ## add scsi_mod, sd_mod if it is not part of     ## INITRD_MODULES in /etc/sysconfig/kernel.    ## Even if these modules are compiled within the    ## kernel, there is no harm in including scsi_mod    ## and sd_mod here.        if [ ! $scsi_mod ] ; then 	MOD="$MOD $PREMODS scsi_mod sd_mod"    fi        if [[ $iscsi_driver_version > "4:0.1.10" ]]; then	MOD="$MOD scsi_transport_iscsi"    fi    MOD="$MOD iscsi"        rootdev=$(awk '{ if ($1 && $2 == "/") { print $1; }}' /etc/fstab)    test -h $rootdev    while [ $? -eq 0 ]; do	rootdev=`ls -l $rootdev | cut -d ">" -f 2 | cut -d " " -f 2`	test -h $rootdev    done        cd /lib/modules/`uname -r`/misc    ln -s iscsi_sfnet.ko iscsi.o    if [[ $iscsi_driver_version > "4:0.1.10" ]]; then	ln -s scsi_transport_iscsi.ko scsi_transport_iscsi.o    fi    cd -        test -e /lib/modules/`uname -r`/kernel/drivers/scsi/sd_mod.ko    if [ $? -eq 0 ] ; then	cd /lib/modules/`uname -r`/kernel/drivers/scsi	ln -s sd_mod.ko sd_mod.o	test -e /lib/modules/`uname -r`/kernel/drivers/scsi/scsi_mod.ko	if [ $? -eq 0 ] ; then	    ln -s scsi_mod.ko scsi_mod.o	fi	cd -    fi    mkinitrd -i $target -k $image -b $bootdir -d $rootdev -m "$MOD"        cd $iscsipkgdir; cp $bootdir$target .fiTMPDIR=""for t in /tmp /var/tmp /root ${PWD}; do    if [ ! -d $t ]; then continue; fi    fs=$(df -T $t 2>/dev/null | tail -1 | awk '{printf $2}')    if [ "$fs" != "tmpfs" ]; then 	TMPDIR=$t	break    fidoneif [ -z "$TMPDIR" ]; then    echo "no temporary directory could be found" >&2    exit 1fiif [ $TMPDIR = "/root" -o $TMPDIR = "${PWD}" ]; then     echo "WARNING: using $TMPDIR for temporary files" >&2fiIMAGE=`mktemp ${TMPDIR}/initrd.img.XXXXXX`MNTPOINT=`mktemp -d ${TMPDIR}/initrd.mnt.XXXXXX`WRAPPER_IMAGE=`mktemp ${TMPDIR}/initrd-wrapper.img.XXXXXX`WRAPPER_MNTPOINT=`mktemp -d ${TMPDIR}/initrd-wrapper.mnt.XXXXXX`if [ -z "$WRAPPER_IMAGE" -o -z "$WRAPPER_MNTPOINT" -o -z "$IMAGE" -o -z "$MNTPOINT" ]; then    echo "Error creating temporaries.  Try again" >&2    exit 1fiif [ -n "$compress" ]; then    cp $target $IMAGE.gz    gunzip -f $IMAGE.gzelse    cp $target $IMAGEfirm $targetdd if=/dev/zero of=$WRAPPER_IMAGE bs=1k count=$WRAPPER_IMAGESIZE 2> /dev/nullecho y | mke2fs  $WRAPPER_IMAGE 2>/dev/null 1>&2tune2fs -i 0 $WRAPPER_IMAGE >/dev/null 2>&1mount $IMAGE -t ext2 -o loop $MNTPOINT || {	echo "Can't get a loopback device"	exit 1}mount $WRAPPER_IMAGE -t ext2 -o loop $WRAPPER_MNTPOINT || {	echo "Can't get a loopback device"	exit 1}rm -rf $WRAPPER_MNTPOINT/lost+foundcp -a $MNTPOINT/* $WRAPPER_MNTPOINT/# Overwrite the iscsi.o if it was in misc or scsi from /lib/...# Better option is to copy iscsi.o into these directories by calling# findmodule()if [ -f /etc/redhat-release ] ; then    cp $iscsipkgdir/driver/iscsi_sfnet.ko $WRAPPER_MNTPOINT/lib/    if [[ $iscsi_driver_version > "4:0.1.10" ]]; then	cp $iscsipkgdir/driver/scsi_transport_iscsi.ko $WRAPPER_MNTPOINT/lib/		cd $WRAPPER_MNTPOINT/lib/	ln -s scsi_transport_iscsi.ko scsi_transport_iscsi.o	cd -    fifiif [ -f /etc/SuSE-release  ] ; then    cp $iscsipkgdir/driver/iscsi_sfnet.ko $WRAPPER_MNTPOINT/lib/modules/`uname -r`/misc    chmod 755 $WRAPPER_MNTPOINT/lib/modules/`uname -r`/misc/iscsi_sfnet.ko        if [[ $iscsi_driver_version > "4:0.1.10" ]]; then	cp $iscsipkgdir/driver/scsi_transport_iscsi.ko $WRAPPER_MNTPOINT/lib/modules/`uname -r`/misc	chmod 755 $WRAPPER_MNTPOINT/lib/modules/`uname -r`/misc/scsi_transport_iscsi.ko    fificp $iscsipkgdir/Linux-i686/obj/utils/iscsi-boot/init $WRAPPER_MNTPOINT/bin/mknod $WRAPPER_MNTPOINT/dev/mem c 1 1# Generate iSCSI InitiatorNamemkdir -p $WRAPPER_MNTPOINT/etcprintf "InitiatorName=%s\n" `$iscsipkgdir/Linux-i686/obj/utils/iscsi-iname` >> $WRAPPER_MNTPOINT/etc/initiatorname.iscsimkdir -p $WRAPPER_MNTPOINT/var/iscsimkdir -p $WRAPPER_MNTPOINT/var/runmkdir -p $WRAPPER_MNTPOINT/procmkdir -p $WRAPPER_MNTPOINT/sysmkdir -p $WRAPPER_MNTPOINT/sysrootfstab=/etc/fstabiscsirootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)varfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/var") { print $3; }}' $fstab)touch $WRAPPER_MNTPOINT/linuxrc.$$if [ -f /etc/SuSE-release ]; then    echo "#!/bin/sh" >> $WRAPPER_MNTPOINT/linuxrc.$$    echo "" >> $WRAPPER_MNTPOINT/linuxrc.$$else    echo "#!/bin/nash" >> $WRAPPER_MNTPOINT/linuxrc.$$    echo "" >> $WRAPPER_MNTPOINT/linuxrc.$$fiecho "echo Mounting /sys filesystem"  >> $WRAPPER_MNTPOINT/linuxrc.$$echo "mount -t sysfs sysfs /sys" >> $WRAPPER_MNTPOINT/linuxrc.$$if [[ $iscsi_driver_version > "4:0.1.10" ]]; then    echo "echo Loading scsi_transport_iscsi"  >> $WRAPPER_MNTPOINT/linuxrc.$$    echo "insmod /lib/scsi_transport_iscsi.o"  >> $WRAPPER_MNTPOINT/linuxrc.$$fiwhile read linedo    echo $line | grep Loading >> $WRAPPER_MNTPOINT/linuxrc.$$    echo $line | grep insmod >> $WRAPPER_MNTPOINT/linuxrc.$$    echo $line | grep "echo Mounting /proc filesystem"  >> $WRAPPER_MNTPOINT/linuxrc.$$    echo $line | grep "mount -t proc /proc /proc" >> $WRAPPER_MNTPOINT/linuxrc.$$done < $MNTPOINT/linuxrcif [ -f /etc/SuSE-release ]; then    echo "echo \"Mounting /proc filesystem\""  >> $WRAPPER_MNTPOINT/linuxrc.$$    echo "mount -t proc /proc /proc" >> $WRAPPER_MNTPOINT/linuxrc.$$    cp /bin/mount $WRAPPER_MNTPOINT/bin/    cp /lib/libc.so.6 $WRAPPER_MNTPOINT/lib/    cp /lib/ld-linux.so.2 $WRAPPER_MNTPOINT/lib/fiecho "echo \"Execing init ... \"" >> $WRAPPER_MNTPOINT/linuxrc.$$echo "exec /bin/init $iscsirootfs $varfs" >> $WRAPPER_MNTPOINT/linuxrc.$$mv $WRAPPER_MNTPOINT/linuxrc.$$ $WRAPPER_MNTPOINT/linuxrcchmod 755 $WRAPPER_MNTPOINT/linuxrcumount $MNTPOINTumount $WRAPPER_MNTPOINTif [ -n "$compress" ]; then    gzip -9 < $WRAPPER_IMAGE > $target || rc=1else    cp -a $WRAPPER_IMAGE $target || rc=1fiif [ -f /etc/SuSE-release ]; then    mv $target $bootdirfirm -rf $MNTPOINT $IMAGErm -rf $WRAPPER_MNTPOINT $WRAPPER_IMAGEexit $rc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -