📄 mkrescue
字号:
#!/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)#debug=falseversion=1.2usage () { cat <<EOFusage: `basename $0` [--help] `basename $0` [--version] `basename $0` [--device <device>] [--fast] [--fs ext2|msdos|minix] [--initrd <file> --kernel <file>] [--keymap <keymap.ktl>] [--nocompact] [--noformat] [--root <device>] --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 --initrd and --kernel are the initial ramdisk & kernel files --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 --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 running kernel bootedby lilo, the companion initrd (if any), and the current root filesystem tomake a bootable 1.44M rescue floppy.EOF exit $1}lilo=/sbin/lilo## lilo=$(pwd)/lilocompact=-cconfig=/etc/lilo.confdevice=/dev/fd0fs=ext2mount=/tmp/mkrescue-flpmfile=/tmp/mkrescue-emuloopback=loop4install=textformat=yesroot=currentfast=size=1440bootcmd=image=`cat /proc/cmdline | sed "s/.*BOOT_IMAGE=//" | sed "s/ .*//"`kernel=`$lilo -C $config -I $image i`if [ "$kernel" = "" ]; then exit 1;elif [ $debug = "true" ]; then echo kernel = "$kernel";fiinitrd=`$lilo -C $config -I $image r`if [ "$initrd" = "" ]; then exit 1;elif [ $debug = "true" ]; then echo initrd = "$initrd";fiif [ "$initrd" = "No initial ramdisk specified" ]; then initrd= ; fikeymap=`$lilo -C $config -I $image k`if [ "$keymap" = "" ]; then exit 1;elif [ $debug = "true" ]; then echo keymap = "$keymap";firoot=`mount | grep " on / type" | sed "s/ .*//"`if [ -z $root ]; then echo "Cannot find mounted root partition" echo "Using current root" root=currentfiwhile [ $# -gt 0 ]; do case $1 in --debug) debug=true ;; --device) shift device=$1 ;; --fast) fast=fast ;; --fs) shift fs=$1 ;; -h) usage 0 ;; --help) usage 0 ;; --initrd) shift initrd=$1 ;; --kernel) shift kernel=$1 ;; --keymap) shift keymap=$1 ;; --nocompact) compact= ;; --noformat) format=no ;; --root) shift root=$1 ;; --version) echo `basename $0` version $version exit 0 ;; *) echo "unrecognized argument: " $1 usage 1 ;; esac shiftdoneif [ $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 lilo = $lilo echo device = $device echo image = $image echo kernel = $kernel echo initrd = $initrd echo install = $install echo format = $format echo fs = $fs echo root = $root echo compact = $compact echo keymap = $keymap fiif [ ! -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 fifiecho ""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 alineif [ "$fast" = fast ]; then rm -rf $mount $mfile mkdir $mount dd bs=1024 count=$size of=$mfile if=/dev/zero echo Making filesystem echo y | mkfs -t $fs $mfile echo Mounting filesystem mount -t $fs -o loop=/dev/$loopback $mfile $mount if [ $debug = true ]; then mount fi disk="/dev/$loopback sectors=18 heads=2 cylinders=80"else if [ "$format" = "yes" ]; then echo Formatting $device with $fs filesystem... mkfs.$fs $device 1>/dev/null 2>/dev/null echo done. echo "" fi rm -rf $mount mkdir $mount mount -t $fs -o rw $device $mount rm -rf $mount/* disk=$deviceficat > $mountconfig <<EOFinstall=$installboot=$devicemap=mapbackup=/dev/nullmessage=messageprompttimeout=150geometricdefault=linuxdisk=$disk bios=0x00root=$rootread-onlyEOFif [ $keymap != us.ktl ]; then echo "keytable=lang.ktl" >>$mountconfigfiecho " " >>$mountconfigecho "image=linux" >>$mountconfigif [ ! -z $initrd ]; then echo " initrd=initrd" >>$mountconfigficat > $mount/message <<EOFmkrescue version $version floppy will boot in 15 secondsUse "boot: linux <options>" to enter kernel optionsThe root device is currently configured as root=$rootEOFecho `uname --sysname` `uname --release` > $mount/$(uname --release)syncif [ $debug = true ]; then 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 ""log=$(pwd)/mkrescue.logpushd $mount >/dev/null 2>/dev/nullif [ "$fast" = fast ]; then bootcmd="-b /dev/$loopback"fiecho Running $lilo ...if [ $debug = true ]; then echo $lilo -C $mountconfig $compact $bootcmd -v5 ">$log" $lilo -C $mountconfig $compact $bootcmd -v5 >$log || fast=errorelse $lilo -C $mountconfig $compact $bootcmd || fast=errorfipopd >/dev/null 2>/dev/nullif [ "$fast" = error ]; then echo lilo failure.else echo done.fiecho ""umount $mountrmdir $mountif [ "$fast" = fast ]; then dd if=$mfile of=$device bs=1024firm -f $mfileecho "All done."echo ""exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -