New Defrag Utility in 2026

eric

Administrator
Staff member
Sep 2, 2021
1,232
2,127
113
MN
bluescsi.com
Did you have that on your 2026 bingo card? Now Linux and Mac users can defragment their SD cards for things like FloppyEMU which refuses to work with fragmented files, or BlueSCSI (though @polpo just added FastSeek which means fragmented files are fast regardless on a BlueSCSI/PicoIDE) But you can still if you absolutely need that 1% performance difference. Runs on Linux and macOS.


1772393637402.png


This is about my 5th attempt to make this utility - and honestly claude got me past the issues I was having in the prior 4 attempts.

I plan to release it opensource after some testers (you) and #MARCHintosh is over.

Give it a try it today! Find the latest downloads attached to this post!

This utility is currently named an uninspiring "fatdefrag" -- maybe that's good enough but I'd like some better ideas!

README:

# fatdefrag

A tool for defragmenting FAT32 and exFAT filesystems on Linux and macOS. Designed for SD cards used with embedded systems (e.g., SDFat library) where fragmented files cause significant performance degradation.

NOTE: This was originally created for BlueSCSI but since release v2026.02.08 is not required any more due to FastSeek by Ian (@polpo).

WARNING: Backup your data before any operation with this tool.

## Why?

When using FAT filesystems on SD cards with embedded devices, fragmented files force the SD card controller to perform multiple seeks through the FAT table, dramatically slowing sequential reads. In addition some devices such as the FloppyEMU can't read fragmented files.

Neither Linux nor macOS has a native FAT defragmentation tool. This project fills that gap.

## Features

- **Check fragmentation**: Analyze files and report extent counts
- **Single-file defrag**: Move a fragmented file to contiguous clusters
- **Full filesystem defrag**: Defragment all fragmented files at once
- **Crash recovery journaling**: Journal-based recovery for interrupted operations

## Portable Binaries

