| 1 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,111 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+################################################# |
|
| 2 |
+# Title: mk-setup-grub # |
|
| 3 |
+# Date: 2014-11-26 # |
|
| 4 |
+# Version: 1.0 # |
|
| 5 |
+# Author: sharathg@vmware.com # |
|
| 6 |
+# Options: # |
|
| 7 |
+################################################# |
|
| 8 |
+# Overview |
|
| 9 |
+# This is a precursor for the vmware build system. |
|
| 10 |
+# This assumes that an empty hard disk is attached to the build VM. |
|
| 11 |
+# The path to this empty disk is specified in the HDD variable in config.inc |
|
| 12 |
+# End |
|
| 13 |
+# |
|
| 14 |
+grub_efi_install() |
|
| 15 |
+{
|
|
| 16 |
+ mkdir $BUILDROOT/boot/efi |
|
| 17 |
+ mkfs.vfat /dev/sda1 |
|
| 18 |
+ mount -t vfat /dev/sda1 $BUILDROOT/boot/efi |
|
| 19 |
+ cp boot/unifont.pf2 /usr/share/grub/ |
|
| 20 |
+ grub2-efi-install --target=x86_64-efi --efi-directory=$BUILDROOT/boot/efi --bootloader-id=Boot --root-directory=$BUILDROOT --recheck --debug |
|
| 21 |
+ mv $BUILDROOT/boot/efi/EFI/Boot/grubx64.efi $BUILDROOT/boot/efi/EFI/Boot/bootx64.efi |
|
| 22 |
+ umount $BUILDROOT/boot/efi |
|
| 23 |
+} |
|
| 24 |
+ |
|
| 25 |
+grub_mbr_install() |
|
| 26 |
+{
|
|
| 27 |
+ $grubInstallCmd --force --boot-directory=$BUILDROOT/boot "$HDD" |
|
| 28 |
+} |
|
| 29 |
+ |
|
| 30 |
+set -o errexit # exit if error...insurance ;) |
|
| 31 |
+set -o nounset # exit if variable not initalized |
|
| 32 |
+set +h # disable hashall |
|
| 33 |
+PRGNAME=${0##*/} # script name minus the path
|
|
| 34 |
+source config.inc # configuration parameters |
|
| 35 |
+source function.inc # commonn functions |
|
| 36 |
+LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}" # set log file name
|
|
| 37 |
+#LOGFILE=/dev/null # uncomment to disable log file |
|
| 38 |
+ARCH=$(uname -m) # host architecture |
|
| 39 |
+[ ${EUID} -eq 0 ] || fail "${PRGNAME}: Need to be root user: FAILURE"
|
|
| 40 |
+> ${LOGFILE} # clear/initialize logfile
|
|
| 41 |
+ |
|
| 42 |
+# Check if passing a HHD and partition |
|
| 43 |
+if [ $# -eq 3 ] |
|
| 44 |
+ then |
|
| 45 |
+ BOOTMODE=$1 |
|
| 46 |
+ HDD=$2 |
|
| 47 |
+ PARTITION=$3 |
|
| 48 |
+fi |
|
| 49 |
+ |
|
| 50 |
+# |
|
| 51 |
+# Install grub2. |
|
| 52 |
+# |
|
| 53 |
+UUID=$(blkid -s UUID -o value $PARTITION) |
|
| 54 |
+ |
|
| 55 |
+grubInstallCmd="" |
|
| 56 |
+mkdir -p $BUILDROOT/boot/grub2 |
|
| 57 |
+ln -sfv grub2 $BUILDROOT/boot/grub |
|
| 58 |
+command -v grub-install >/dev/null 2>&1 && grubInstallCmd="grub-install" && { echo >&2 "Found grub-install"; }
|
|
| 59 |
+command -v grub2-install >/dev/null 2>&1 && grubInstallCmd="grub2-install" && { echo >&2 "Found grub2-install"; }
|
|
| 60 |
+if [ -z $grubInstallCmd ]; then |
|
| 61 |
+echo "Unable to found grub install command" |
|
| 62 |
+exit 1 |
|
| 63 |
+fi |
|
| 64 |
+ |
|
| 65 |
+if [ "$BOOTMODE" == "bios" ]; then |
|
| 66 |
+ grub_mbr_install |
|
| 67 |
+fi |
|
| 68 |
+if [ "$BOOTMODE" == "efi" ]; then |
|
| 69 |
+ grub_efi_install |
|
| 70 |
+fi |
|
| 71 |
+ |
|
| 72 |
+cp boot/unifont.pf2 ${BUILDROOT}/boot/grub2/
|
|
| 73 |
+mkdir -p ${BUILDROOT}/boot/grub2/themes/photon
|
|
| 74 |
+cp boot/splash.tga ${BUILDROOT}/boot/grub2/themes/photon/photon.tga
|
|
| 75 |
+cp boot/terminal_*.tga ${BUILDROOT}/boot/grub2/themes/photon/
|
|
| 76 |
+cp boot/theme.txt ${BUILDROOT}/boot/grub2/themes/photon/
|
|
| 77 |
+cat > "$BUILDROOT"/boot/grub2/grub.cfg << "EOF" |
|
| 78 |
+# Begin /boot/grub2/grub.cfg |
|
| 79 |
+set default=0 |
|
| 80 |
+set timeout=5 |
|
| 81 |
+set root=(hd0,2) |
|
| 82 |
+loadfont /boot/grub2/unifont.pf2 |
|
| 83 |
+ |
|
| 84 |
+insmod gfxterm |
|
| 85 |
+insmod vbe |
|
| 86 |
+insmod tga |
|
| 87 |
+ |
|
| 88 |
+set gfxmode="640x480" |
|
| 89 |
+gfxpayload=keep |
|
| 90 |
+ |
|
| 91 |
+terminal_output gfxterm |
|
| 92 |
+ |
|
| 93 |
+set theme=/boot/grub2/themes/photon/theme.txt |
|
| 94 |
+ |
|
| 95 |
+menuentry "Photon" {
|
|
| 96 |
+ insmod ext2 |
|
| 97 |
+ insmod part_gpt |
|
| 98 |
+ linux /boot/vmlinuz-4.0.9 init=/lib/systemd/systemd root=UUID=UUID_PLACEHOLDER loglevel=3 ro |
|
| 99 |
+ initrd /boot/initrd.img-no-kmods |
|
| 100 |
+} |
|
| 101 |
+# End /boot/grub2/grub.cfg |
|
| 102 |
+EOF |
|
| 103 |
+ |
|
| 104 |
+sed -i "s/UUID_PLACEHOLDER/$UUID/" "$BUILDROOT"/boot/grub2/grub.cfg > ${LOGFILE}
|
|
| 105 |
+ |
|
| 106 |
+#Cleanup the workspace directory |
|
| 107 |
+rm -rf "$BUILDROOT"/tools |
|
| 108 |
+rm -rf "$BUILDROOT"/RPMS |
|
| 109 |
+ |
|
| 110 |
+#umount $BUILDROOT |