diskutil

Format a USB drive and create a Windows 11 ISO

Following instructions details here.

## ONE-TIME SETUP
brew install wimlib

# --- PER USB ---

# 1. Find the USB disk id — VERIFY this every time (it erases!)
diskutil list external

# 2. Format as FAT32, MBR scheme (needed for UEFI boot)
diskutil eraseDisk MS-DOS "WIN11" MBR /dev/disk4      # <-- swap disk4

# 3. Mount the ISO, then find its volume name (CHANGES every download)
hdiutil attach ~/Downloads/Win11.iso
ls /Volumes                                            # note the CCCOMA_... name

# 4. Copy everything EXCEPT install.wim
#    trailing slash on the SOURCE is mandatory, or files nest one level deep
rsync -vha --exclude=sources/install.wim "/Volumes/CCCOMA_X64FRE_EN-US_DV9/" /Volumes/WIN11/

# 5. Split install.wim into <4 GB chunks (FAT32 can't hold the whole file)
wimlib-imagex split "/Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.wim" /Volumes/WIN11/sources/install.swm 3800

# 6. Verify and eject
ls -lh /Volumes/WIN11/sources/install.swm*
diskutil eject /dev/disk4

Format a USB drive with an ESXi installer

I heavily borrowed this approach and associated commands from this Github project. To prep:

  • Download the ESXi ISO file to a folder on your machine and name it esxi.iso
  • Download the syslinux.cfg file from the Github project link into the same folder
  • In Terminal, cd to the destination directory where these two files live and do this:

Terminal commands:

diskutil list

(This command is to identify your USB drive...in most cases it's /dev/disk2 but be careful!!! My commands below assume /dev/disk2!!11!111!!!!)

sudo diskutil eraseDisk MS-DOS ESXI MBR /dev/disk2
mkdir -p source
mkdir -p target
hdiutil mount esxi.iso -mountpoint ./source
cp -r source/ /Volumes/ESXI/
cp syslinux.cfg /Volumes/ESXI/
hdiutil eject ./source
diskutil unmountDisk /dev/disk2
diskutil eject /dev/disk2

Secure erase the primary Mac OS drive

First create a USB install of Mac OS, boot to it, and drop to Terminal. Then find your physical disk path:

diskutil list

Unmount it (in my case disk0):

diskutil unmountDisk disk0

Then secure erase it:

diskutil secureErase 2 disk0

(Run diskutil secureErase) to see all the options. I did option 2 which is a seven-pass "secure" erase)