-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-rhvh-iso.sh
executable file
·137 lines (110 loc) · 4.75 KB
/
create-rhvh-iso.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
#!/bin/sh
set -e
###############################################################################
# John Call hacked this up for RHVH from Frank's work at
# https://github.com/RedHatGov/ssg-el7-kickstart.git
#
# see also: https://access.redhat.com/solutions/1147263
###############################################################################
# USAGE STATEMENT
function usage() {
cat << EOF
Error! Use this program to customize the Red Hat Virtualization Host (RHVH) ISO
usage: $0 /path/to/rhhi.ks /path/to/RHVH*.iso
EOF
exit 1
}
# Check for correct arguments
if [[ $# -ne 2 ]]; then usage; exit 1; fi
# Check for root user, required to mount the ISO and install required tools
if [[ $EUID -ne 0 ]]; then
tput setaf 1; echo -e "\033[1mPlease re-run this script as root!\033[0m"; tput sgr0; echo
echo "root is required to mount the ISO and install required tools"
echo "e.g. sudo $0 $@"
exit 1
fi
echo "Make sure all tools (genisoimage, isomd5sum, syslinux) are installed..."
rpm -q genisoimage || yum install -y genisoimage
rpm -q isomd5sum || yum install -y isomd5sum
rpm -q syslinux || yum install -y syslinux
echo "Checking for available disk space in /tmp"
volume_size=$(isoinfo -d -i $2 | awk '/Volume size/ {print $NF}')
block_size=$(isoinfo -d -i $2 | awk '/block size/ {print $NF}')
required_bytes=$(( volume_size * block_size ))
available_kilobytes=$(df --output=avail /tmp | awk '/^[0-9]/')
available_bytes=$(( available_kilobytes * 1024 ))
if [[ $required_bytes -gt $available_bytes ]]; then
tput setaf 1; echo -e "\033[1mNot enough free space in /tmp!\033[0m"; tput sgr0; echo
echo "Need $required_bytes bytes"
echo "Have $available_bytes bytes"
exit 1
fi
echo "Checking for available disk space in output directory ($(pwd))"
OUTDIR=$(pwd)
OUTFILE=$(basename $2 | sed 's/.iso$/-NEW.iso/')
available_kilobytes=$(df --output=avail $OUTDIR | awk '/^[0-9]/')
available_bytes=$(( available_kilobytes * 1024 ))
if [[ $required_bytes -gt $available_bytes ]]; then
tput setaf 1; echo -e "\033[1mNot enough free space to create ISO at $OUTDIR!\033[0m"; tput sgr0; echo
echo "Need $required_bytes bytes"
echo "Have $available_bytes bytes"
exit 1
fi
if [[ -e ${OUTDIR}/${OUTFILE} ]]; then
tput setaf 1; echo -e "\033[1mOutput file already exists at ${OUTDIR}/${OUTFILE}!\033[0m"; tput sgr0; echo
exit 1
fi
echo "Mount ISO image..."
SOURCE=$(mktemp -d)
DEST=$(mktemp -d)
mount -o loop $2 $SOURCE
echo "Copying ISO contents..."
shopt -s dotglob
cp -av ${SOURCE}/* ${DEST}/
echo "Unmount and cleanup temporary mount point..."
umount $SOURCE
rm -rv $SOURCE
#TODO: Extract isolinux.cfg and grub.cfg from the source ISO
# and patch them, instead of providing them
echo "Installing custom kickstarts..."
cp -v $1 ${DEST}/dota.ks
cp -v /home/jcall/Documents/FAA-Tech/*.ks ${DEST}/
echo "Patching BIOS and UEFI boot menus..."
cp -fv /home/jcall/Documents/storage-install/my_isolinux.cfg ${DEST}/isolinux/isolinux.cfg
cp -fv /home/jcall/Documents/storage-install/my_grub.cfg ${DEST}/EFI/BOOT/grub.cfg
echo "Remastering RHEL DVD Image..."
cd $DEST
# make boot image writeable, because `genisoimage` patches some layout data into it
chmod u+w isolinux/isolinux.bin
VOLNAME=$(isoinfo -d -i $2 | awk -F ': ' '/Volume id:/ {print $NF}')
genisoimage -R -J -T -m TRANS.TBL \
-V "$VOLNAME" -o ${OUTDIR}/${OUTFILE} \
-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot -e images/efiboot.img -no-emul-boot .
# make ISO bootable on UEFI systems
isohybrid --uefi ${OUTDIR}/${OUTFILE}
# Does this add the MD5SUM to the "-A" field of genisoimage?
# I don't think Red Hat supplies this in their official isos...
implantisomd5 ${OUTDIR}/${OUTFILE}
echo "Cleaning up..."
cd - &> /dev/null
rm -rf $DEST
echo "Created new ISO as ${OUTDIR}/${OUTFILE}"
exit 0
# Notes by John Call
# -J -- generate Joliet records, for Microsoft
# -R -- generate Rock Ridge records, for Linux (POSIX)
# -T -- generate translation tables (TRANS.TBL) for stuff older than Joliet and Rock Ridge
# -m TRANS.TBL -- exclude any TRANS.TBL files in the source tree from the output destination
# -V -- set the Volume ID !!!!!! This is referenced on the kernel cmdline to find the kickstart file !!!!!!!
# -o -- output file
#
# -b isolinux/isolinux.bin -- el torito boot image (in source tree)
# -c isolinux/boot.cat -- create this file/catalog (in source tree)
# -no-emul-boot -- ISOLINUX doesn't need HDD or FD emulation
# -boot-load-size 4 -- load 4*512bytes of the boot image during boot
# -boot-info-table -- patch/modify the isolinux.bin with 56 bytes of image layout
#
# -eltorito-alt-boot --
# -e (-efi-boot) images/efiboot.img -- EFI boot file
# -no-emul-boot -- use it again, for EFI boot / "isohybrid" - https://wiki.syslinux.org/wiki/index.php?title=Isohybrid#UEFI