update to 31b795ca71189b326b80666076398f31aea4f2be
[automated-distro-installer] / fai / config / scripts / CENTOS / 40-install-grub
1 #! /bin/bash
2
3 # (c) Michael Goetze, 2011, mgoetze@mgoetze.net
4 # (c) Thomas Lange 2014
5
6 error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
7
8 if [ -r $LOGDIR/disk_var.sh ] ; then
9 . $LOGDIR/disk_var.sh
10 else
11 echo "disk_var.sh not found!"
12 exit 1
13 fi
14
15
16 # CentOS 7 does not have a device.map file, so generate one
17 if [ -d $target/boot/grub2 -a ! -f $target/boot/grub2/device.map ]; then
18 echo "# Generated by FAI" >> $target/boot/grub2/device.map
19 centosdisks=$(awk '/[sv]d.$/ {print $4}' /proc/partitions | sort)
20 dcount=0
21 for d in $centosdisks; do
22 echo "(hd$dcount) /dev/$d" >> $target/boot/grub2/device.map
23 dcount=$((dcount + 1))
24 done
25 fi
26
27 bootdev=$(device2grub $BOOT_DEVICE)
28 bootpart=$(device2grub $BOOT_PARTITION)
29 version=$($ROOTCMD rpm -qv kernel | cut -d- -f2-)
30
31 if grep '[[:space:]]/boot[[:space:]]' $LOGDIR/fstab; then
32 bootdir=''
33 else
34 bootdir='/boot'
35 fi
36
37 mount -o bind /dev $target/dev
38
39
40
41 if [ -f $target/usr/sbin/grub2-install ]; then
42
43 # CentOS 7
44 $ROOTCMD grub2-install --no-floppy "$BOOT_DEVICE"
45 $ROOTCMD grub2-mkconfig --output=/boot/grub2/grub.cfg
46 else
47
48 $ROOTCMD grub-install --just-copy
49
50 $ROOTCMD grub --device-map=/dev/null --no-floppy --batch <<-EOF
51 device $bootdev $BOOT_DEVICE
52 root $bootpart
53 setup $bootdev
54 quit
55 EOF
56
57 ln -s ./menu.lst $target/boot/grub/grub.conf
58
59 if [ -f $target/boot/grub/splash.xpm.gz ]; then
60 pretty="splashimage=$bootpart$bootdir/grub/splash.xpm.gz"
61 else
62 pretty="color cyan/blue white/blue"
63 fi
64
65 if [ -f $target/sbin/dracut -o -f $target/usr/sbin/dracut ]; then
66 # CentOS 6
67 iname=initramfs
68 else
69 # CentOS 5
70 iname=initrd
71 fi
72 title=$(head -1 $target/etc/redhat-release)
73
74 cat > $target/boot/grub/grub.conf <<-EOF
75 timeout 5
76 default 0
77 $pretty
78 hiddenmenu
79
80 title $title
81 root $bootpart
82 kernel $bootdir/vmlinuz-$version root=$ROOT_PARTITION ro
83 initrd $bootdir/$iname-$version.img
84 EOF
85
86 fi
87
88 umount $target/dev
89
90 echo ""
91 echo "Grub installed on $BOOT_DEVICE = $bootdev"
92 echo "Grub boot partition is $BOOT_PARTITION = $bootpart"
93 echo "Root partition is $ROOT_PARTITION"
94 echo "Boot kernel: $version"
95
96 exit $error