Files
new_install/operation/install_bootloader.sh
Peng Zhihui 3c0236842a rewrite text isntall interface and partition-tool
modified:   dialog/di_dialog.py
	modified:   dialog/di_main.py
	new file:   dialog/di_newt.py
	modified:   interface/ri_inst_cli.py
	modified:   interface/ri_oper.py
	new file:   new_partition/finddisk.sh
	new file:   new_partition/list-devices
	new file:   new_partition/new_partition.py
	new file:   new_partition/parted_devices
	new file:   new_partition/parted_devices.py
	modified:   operation/configure_bootloader_cnf.sh
	modified:   operation/copy_kernels.sh
	modified:   operation/install_bootloader.sh
	modified:   xml/config.xml
	modified:   xml/dependency.xml
2013-12-20 11:10:32 +08:00

157 lines
2.8 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
}
# This should probably be rewritten using udevadm or similar.
# from di grub-install
device_to_disk ()
{
echo "$1" | \
sed 's:\(/dev/\(cciss\|ida\|rs\)/c[0-9]d[0-9][0-9]*\|/dev/mmcblk[0-9]\|/dev/\(ad\|da\)[0-9]\+\|/dev/[hs]d[0-9]\+\|/dev/[a-z]\+\).*:\1:'
}
install_grub2()
{
mount -obind /dev $TARGET/dev
mount -obind /proc $TARGET/proc
mount -obind /sys $TARGET/sys
boot_dev=$(chroot $TARGET grub-probe -t device /boot)
disk=$(device_to_disk $boot_dev)
chroot $TARGET update-grub > /dev/null 2>&1
chroot $TARGET grub-install $disk --force > /dev/null 2>&1
chroot $TARGET update-grub > /dev/null 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
;;
grub2)
install_grub2
erv
;;
elilo)
echo "install elilo";
sed -i '/tmppoint/d' $TARGET/etc/fstab
umount /tmp/tmppoint
rm -rf /tmp/tmppoint
;;
*)
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 "$@"