#!/usr/bin/env sh ISO_PATH="/path/to/centos.iso" # Must be an absolute path. USB_NAME="" USB_PATH="/Volumes/$USB_NAME" # Must be an absolute path # Mounting the ISO requires a privileged container. docker run --rm -it --privileged \ -v "$ISO_PATH":/centos.iso \ -v "$USB_PATH":/usb \ centos bash -c " echo -e '\033[0;32mInstalling Dependencies...\033[0m' sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* yum install -y grub2 grub2-efi-x64-modules rsync genisoimage # Mount the ISO at /mnt to access its contents. mount -o ro /centos.iso /mnt ISO_NAME=\$(isoinfo -d -i /centos.iso | grep -i 'Volume id:' | cut -d' ' -f3-) # Store the name of the ISO for later ISO_NAME=\$(isoinfo -d -i /centos.iso | grep -i 'Volume id:' | cut -d' ' -f3-) # Copy the contents of the ISO to the USB drive echo -e '\033[0;32mCopying ISO contents...\033[0m' rsync -ra --info=progress2 /mnt/. /usb/ # Generate a EFI boot image that can be used on Macs. It may be possible to # shorten this but it works. # This is adapted from https://unix.stackexchange.com/a/273334 echo -e '\033[0;32mCreating EFI boot image...\033[0m' grub2-mkimage -O x86_64-efi -o /usb/EFI/BOOT/BOOTX64.EFI -p /efi/grub \ disk part_msdos part_gpt linux loopback normal configfile test search \ search_fs_uuid search_fs_file true iso9660 test search_label efi_uga \ efi_gop gfxterm gfxmenu gfxterm_menu fat ext2 ntfs cat echo ls memdisk tar # Replace the default boot drive name with the actual boot drive name. echo -e '\033[0;32mFixing grub.cfg...\033[0m' sed -i \"s/\$ISO_NAME/$USB_NAME/g\" /usb/EFI/BOOT/grub.cfg umount /mnt "