A small Bash script that wipes a USB stick and reformats it as NTFS (default) or exFAT, so Windows can read it after Ubuntu mkusb chewed it up. It refuses to touch anything that looks like a system disk.
One pass, five steps. wipefs clears the old signatures, sgdisk writes a fresh GPT with a single full-size partition, then mkfs.ntfs or mkfs.exfat lays down the filesystem. Before any of that, every partition on the device is unmounted through udisksctl so udisks2 does not auto-remount mid-format.
If the wipe fails because something is still holding the device, the script runs its own diagnostic (lsblk, mount, fuser, pvs, lvs) and prints what is in the way before bailing out.
Pull the script, mark it executable, preview the run, then commit:
curl -O https://raw.githubusercontent.com/cocodedk/usb-formatter/main/format-usb.sh
chmod +x format-usb.sh
./format-usb.sh /dev/sdX KINGSTON --dry-run
sudo ./format-usb.sh /dev/sdX KINGSTON
--dry-run first. It does not need root and prints every command it would execute, so you can confirm the right device before handing it sudo.
| flag | effect |
|---|---|
| --ntfs | Format as NTFS. Default. Reads on Windows out of the box. |
| --exfat | Format as exFAT instead. Better for files over 4 GB on cameras and TVs. |
| -n, --dry-run | Print every step without changing anything. No root needed. |
| -d, --diagnose | Inspect the device only — mounts, holders, LVM. Use when a previous run failed busy. |
| -h, --help | Print usage and exit. |
/sys/block/<dev>/removable. If it is not 1, the script refuses. Internal SSDs and NVMe drives never pass this check./, /home, or /boot, the run aborts before anything is touched.swapon --show), the script will not wipe it.udisksctl unmount --no-user-interaction, then falls back to umount and finally lazy umount -l. udisks2 is told not to remount.wipefs fails, the diagnostic block runs automatically and prints holders, mounts, and LVM state before the script exits.YES to proceed. --dry-run skips this and changes nothing.The most common failure is "device busy" — a file manager opened a partition the moment you plugged the stick in. Run the diagnostic to see the holder:
sudo ./format-usb.sh /dev/sdX --diagnose
You get an lsblk tree, all live mount entries, the output of fuser -v on every partition node, and the LVM picture from pvs and lvs. Close the file manager (or kill the holder), unplug, replug, retry.