122 lines
2.0 KiB
Bash
Executable File
122 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# DESCRIPTION: install bootloader for OS
|
|
#
|
|
# SCRIPT NAME: install_bootloader.sh
|
|
#
|
|
# Input:
|
|
# [--help] show this message
|
|
# <-t|--type> boot loader type:grub,etc.
|
|
# Output:
|
|
# NULL
|
|
# Return value:
|
|
# 1 argument error
|
|
# 2 bootloader type doesn't specify
|
|
# 3 bootloader no implement
|
|
# 127 bootloader utils not found
|
|
#
|
|
# AUTHOR: Qin Bo
|
|
#
|
|
# EMAIL: bqin@linx-info.com
|
|
#
|
|
# DATE: 2010-09-02
|
|
#
|
|
# HISTORY:
|
|
# REVISOR DATE MODIFICATION
|
|
# Qin Bo 2010-09-02 create
|
|
#
|
|
#
|
|
#
|
|
|
|
source ./functions
|
|
|
|
usage ()
|
|
{
|
|
if [ "$1" == "-n" ];then
|
|
cmd="info"
|
|
ret=0
|
|
else
|
|
cmd="err"
|
|
ret=1
|
|
fi
|
|
$cmd "
|
|
This script will install boot loader for system
|
|
|
|
Usage: $0 options
|
|
|
|
options:
|
|
[--help] show this message
|
|
<-t|--type> boot loader type:grub, etc.
|
|
|
|
"
|
|
return $ret
|
|
}
|
|
|
|
install_grub ()
|
|
{
|
|
|
|
# generate device.map
|
|
grub --batch --no-floppy --device-map="$DEVICEMAP" << EOF 1>>"$DEV_LOG" 2>&1
|
|
quit
|
|
EOF
|
|
# in order to let bios to load grub correct,
|
|
# we install grub to first hard disk by default,
|
|
# so even though OS install in secondary hard disk,
|
|
# the OS still can be loaded from first hard disk.
|
|
|
|
f_hd=$(grep "(hd0)" "$DEVICEMAP"|awk '{print $NF}')
|
|
|
|
grub-install --no-floppy --root-directory=$TARGET $f_hd 1>>$DEV_LOG 2>&1
|
|
}
|
|
|
|
main ()
|
|
{
|
|
if [ $# -eq 0 ];then
|
|
usage; erv
|
|
fi
|
|
|
|
tmp=$(getopt -o t: --long type:,help -- "$@" 2>>$DEV_LOG)
|
|
if [ $? -ne 0 ];then
|
|
usage; erv
|
|
fi
|
|
|
|
# set all argument to arg variable
|
|
eval set -- "$tmp"
|
|
|
|
while true ;do
|
|
case "$1" in
|
|
-t|--type)
|
|
type="$2"
|
|
shift 2
|
|
;;
|
|
--help) usage -n; exit 0 ;;
|
|
# shift the last "--", this dash is define by getopt (more information see man getopt)
|
|
--) shift; break;;
|
|
*) usage; erv ;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$type" ];then
|
|
case "$type" in
|
|
grub)
|
|
install_grub
|
|
erv
|
|
;;
|
|
*)
|
|
err "$type bootloader no implement yet !"
|
|
exit 3
|
|
;;
|
|
esac
|
|
else
|
|
err "bootloader type doesn't specify"
|
|
exit 2
|
|
fi
|
|
}
|
|
|
|
GRUB_DIR="$TARGET/boot/grub"
|
|
DEVICEMAP="$GRUB_DIR/device.map"
|
|
|
|
main "$@"
|
|
|
|
|