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

📄 mkrescue

📁 LINUX lilo-22.7 源代码。
💻
字号:
#!/bin/bash## mkrescue##	30-Oct-2001	original version 1.0## Revision history:#	09-Apr-2002	John Coffman	modify for lilo 22.3   1.1#	09-Jun-2002	John Coffman	get keyboard translation table 1.2#					(suggested by Qing Liu)#	07-May-2003	John Coffman	add nowarn for lilo 22.5.2  1.3#	13-May-2003	John Coffman	use default image, add append=  1.4#	24-May-2003	John Coffman	specify ext2 params for xtra space#	26-May-2003	John Coffman	el-torito-bootable-CD   2.1#	30-May-2003	   "		add lilo version check  2.1#	07-Jul-2003	   "		determine loopback dynamically 2.3#	29-Aug-2004	   "		allow --root LABEL=lblname  2.4#	01-Sep-2004	   "		fix check for LILO version  2.4#	03-Oct-2004	   "		get root= from /etc/fstab   2.5#	15-Nov-2004	   "		support --iso --size HD	    3.0#debug=false#debug=truelog=$(pwd)/mkrescue.log#log=# set the version number on this commandversion=3.0# set the version of LILO required to runmajor=22minor=6revision=1usage () {    cat <<EOFusage:	`basename $0` [--help]	`basename $0` [--version]	`basename $0` [--device <device>] [--fast] [--fs ext2|msdos|minix]	    [--image <label>] [--install text|menu] [--keymap <keymap.ktl>] 	    [--initrd <file> --kernel <file>] [--append <string>]	    [--root <device>] [--nocompact] [--noformat]	    [--iso] [--size 1440|1200|2880|HD]  --device  is the floppy drive; e.g.,  /dev/fd0  --fast  specifies creation using a loopback device, which may be faster  --fs  is the filesystem to make on the device; e.g.,  ext2  --help  prints this helpfile  --iso  create a bootable ISO image to burn to a CD-R or CD-RW  --keymap  is the keyboard translation table; default to same as lilo.conf  --noformat  bypasses creation of a new filesystem on device  --nocompact  omits lilo map file compaction  --size  is assumed to be 1440 (1.44M), unless 1200 or 2880 is specified	HD may be specified for ISO images  --image  specifies the label of the kernel/initrd if not the default  --install  text is the default for floppies, menu for ISO images  --initrd and --kernel  are the initial ramdisk & kernel files  --append  is a string used to specify kernel options  --root  is the root filesystem for the boot floppy; e.g., current  --version  prints the version number of `basename $0`Used without any arguments, `basename $0` will use the default kernel in/etc/lilo.conf, the companion initrd (if any), and the specified rootfilesystem to make a bootable rescue floppy.EOF## --install & --debug are undocumented above##    exit $1}if [ $debug != false ]; then	lilo=$(pwd)/lilo	config=$(pwd)/lilo.confelse	lilo=/sbin/lilo	config=/etc/lilo.conffitmp=/tmpcompact=-cdevice=/dev/fd0fs=ext2mount=$tmp/mkrescue-flpmfile=$tmp/mkrescue-emumtemp=$tmp/mkrescue-tmploopback=loop0looppart=loop1install=textisoimage=noformat=yesimage=root=bios=0x00fast=slowsize=0heads=2sectors=18cylinders=80hdsize=16384bootcmd=append=initrd=boot=/bootdiag=noif [ -b /dev/hda ]; then	master=/dev/hdaelif [ -b /dev/sda ]; then	master=/dev/sdaelif [ -b /dev/ide/host0/bus0/target0/lun0/disc ]; then	master=/dev/ide/host0/bus0/target0/lun0/discelif [ -b /dev/scsi/host0/bus0/target0/lun0/disc ]; then	master=/dev/scsi/host0/bus0/target0/lun0/discelse	master=fiVERSION=$($lilo -V | sed "/version/s/.*n //" | sed "/,/s/,.*//" )NVERSION=$(echo $VERSION | sed "s/\\./ /g")DASH=$(echo $VERSION | sed "/-/s/.*-//" )if [ "$DASH" = "$VERSION" ]; then	DASH=0else	NVERSION=$(echo $NVERSION | sed "s/-.*//")fiMAJOR=$(echo $NVERSION | sed "s/ .*//")MINOR=$(echo $NVERSION | sed -e "s/$MAJOR //" -e "s/ .*//" )if [ "$MINOR" = "$NVERSION" ]; then	MINOR=0fiREVISION=$(echo $NVERSION | sed "s/$MAJOR $MINOR //")if [ "$REVISION" = "$NVERSION" ]; then	REVISION=0fiREVISION=$(echo $REVISION | sed "s/ .*//")if [ "$MINOR" -gt 49 ]; then MINOR=$(expr $MINOR % 10); fiif [ $debug = true ]; thenecho ""echo VERSION $VERSIONecho ""echo MAJOR $MAJORecho MINOR $MINORecho REVISION $REVISIONecho DASH $DASHecho ""fi#if [ "$MAJOR" -lt "$major" \#	-o "$MINOR" -lt "$minor" \# 		-o $REVISION -lt "$revision" ]skip=falseif [ "$REVISION" -lt "$revision" ]thenskip=true#echo $REVISION lt $revisionfiif [ "$MINOR" -gt "$minor" ]thenskip=false#echo $MINOR gt $minorfiif [ "$MAJOR" -gt "$major" ]thenskip=false#echo $MAJOR gt $majorfiif [ "$skip" = "true" ]then    echo `basename $0` version $version    echo "LILO version $major.$minor.$revision (or newer) is required."    exit 0fiumount $mount 2>/dev/nullrm -rf $mount $mfile 2>/dev/nullwhile [ $# -gt 0 ]; do    case $1 in	--append)	    shift	    append=$1	    ;;	--debug)	    debug=true	    ;;	--device)	    shift	    device=$1	    ;;	--fast)	    fast=fast	    ;;	--fs)	    shift	    fs=$1	    ;;	-h)	    usage 0	    ;;	--help)	    usage 0	    ;;	--image)	    shift	    image=$1	    ;;	--initrd)	    shift	    initrd=$1	    ;;	--install)	    shift	    install=$1	    ;;	--iso)	    isoimage=yes	    ;;	--kernel)	    shift	    kernel=$1	    ;;	--keymap)	    shift	    keymap=$1	    ;;	--nocompact)	    compact=	    ;;	--noformat)	    format=no	    ;;	--root)	    shift	    root=$1	    ;;	--size)	    shift	    size=$1	    ;;	--version)	    echo `basename $0` version $version	    exit 0	    ;;	*)	    echo "unrecognized argument: " $1	    usage 1	    ;;    esac    shiftdoneif [ -z $image ]; then#	image=`cat /proc/cmdline | sed "s/.*BOOT_IMAGE=//" | sed "s/ .*//"`	image=`$lilo -C $config -I " " D`fiif [ -z $kernel ]; then	kernel=`$lilo -C $config -I $image i`	if [ "$kernel" = "" ]; then exit 1;	elif [ $debug = "true" ]; then echo kernel = "$kernel";	fifiif [ -z $root ]; then	root=`$lilo -C $config -I $image R`	if [ "$root" = "No root specified" ]; then		root=`grep </etc/fstab -v "^[ \t]*#" |			grep "[[:space:]]/[[:space:]]" | \				sed -e "s/^[ \t]*//" -e "s/[ \t].*//"`		if [ -z $root ]; then			root=`mount | grep " on / type" | sed "s/ .*//"`		fi		if [ -z $root ]; then			echo "Cannot find mounted root partition"			echo "Using current root"			root=current		fi	fi	if [ $debug = true ]; then echo root = "$root";	fifiif [ -z $initrd ]; then	initrd=`$lilo -C $config -I $image r`	if [ "$initrd" = "" ]; then exit 1;	elif [ $debug = "true" ]; then echo initrd = "$initrd";	fifiif [ "$initrd" = "No initial ramdisk specified" ]; then initrd= ; fiif [ -z $append ]; then	append=`$lilo -C $config -I $image a`	if [ "$append" = "" ]; then exit 1;	elif [ $debug = "true" ]; then echo append = \"$append\";	fifiif [ "$append" = "No append= was specified" ]; then append= ; fiif [ -z $keymap ]; then	keymap=`$lilo -C $config -I $image k`	if [ "$keymap" = "" ]; then exit 1;	elif [ $debug = "true" ]; then echo keymap = "$keymap";	fifiif [ $isoimage = yes ]; then    fast=fast    if [ $size = 0 ]; then	size=2880    elif [ $size = HD -o $size = hd ]; then	size=$hdsize    fi    if [ $device = "/dev/fd0" ]; then	device=rescue.iso    fielse	umount $device 2>/dev/null 1>/dev/nullfiif [ $size = 0 ]; then    size=1440fiif [ $size = 1200 ]; then    sectors=15elif [ $size = 1440 ]; then    sectors=18elif [ $size = 2880 ]; then    sectors=36    install=menu    if [ -f $boot/diag1.img -a -f $boot/diag2.img ]; then	diag=yes    fielif [ $size = $hdsize ]; then    sectors=32    heads=8    cylinders=$(($size/$sectors/$heads*2))    if [ $size != $(($sectors*$heads*$cylinders/2)) ]; then	echo Internal error in HDsize	exit 1    fi    install=menu    if [ -f $boot/diag1.img -a -f $boot/diag2.img ]; then	diag=yes    fielif [ $size = HD -o $size = hd ]; then    echo "--size $size  may only be used with the  --iso  option."    exit 1else    echo "--size must be 1200 or 1440; --size 1440 assumed."    sectors=18    size=1440fiif [ $fs != msdos -a $fs != ext2 -a $fs != minix ]; then    echo "illegal option:  --fs" $fs    echo "   must be either  msdos  or  ext2  or  minix"    exit 1fiif [ $fs = msdos ]; then	mountconfig=$mount/lilo.cnfelse	mountconfig=$mount/lilo.conffiif [ $debug = "true" ]; then	umount $mfile	echo ""	echo lilo = $lilo	echo device = $device	echo image = $image	echo kernel = $kernel	echo initrd = $initrd	echo append = \"$append\"	echo install = $install	echo format = $format	echo fs = $fs	echo size = $size	echo root = $root	echo compact = $compact	echo keymap = $keymap	echo isoimage = $isoimage	echo master = $master	echo ""	echo pause after parameter display	read alinefiif [ ! -f $kernel ]; then	echo "Kernel file " $kernel " does not exist"	exit 1fiif [ ! -z $initrd ]; then	if [ ! -f $initrd ]; then		echo "Initial ramdisk file " $initrd " does not exist"		exit 1	fifiif [ $isoimage != yes ]; then	echo ""	echo "Insert a blank floppy into $device"	echo "All information on this floppy will be destroyed"	echo "Press [Enter] to proceed, ^C to abort"	read alinefiif [ "$fast" = fast ]; then	rm -rf $mount $mfile	mkdir $mount	dd bs=1024 count=$size of=$mfile if=/dev/zero	bsize=$size	mpart=$mfile	if [ $size = $hdsize ]; then	    bios=0x80	    bsize=$(($size-$sectors))	    cat > $mtemp <<EOFnp1a1wEOF	    echo Partitioning HD "file   (this will take a minute)"	    fdisk -b 512 -S $sectors -H $heads -C $cylinders \		$mfile < $mtemp > /dev/null 2> /dev/null	    rm -f $mtemp	    echo bsize = $bsize#read aline	    losetup -d /dev/$loopback 2>/dev/null            losetup -d /dev/$looppart 2>/dev/null            losetup /dev/$loopback $mfile	    losetup -o $(($sectors*512)) /dev/$looppart $mfile	    mpart=/dev/$looppart	fi	echo Making filesystem	if [ "$fs" = ext2 ]; then		echo y | mkfs.$fs -N 24 -b 1024 $mpart $bsize	else		echo y | mkfs.$fs $mpart	fi	echo Mounting filesystem#read aline	if [ $size != $hdsize ]; then	    mount -t $fs -o rw,loop $mfile $mount	    loopback=`mount | grep $mfile | sed -e "sX.*loop=/dev/XX" -e "s/).*//"`	else	    mount -t $fs -o rw $mpart $mount	fi	if [ $debug = true ]; then		mount	fi	disk="/dev/$loopback"	if [ $debug = true ]; then		echo "disk=$disk"	fielse	if [ "$format" = "yes" ]; then		echo Formatting $device with $fs filesystem...		dd of=$device if=/dev/zero bs=512 count=1		if [ "$fs" = ext2 ]; then			mkfs -t $fs -N 24 -b 1024 $device 1>/dev/null 2>/dev/null		else			mkfs -t $fs $device 1>/dev/null 2>/dev/null		fi		echo done.		echo ""	fi	rm -rf $mount	mkdir $mount	mount -t $fs -o rw $device $mount	rm -rf $mount/*	disk=$deviceficat > $mountconfig <<EOF#  Begin mkrescue $version configuration fileinstall=$installboot=$devicemap=mapbackup=/dev/nullmessage=messageprompttimeout=150nowarngeometricdisk=$disk bios=$bios  sectors=$sectors heads=$heads cylinders=$cylindersEOFif [ $size = $hdsize ]; then	echo "  max-partitions=7" >>$mountconfig	echo "  partition=/dev/$looppart  start=$sectors" >>$mountconfig	echo static-bios-codes >>$mountconfig	bios=0x81else	bios=0x80fiif [ "$master" != "" -a $isoimage = yes ]; then	echo "disk=$master" >>$mountconfig	echo "  bios=$bios" >>$mountconfigelif [ "$master" != "" -a $debug = true ]; then	echo "disk=$master" >>$mountconfig	echo "  bios=$bios" >>$mountconfigfiif [ $keymap != us.ktl ]; then 	echo "keytable=lang.ktl" >>$mountconfigfiif [ $isoimage = yes ]; then 	echo "el-torito-bootable-CD" >>$mountconfigfiecho " " >>$mountconfigecho "image=linux" >>$mountconfigif [ ! -z $initrd ]; then	echo "  initrd=initrd" >>$mountconfigfiif [ ! -z "$append" ]; then	echo "  append=\"$append\"" >>$mountconfigficat >> $mountconfig <<EOF  root="$root"  read-onlyEOFif [ "$master" != "" -a $isoimage = yes ]; thencat >> $mountconfig <<EOFother=$master  unsafe  label=hard_diskEOFfiif [ "$diag" = yes ]; thencp -pv $boot/diag1.img $mountcp -pv $boot/diag2.img $mountcat >> $mountconfig <<EOFimage=diag1.img  label=diagnostic_1image=diag2.img  label=diagnostic_2EOFfiecho >>$mountconfig "#  End of mkrescue-generated configuration file"if [ $isoimage = yes ]; then	comment="El-Torito bootable-CD will boot at end of timeout"else	comment="floppy will boot in 15 seconds"firm -rf $mount/lost+foundcat > $mount/message <<EOFMKRESCUE version $version $commentUse  "boot: linux <options>"  to enter kernel optionsThe root device is currently configured as  root="$root"EOFecho `uname --sysname` `uname --release` > $mount/$(uname --release)syncif [ $debug = true ]; then	echo root=\"$root\"	echo ""	echo "pause after writing lilo.conf & message ..."	read alinefiecho "Copying files..."if [ $keymap != us.ktl ]; then 	cp -pv $keymap $mount/lang.ktlfiif [ ! -z $initrd ]; then	cp -pv $initrd $mount/initrdficp -pv $kernel $mount/linuxsyncecho "done."echo ""pushd $mount >/dev/null 2>/dev/nullif [ "$fast" = fast ]; then	bootcmd="-b /dev/$loopback"fiecho Running $lilo ...if [ $debug = true ]; thenif [ -z $log ]; then echo	$lilo -w+ -C $mountconfig $compact $bootcmd -v5	$lilo -w+ -C $mountconfig $compact $bootcmd -v5 || fast=errorelse echo	$lilo -w+ -C $mountconfig $compact $bootcmd -v5 ">$log"	$lilo -w+ -C $mountconfig $compact $bootcmd -v5 >$log || fast=errorfielse	$lilo -C $mountconfig $compact $bootcmd || fast=errorfipopd >/dev/null 2>/dev/nullif [ "$fast" = error ]; then	echo -n `$lilo -V`	echo " failure."else	echo done.fiecho ""umount $mountif [ $fast = error ]; then	rm -rf $mount	exit 1fiif [ $isoimage = yes ]; then	echo MKISOFS	out=$device	opt=	if [ $size = $hdsize ]; then	    losetup -d /dev/$looppart	    losetup -d /dev/$loopback	    opt=-hard-disk-boot	fi	mv $mfile $mount/boot.bin	mkisofs $opt -J -R -T \		-V LILO_BOOT -A "Linux Boot CD created by LILO mkrescue" \		-b boot.bin -c boot.cat -o $out $mount	cat <<EOFEND MKISOFS:  output is in  '$device'The bootable CD can be burned with the 'cdrecord' utilityusing a command of the form:	cdrecord [<options>] [dev=<device>] $deviceEOFelif [ "$fast" = fast ]; then	if [ $debug = true ]; then		echo Pause before transfering to $device		read aline	fi	dd if=$mfile of=$device bs=1024fiif [ $debug != true ]; then 	rm -f $mfilefiecho "All done."echo ""exit 0

⌨️ 快捷键说明

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