#!/bin/bash | |
# This script prepare a bootable pendrive from a VMware ESXi iso image. | |
# the official install steps are documented here: | |
# https://docs.vmware.com/en/VMware-vSphere/6.7/vsphere-esxi-67-installation-setup-guide.pdf | |
# Use at Your own risk! | |
ISO=$1 | |
DEVICE=$2 | |
# Syslinux MBR image | |
MBR="/usr/share/syslinux/mbr.bin" | |
if [ $# -ne 2 ] | |
then | |
# print help | |
echo "Usage: $0 ISO_IMAGE DEVICE" | |
exit 1 | |
fi | |
syslinux --help 2>/dev/null || { echo "Error: syslinux package not found"; exit 11; } | |
if [[ ! -e "$MBR" || ! -f "$MBR" || ! -r "$MBR" ]] | |
then | |
echo "Error: '$MBR' file is not readable." | |
echo "Fix the syslinux MBR image location first!" | |
exit 12 | |
fi | |
if [[ -e "$ISO" && -f "$ISO" && -r "$ISO" ]] | |
then | |
echo "The following image will be used:" | |
file -b ${ISO} | |
echo | |
else | |
echo "Error: '$ISO' file is not readable and/or not a regular file" | |
exit 3 | |
fi | |
if [[ ! -b "$DEVICE" || ! -w "$DEVICE" ]] | |
then | |
echo "Error: Can't write to device: '$DEVICE'" | |
exit 2 | |
fi | |
echo "The following device will be wiped:" | |
lsblk -fp ${DEVICE} | |
echo | |
read -p "Type capital YES to continue: " confirm | |
if [ "$confirm" != "YES" ] | |
then | |
echo "Image creation cancelled." | |
exit 22 | |
fi | |
ISO_DIR=`mktemp -d` | |
DEVICE_DIR=`mktemp -d` | |
echo | |
echo "Preparing the partitions..." | |
sfdisk -q --delete ${DEVICE} | |
sleep 2 | |
echo 'label:dos' | sfdisk -q ${DEVICE} | |
echo 'type=c, bootable' | sfdisk -q ${DEVICE} | |
echo | |
sleep 2 | |
echo "Creating the filesystem..." | |
mkfs.vfat -F 32 -n USB ${DEVICE}1 | |
echo | |
sleep 2 | |
echo "Syslinux stuff..." | |
syslinux ${DEVICE}1 | |
cat ${MBR} > ${DEVICE} >/dev/null | |
echo | |
echo "Mounting the temporary directories..." | |
sleep 2 | |
mount -r ${ISO} ${ISO_DIR} | |
sleep 2 | |
mount ${DEVICE}1 ${DEVICE_DIR} | |
echo | |
sleep 2 | |
echo "Copying the files..." | |
cp -r ${ISO_DIR}/* ${DEVICE_DIR}/ | |
sed "s/APPEND -c boot.cfg/APPEND -c boot.cfg -p 1/" ${ISO_DIR}/isolinux.cfg > ${DEVICE_DIR}/syslinux.cfg | |
echo | |
sleep 2 | |
echo "Cleaning up the temporary directories..." | |
umount ${ISO_DIR} | |
umount ${DEVICE_DIR} | |
echo | |
echo "Cleaning up the temporary directories..." | |
rmdir ${ISO_DIR} | |
rmdir ${DEVICE_DIR} | |
echo | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment