forked from vmware/photon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk-setup-grub.sh
executable file
·148 lines (131 loc) · 4.25 KB
/
mk-setup-grub.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
#################################################
# Title: mk-setup-grub #
# Date: 2014-11-26 #
# Version: 1.0 #
# Author: [email protected] #
# Options: #
#################################################
# Overview
# This is a precursor for the vmware build system.
# This assumes that an empty hard disk is attached to the build VM.
# The path to this empty disk is specified in the HDD variable in config.inc
# End
#
grub_efi_install()
{
mkdir -p $BUILDROOT/boot/efi
#
# if it is a loop device then we should mount the dev mapped boot partition
#
if [[ $HDD == *"loop"* ]]
then
BOOT_PARTITION=/dev/mapper/`basename ${HDD}`p1
elif [[ $HDD == *"nvme"* ]]
then
BOOT_PARTITION=${HDD}p1
else
BOOT_PARTITION=${HDD}1
fi
mkfs.fat $BOOT_PARTITION
mount -t vfat $BOOT_PARTITION $BUILDROOT/boot/efi
cp boot/unifont.pf2 /usr/share/grub/
mkdir -p $BUILDROOT/boot/efi/EFI/Boot/
cp EFI/BOOT/* $BUILDROOT/boot/efi/EFI/Boot/
mkdir -p $BUILDROOT/boot/efi/boot/grub2
cat > $BUILDROOT/boot/efi/boot/grub2/grub.cfg << EOF
search -n -u ${BOOT_UUID} -s
configfile ${BOOT_DIRECTORY}grub2/grub.cfg
EOF
umount $BUILDROOT/boot/efi
}
grub_mbr_install()
{
$grubInstallCmd --target=i386-pc --force --boot-directory=$BUILDROOT/boot "$HDD"
}
set -o errexit # exit if error...insurance ;)
set -o nounset # exit if variable not initalized
set +h # disable hashall
PRGNAME=${0##*/} # script name minus the path
source config.inc # configuration parameters
source function.inc # commonn functions
LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}" # set log file name
ARCH=$(uname -m) # host architecture
[ ${EUID} -eq 0 ] || fail "${PRGNAME}: Need to be root user: FAILURE"
> ${LOGFILE} # clear/initialize logfile
# Check if passing a HHD and partition
if [ $# -eq 6 ]
then
BOOTMODE=$1
HDD=$2
ROOT_PARTITION_PATH=$3
BOOT_PARTITION_PATH=$4
BOOT_DIRECTORY=$5
BOOT_PARTITION_NUMBER=$6
fi
#
# Install grub2.
#
PARTUUID=$(blkid -s PARTUUID -o value $ROOT_PARTITION_PATH)
BOOT_UUID=$(blkid -s UUID -o value $BOOT_PARTITION_PATH)
grubInstallCmd=""
mkdir -p $BUILDROOT/boot/grub2
ln -sfv grub2 $BUILDROOT/boot/grub
command -v grub-install >/dev/null 2>&1 && grubInstallCmd="grub-install" && { echo >&2 "Found grub-install"; }
command -v grub2-install >/dev/null 2>&1 && grubInstallCmd="grub2-install" && { echo >&2 "Found grub2-install"; }
if [ "$BOOTMODE" == "bios" ]; then
if [ -z $grubInstallCmd ]; then
echo "Unable to find grub install command"
exit 1
fi
grub_mbr_install
fi
if [ "$BOOTMODE" == "efi" ]; then
grub_efi_install
fi
rm -rf ${BUILDROOT}/boot/grub2/fonts
cp boot/ascii.pf2 ${BUILDROOT}/boot/grub2/
mkdir -p ${BUILDROOT}/boot/grub2/themes/photon
cp boot/splash.png ${BUILDROOT}/boot/grub2/themes/photon/photon.png
cp boot/terminal_*.tga ${BUILDROOT}/boot/grub2/themes/photon/
cp boot/theme.txt ${BUILDROOT}/boot/grub2/themes/photon/
# linux-esx tries to mount rootfs even before nvme got initialized.
# rootwait fixes this issue
EXTRA_PARAMS=""
if [[ $HDD == *"nvme"* ]]; then
EXTRA_PARAMS=rootwait
fi
cat > $BUILDROOT/boot/grub2/grub.cfg << EOF
# Begin /boot/grub2/grub.cfg
set default=0
set timeout=5
search -n -u $BOOT_UUID -s
loadfont ${BOOT_DIRECTORY}grub2/ascii.pf2
insmod gfxterm
insmod vbe
insmod tga
insmod png
insmod ext2
insmod part_gpt
set gfxmode="640x480"
gfxpayload=keep
terminal_output gfxterm
set theme=${BOOT_DIRECTORY}grub2/themes/photon/theme.txt
load_env -f ${BOOT_DIRECTORY}photon.cfg
if [ -f ${BOOT_DIRECTORY}systemd.cfg ]; then
load_env -f ${BOOT_DIRECTORY}systemd.cfg
else
set systemd_cmdline=net.ifnames=0
fi
set rootpartition=PARTUUID=$PARTUUID
menuentry "Photon" {
linux ${BOOT_DIRECTORY}\$photon_linux root=\$rootpartition \$photon_cmdline \$systemd_cmdline $EXTRA_PARAMS
if [ -f ${BOOT_DIRECTORY}\$photon_initrd ]; then
initrd ${BOOT_DIRECTORY}\$photon_initrd
fi
}
# End /boot/grub2/grub.cfg
EOF
#Cleanup the workspace directory
rm -rf "$BUILDROOT"/tools
rm -rf "$BUILDROOT"/RPMS