Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CentOS 7 USB kickstart installation
#! /bin/bash
# Make a CentOS 7 DVD installer on a USB drive that offers the option
# of doing an automated install via a kickstart file (given by $url
# below).
set -eu
url="http://tftpboot:8000/kickstart/box.cfg"
##### WARNING: make sure this is correct:
usb="/dev/disk/by-id/usb-_Patriot_Memory_0701412932122412-0:0"
iso="/tftpboot/ISO/CentOS/CentOS-7-x86_64-DVD-1503-01.iso"
tmp="/backup/tmp/centos7-respin"
mnt="/mnt/centos7iso"
if [ ! -e "$usb" ]; then
echo USB drive $usb
echo does not exist
exit 1
fi
set -x
mkdir -p $mnt
rm -fr $tmp
mkdir -p $tmp/CentOS-7-unpacked
mkdir -p $tmp/CentOS-7-KS-iso
function cleanup {
if mount | grep -q "$mnt"; then
umount $mnt
fi
}
trap cleanup 0
# put in a list so we can edit this script while it's being executed
{
mount -o loop $iso $mnt
rsync -aq $mnt/ $tmp/CentOS-7-unpacked
umount $mnt
set +x
cat <<EOF
Now add something like the following lines to
$tmp/CentOS-7-unpacked/isolinux/isolinux.cfg:
label linuxks
menu label ^Install CentOS 7 with Kickstart
append ... ks=$url
inst.repo=http://tftpboot:8000/centos/7/os/x86_64/
EOF
echo -n "Hit ENTER when done:"
read answer
set -x
newiso=$tmp/CentOS-7-KS-iso/CentOS-7.0-KS-x86_64-DVD.iso
# NOTE: the -volid needs to match the isolinux.cfg LABEL= value
genisoimage -untranslated-filenames \
-volid 'CentOS 7 x86_64' -J -joliet-long -rational-rock \
-translation-table -input-charset utf-8 \
-x ./lost+found \
-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 \
-T -o $newiso $tmp/CentOS-7-unpacked/
isohybrid -u $newiso
# bs=4M seems to be much faster than no bs at all
time dd bs=4M if=$newiso of=$usb
udisks --detach $usb
exit 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment