static usb ethnet addresses
[automated-distro-installer] / fai / config / scripts / ROCKY / 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 if [ -f $target/usr/sbin/grub2-install ]; then
40
41 # CentOS 7
42 $ROOTCMD grub2-install --no-floppy "$BOOT_DEVICE"
43 $ROOTCMD grub2-mkconfig --output=/boot/grub2/grub.cfg
44 else
45
46 $ROOTCMD grub-install --just-copy
47
48 $ROOTCMD grub --device-map=/dev/null --no-floppy --batch <<-EOF
49 device $bootdev $BOOT_DEVICE
50 root $bootpart
51 setup $bootdev
52 quit
53 EOF
54
55 ln -s ./menu.lst $target/boot/grub/grub.conf
56
57 if [ -f $target/boot/grub/splash.xpm.gz ]; then
58 pretty="splashimage=$bootpart$bootdir/grub/splash.xpm.gz"
59 else
60 pretty="color cyan/blue white/blue"
61 fi
62
63 title=$(head -1 $target/etc/redhat-release)
64
65 cat > $target/boot/grub/grub.conf <<-EOF
66 timeout 5
67 default 0
68 $pretty
69 hiddenmenu
70
71 title $title
72 root $bootpart
73 kernel $bootdir/vmlinuz-$version root=$ROOT_PARTITION ro
74 initrd $bootdir/initramfs-$version.img
75 EOF
76
77 fi
78
79 umount $target/dev
80
81 echo ""
82 echo "Grub installed on $BOOT_DEVICE = $bootdev"
83 echo "Grub boot partition is $BOOT_PARTITION = $bootpart"
84 echo "Root partition is $ROOT_PARTITION"
85 echo "Boot kernel: $version"
86
87 exit $error