Pre-built x86_64 Linux binaries are available on the [GitHub Releases](https://github.com/erichelgeson/fatdefrag/releases) page. No compilation or dependencies required.

**GUI** (AppImage):
```bash
chmod +x fatdefrag-gui-x86_64.AppImage
./fatdefrag-gui-x86_64.AppImage
# If FUSE is unavailable:
./fatdefrag-gui-x86_64.AppImage --appimage-extract-and-run
```

**CLI/TUI** (statically linked):
```bash
chmod +x fatdefrag-linux-x86_64
./fatdefrag-linux-x86_64 check /dev/sdX1
```

**NixOS** users: AppImages require FUSE, which NixOS doesn't provide by default. Use `appimage-run`:
```bash
nix-shell -p appimage-run --run "appimage-run ./fatdefrag-gui-x86_64.AppImage"
```

## Building from Source

See [BUILDING.md](BUILDING.md) for build instructions, requirements, and portable build details.

## GUI Usage

Launch the GUI with:

```bash
./fatdefrag-gui-linux-x86_64 # or fatdefrag-gui-macOS-aarch64, etc.
```

**Features:**
- **Drive selector**: Shows only removable FAT32/exFAT drives (protects system drives)
- **Cluster map**: Visual representation of disk layout with real-time animation during defrag
- **Fragmented files list**: Click a file to highlight its clusters on the map
- **Defrag All / Defrag File**: Defragment everything or just selected files
- **Backup warning**: Confirmation dialog before any defrag operation

**Color Legend:**
- Dark blue: Free clusters
- Teal: Used (contiguous) clusters
- Orange/Red: Fragmented clusters
- Yellow pulse: Reading
- Green pulse: Writing
- White border: Selected file's clusters

**Note:** The GUI can enumerate drives without root, but defrag operations require block device access. On Linux, use`sudo` or add your user to the `disk` group. On macOS, the app will prompt for permission automatically.

## TUI Usage

A ncurses Terminal UI (TUI) remenicent of the DOS days.

Launch the TUI with:

```bash
./fatdefrag-tui-linux-x86_64 # or fatdefrag-tui-macOS-aarch64, etc.
```

**Keyboard Controls:**
| Key | Action |
|-----|--------|
| `↑/↓` | Change drive selection |
| `A` | Analyze selected drive |
| `D` | Defrag All (after analysis) |
| `S` | Stop current operation |
| `R` | Refresh drive list |
| `Q` | Quit |

**Color Legend:**
- White: Used clusters
- Cyan: Free clusters
- Red: Fragmented clusters
- Yellow: Reading
- Green: Writing

**Note:** Requires block device access. On Linux, use `sudo` or add your user to the `disk` group. On macOS, the app will prompt for permission automatically.

## CLI Usage

Requires block device access. On Linux, use `sudo` or add your user to the `disk` group. On macOS, the app will prompt for permission automatically.

```bash
# Analyze entire filesystem
fatdefrag check /dev/sdX1

# Analyze with verbose output (show fragmented files)
fatdefrag check /dev/sdX1 -v

# Check specific file
fatdefrag check /dev/sdX1 -f /path/to/file.bin

# Defragment all files (dry-run first)
fatdefrag defrag /dev/sdX1 -n

# Defragment all fragmented files
fatdefrag defrag /dev/sdX1

# Defragment a specific file
fatdefrag defrag /dev/sdX1 -f /path/to/file.bin

# Copy file contiguously to FAT device (dry-run first)
fatdefrag copy /path/to/source.bin /dev/sdX1:/dest.bin -n

# Copy file contiguously
fatdefrag copy /path/to/source.bin /dev/sdX1:/dest.bin
```

### Options

| Option | Description |
|--------|-------------|
| `-v, --verbose` | Show detailed output |
| `-f, --file <path>` | Specify file path on filesystem |
| `-n, --dry-run` | Don't make changes, show what would be done |
| `-h, --help` | Show help |

## Windows Users

For defragmenting FAT volumes on Windows, try [Defraggler](https://www.ccleaner.com/defraggler).

## License

Copyright (c) 2026 Eric Helgeson. All rights reserved. See [LICENSE](LICENSE) for details.

This project includes vendored third-party libraries under permissive open source licenses. See [THIRD_PARTY_LICENSES](THIRD_PARTY_LICENSES) for details.

And of course it has to have a TUI (Terminal UI) reminiscent of DEFRAG.EXE
1772393860455.png
 

Attachments

  • fatdefrag-macOS-aarch64.zip
    1.2 MB · Views: 59
  • fatdefrag-linux-x86_64.zip
    286.3 KB · Views: 53
  • fatdefrag-gui-AppImage.zip
    4.6 MB · Views: 69
Last edited:

Fizzbinn

Active Tinkerer
Nov 29, 2021
278
282
63
Charlottesville, VA
I humbly suggest "Retrodefragulator" or "Defragulator" for short.

Not sure why but inspired by this old gem that popped into my head when first thinking about it!

Another random thought, "Contiguous"

Going in a different direction...

Fatastic
Fatabulous
Fatdango
The Fat and the Furious
 
Last edited:

JDW

Administrator
Staff member
Founder
Sep 2, 2021
2,695
2,117
113
55
Japan
youtube.com
This is absolutely outstanding. You see, every single time I use my M1 Max 16" MBP to add a new disk image to the SD card of my FloppyEMU, the card gets fragmented. I've spent hours and hours trying nearly everything to prevent the fragmentation, but nothing worked. I don't have this problem so much on my BlueSCSI SD cards because I write new files to existing disk images on the SD via Basilisk II. However, if I add a new disk image (or delete anything), then the same horrid fragmentation happens. It seems to only happen on my M1 MBP, not my Intel Macs. And until now, the only cure was to boot Windows on my old 2015 15" MBP and use Defraggler to defrag the SD card. Thankfully, I no long need to resort to Windoze for that! I have confirmed that the new app by @eric works great to defrag my cards. This software is a real game changer! THANK YOU, ERIC!
 
  • Like
Reactions: djc6 and eric

djc6

New Tinkerer
Oct 19, 2024
52
13
8
## Portable Binaries

Pre-built x86_64 Linux binaries are available on the [GitHub Releases](https://github.com/yourusername/fatdefrag/releases) page. No compilation or dependencies required.

Eric, thank you for this amazing contribution! The URL in the README to download latest binaries seems incorrect - notice the "yourusername" in the URL.

I was hoping to see if an intel binary version for macOS exists.

Thanks!
 
  • Like
Reactions: eric

JDW

Administrator
Staff member
Founder
Sep 2, 2021
2,695
2,117
113
55
Japan
youtube.com
I tried the following URL variant WITH NO SUCCESS, so @eric needs to edit his earlier post to fix that URL:

Previously, when I was given the opportunity to beta test this software in private, I was able to use the following steps with success when using my Apple Silicon 16" MBP:
  1. I downloaded the software.

  2. I then launched Terminal.

  3. In Terminal, I typed the following WITH A SPACE AT THE END:
    xattr -cr

  4. Then I switched back to the Finder and dragged the file with "fatdefrag-gui" in its name onto the Terminal window, which inserts the path into the command line. After that I pressed return which gave me a new command prompt.

  5. I then copied & pasted the same path and pressed Return, which launched the app:
    1776991120539.png
Sadly, I tried the same steps again just now on my Intel 5K iMac at the office using the Leftmost & Rightmost downloadable files in the opening post, and it doesn't work. I guess that means during the beta test I must have been given a special binary made specifically for my Apple Silicon MBP.

All said, we need a valid URL to download the Binaries so those of us brain-dead to macOS Terminal and dependencies can use the latest version software.
 

eric

Administrator
Staff member
Sep 2, 2021
1,232
2,127
113
MN
bluescsi.com
You described none steps about what "doesn't work". I just downloaded the release on my M3 MBP and it worked (after I did the I'm not paying Apple $100 a year dance). There is no terminal required and no other dependencies required.
 

djc6

New Tinkerer
Oct 19, 2024
52
13
8
You described none steps about what "doesn't work".

for me the issue is when I run the binary, I get an error that it’s an ARM processor only binary and won’t run on my 2018 Mac mini (intel based).

I think there is a way to compile applications as a “fat” binary that works on ARM or Intel, that’s why I tried the GitHub link in the README to see if any other builds exist. But the URL doesn’t work.

I’m very excited for this tool to see if it helps with fragmentation issues I’ve had with my FloppyEmu device :) Thank You!
 

eric

Administrator
Staff member
Sep 2, 2021
1,232
2,127
113
MN
bluescsi.com
Ahh - JDW tested on his M-series mac. It has never been built for intel macs. File name gives this away.

Edit: FAT binary attached.
 

Attachments

  • fatdefrag-macOS-FAT.zip
    2.8 MB · Views: 5
Last edited:

JDW

Administrator
Staff member
Founder
Sep 2, 2021
2,695
2,117
113
55
Japan
youtube.com
Ahh - JDW tested on his M-series mac.
Privately, yes. But if you re-read my post in this thread today, you will see that when I tested it on my Intel 5K iMac today, it didn't work. Just wanted to mention that. That's why I had the same issue as @djc6 .

At work now. No time right now to test your new file. Will later.