Skip to content

Instantly share code, notes, and snippets.

@scottopell
Last active April 30, 2024 22:46
Show Gist options
  • Save scottopell/595717f0f77ef670f75498bd01f8cab1 to your computer and use it in GitHub Desktop.
Save scottopell/595717f0f77ef670f75498bd01f8cab1 to your computer and use it in GitHub Desktop.
Fix corrupted exFAT disk macOS/OSX

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
  6. Open Disk Utility and you should be able to repair here successfully.

See the apple man page below for details on the fsck_exfat utility.

Sources/Extra Reading: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/fsck_exfat.8.html https://craigsmith.id.au/2014/07/06/repairing-a-corrupted-mac-osx-exfat-partition/ https://discussions.apple.com/thread/4154638?tstart=0

@bonatoc
Copy link

bonatoc commented Dec 8, 2021

@krsnk — Did you try from the Terminal:

diskutil list

The volumes listed should show your disk ("rdisk2s1") and possibly its partitions.

Then, copy paste this (replace "disk2") in the example below with your disk's or partition's name (of course, remove "(but your disk)").

sudo ps -ax | grep disk2 (but your disk)

you should get the process number keeping your disk busy:

13699 ?? 11:52.83 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2

Then execute:

sudo kill 13699

In the example above, "13699" refers to the process currently busy, but it should be a different number on your machine.

After killing the process, the drive should mount, with a Finder's warning.

@mutoo
Copy link

mutoo commented Dec 11, 2021

Thanks, this fixed my Seagate SSD which can not be mounted

** Checking active bitmap.
Checking bitmap cluster 2
Read      offset = 0x000001f00000  length = 0x020000
Read      offset = 0x000000100000  length = 0x001000
Read      offset = 0x000000105000  length = 0x001000
Read      offset = 0x000000108000  length = 0x001000
Read      offset = 0x000000109000  length = 0x001000
Read      offset = 0x00000010a000  length = 0x001000
Read      offset = 0x00000010b000  length = 0x001000
   The bitmap needs to be repaired.
0000001B: FF should be BF
0000029B: FF should be 47
0000029C: FF should be CE
000002A0: FF should be 7F
000002A1: FF should be C3
00000402: FF should be FB
000004A6: FF should be FA
000004A7: FF should be F7
000004AF: FF should be 1F
000004B0: FF should be 00
000004B1: FF should be 00
000004B2: FF should be 40
000004B3: FF should be C7
000004B4: FF should be FC
000004B9: FF should be 7F
000004BA: FF should be EF
000004BC: FF should be FB
000004BD: FF should be DF
000004BE: FF should be 8C
000004BF: FF should be FE
000004C1: FF should be FE
000004CA: FF should be DD
000004CE: FF should be 07
000004CF: FF should be 00
000004D0: FF should be 00
000004D1: FF should be 00
000004D2: FF should be B0
000004D5: FF should be 9F
000004D7: FF should be 7F
000004D8: FF should be FC
00000504: FF should be EF
00000512: FF should be 3F
00000513: FF should be F8
00000537: FF should be FB
0000055A: FF should be EF
0000055B: FF should be 03
0000055C: FF should be E2
0000055D: FF should be 3C
0000055E: FF should be DF
0000055F: FF should be 97
00000561: FF should be 39
00000562: FF should be FE
00000563: FF should be C3
00000567: FF should be BF
00000568: FF should be FE
0000056E: FF should be FB
0000056F: FF should be 9F
00000570: FF should be 96
00000571: FF should be F8
00000573: FF should be 7F
00000574: FF should be F0
00000578: FF should be BE
0000057B: FF should be FD
00000580: FF should be 07
00000581: FF should be FE
00000582: FF should be 6F
00000583: FF should be FB
00000585: FF should be EF
00000587: FF should be F1
00000588: FF should be BE
00000589: FF should be D8
0000058A: FF should be FE
00000594: FF should be 87
00000595: FF should be EF
000005B6: FF should be 7F
000005BF: FF should be FD
000005CA: FF should be 8F
000005D2: FF should be 1F
000005D3: FF should be FE
000005D4: FF should be 7F
000005D5: C3 should be C0
00003B13: 0F should be 2F
Repair? yes
Checking bitmap cluster 3
Read      offset = 0x000001f20000  length = 0x020000
Checking bitmap cluster 4
Read      offset = 0x000001f40000  length = 0x020000
Checking bitmap cluster 5
Read      offset = 0x000001f60000  length = 0x020000
Checking bitmap cluster 6
Read      offset = 0x000001f80000  length = 0x020000
Checking bitmap cluster 7
Read      offset = 0x000001fa0000  length = 0x020000
Checking bitmap cluster 8
Read      offset = 0x000001fc0000  length = 0x020000
Checking bitmap cluster 9
Read      offset = 0x000001fe0000  length = 0x020000
192 clusters were marked used, but not referenced
0 clusters were marked used and CLUST_BAD
1 clusters were marked free, but referenced
** Rechecking main boot region.
** Rechecking alternate boot region.
Write     offset = 0x000001f00000  length = 0x020000
fsck_exfat: Couldn't write 131072 bytes at offset 32505856, errno 9: Bad file descriptor

There is an error at the end, but it seems OK. I can mount the SSD now, and everything comes back.

@bonatoc
Copy link

bonatoc commented Dec 13, 2021

After the disk becomes accessible again, I would advise to backup your data and reformat the hard drive using "Mac OS journaled" as the format.

While Mac OS X states exFAT partitions are compatible, it's probable we come across these problems in part because of that.

Making your hard drive fully compatible with OS X's file system can prevent future problems to arise.

@akashrajpal
Copy link

akashrajpal commented Dec 13, 2021 via email

@valdvit
Copy link

valdvit commented Dec 15, 2021

@bonatoc
Thank you, but I've already gone mad, gave up and bought a macbook.

@sleaze
Copy link

sleaze commented Dec 29, 2021

Thank you this was helpful.

@JingboXia
Copy link

It works. Thanks.

@soonergrrrl
Copy link

Did anyone ever solve this:

sudo fsck_exfat -d disk4s1
Opening /dev/rdisk4s1
fsck_exfat: Opened /dev/rdisk4s1 read-only
** Checking volume.
** Checking main boot region.
fsck_exfat: Invalid jump or signature
Main boot region is invalid. Trying alternate boot region.
** Checking alternate boot region.
fsck_exfat: Invalid jump or signature
Alternate boot region is invalid.
** The volume could not be verified completely.

It does not appear to be something busy, but I don't know enough about Terminal/DOS to be able to read this and see what is wrong. Disk Utility tells me that there is an orphaned cluster that can't be fixed when I try to run First Aid. So, I tried this route, but it isn't working either...

@cocotyty
Copy link

cocotyty commented Feb 1, 2022

sudo gdisk /dev/disk2
just w
Everything become ok!

@mitchelldmiller
Copy link

Open Disk Utility and you should be able to repair here successfully.

I forgot that Volume was open in Disk Utility - stuck on "resource busy" - while I found / applied this fix.
Unmountable USB disk was automagically mounted by disk utility, after fsck_exfat - Thank you!

@harrisondesbrosses
Copy link

Thank you, there seems to be a larger issue with ex_FAT volumes and M1 macs + Monterrey...

@stars-island
Copy link

Thank you for summarizing and sharing your idea about this!

Just wondering if it is safe to do this with my drive which has already stored piles of data. I just searched online but found nothing saying about that.

(I would say I am lazy but I have little spared storage for my large drive to backup data...)

@kurianoff
Copy link

I gotta pay you for this advice, cause I thought I lost my disk drive forever. THANKS A LOT!!!

@sandeepr79
Copy link

Awesome advice, I tried so many things in last couple of weeks without luck. Thanks a lot.

@edubskiy
Copy link

@krsnk — Did you try from the Terminal:

diskutil list

The volumes listed should show your disk ("rdisk2s1") and possibly its partitions.

Then, copy paste this (replace "disk2") in the example below with your disk's or partition's name (of course, remove "(but your disk)").

sudo ps -ax | grep disk2 (but your disk)

you should get the process number keeping your disk busy:

13699 ?? 11:52.83 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2

Then execute:

sudo kill 13699

In the example above, "13699" refers to the process currently busy, but it should be a different number on your machine.

After killing the process, the drive should mount, with a Finder's warning.

Thanks, man. You saved my day!

@jazzsequence
Copy link

Props for this. This is exactly what I needed to get my external drive working again. 👍

@onlyabhi52
Copy link

onlyabhi52 commented Jun 6, 2022

any one has faced this issue while launching the terminal - /dev/fd/14:type:296: bad option: -t

@gg4u
Copy link

gg4u commented Jun 28, 2022

Has anyone ever run into this , and can offer a solution?

It could be a bug of Apple..

sudo fsck_exfat -d disk1s2
....
Read      offset = 0x00001e2ba000  length = 0x001000
--- [1] Evicted 1 buffers (4096 bytes; 1 pages)
Read      offset = 0x00001e2bb000  length = 0x001000
Assertion failed: (result->data == NULL), function fsck_exfat_cache_recycle, file /SourceCache/exfat/exfat-66/fsck/fsck_exfat_cache.c, line 248.

laptop powered off while copying files to external drive.
Disk utilies from the GUI mac can't repair the disk.
Disk is now read only.

Please advise.

@Czechmix
Copy link

Czechmix commented Jul 16, 2022

I was able to run the sudo, but it didn't ask me for anything else after it was done. The drive now shows up in Disk Utility and I am currently doing the repair on a 4TB WD Red. It's been going for the past 4 hours stating "Checking system hierarchy". Hoping in the distant future this will resolve it not mounting to the desktop.

@edgarlim
Copy link

Thank you so much with this!

I am now able to mount my ExFat ext hdd in macOS.

Previously it only worked in Windows. You are a lifesaver!

@Harsha345155
Copy link

@edubskiy I tried your way but it's showing
zsh: unknown file attribute: b

I am lost.

@pmaingi
Copy link

pmaingi commented Feb 3, 2023

@krsnk — Did you try from the Terminal:
diskutil list
The volumes listed should show your disk ("rdisk2s1") and possibly its partitions.
Then, copy paste this (replace "disk2") in the example below with your disk's or partition's name (of course, remove "(but your disk)").

sudo ps -ax | grep disk2 (but your disk)

you should get the process number keeping your disk busy:
13699 ?? 11:52.83 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2
Then execute:
sudo kill 13699
In the example above, "13699" refers to the process currently busy, but it should be a different number on your machine.
After killing the process, the drive should mount, with a Finder's warning.

Thanks, man. You saved my day!

Thank you, i can now access my flash drive.

@edgarlim
Copy link

edgarlim commented Feb 3, 2023 via email

@alexisdray
Copy link

@gg4u just ran into the same issue, did you ever sort that out?
wondering whether to pull the plug and just reformat

@sergeydgr8
Copy link

I'm running into a similar issue as @gg4u where fsck_exfat fails:

--- [1] Evicted 1 buffers (262144 bytes; 16 pages)
Read      offset = 0x00000a036000  length = 0x001000
Assertion failed: (result != NULL), function fsck_exfat_cache_recycle, file fsck_exfat_cache.c, line 349.
[1]    24285 abort      sudo fsck_exfat -dy disk4s2

The debug logs show that it fails on the exact same file. Anyone have advice on how to combat this?

@fitnessbimbo
Copy link

Started with error
Checking volume.
** Checking main boot region.
fsck_exfat: Could not read boot region
** The volume could not be verified completely.

I've done all of the above with no luck. The latest error I get when I run diskutil verifyDisk /dev/disk2 is

Nonexistent, unknown, or damaged partition map scheme
If you are sure this disk contains a (damaged) APM, MBR, or GPT partition
scheme, you might be able to repair it with "diskutil repairDisk /dev/disk2"

I run diskutil repairDisk /dev/disk2 and get

Error repairing map: Input/output error (5)

Any suggestions?

@sergeydgr8
Copy link

So I figured out how to unbrick my drive, but it required loading up a VM of Windows in Parallels and directing USB over to it. Windows fixed the drive and loaded it up just fine, and after the job, it loaded up in macOS right after.

@lilyhara
Copy link

My external hard disk partition (disk2s1) can't be mounted and grayed out in disk utility.The error I get when I run
sudo fsck_exfat -d disk2s1 is

`Password:
Opening /dev/rdisk2s1
** Checking volume.
** Checking main boot region.
1953519616 total sectors; 512 bytes per sector
FAT starts at sector 2048; size 61440 sectors
7630688 clusters starting at sector 63488; 131072 bytes per cluster
Root directory starts at cluster 11
Read offset = 0x000000100000 length = 0x001000
** Checking system files.
Read offset = 0x000002020000 length = 0x020000
fsck_exfat: Couldn't read 131072 bytes at offset 33685504: Input/output error
No upper case translation table was found.
CONTINUE? Yes
Using default upper case translation table.
No main bitmap was found.

CONTINUE? Yes
**** Checking file system hierarchy.**
Directory /
Read offset = 0x000002020000 length = 0x020000
fsck_exfat: Couldn't read 131072 bytes at offset 33685504: Input/output error
Upper case translation table must be replaced.
Replace? Yes

Read offset = 0x000001f00000 length = 0x020000
fsck_exfat: Couldn't read 131072 bytes at offset 32505856: Input/output error
The volume could not be verified completely.

The disk utility gives me this error when I run first aid on the unmounted partition.

Running First Aid on “” (disk2s1)
Repairing file system.
Volume is already unmounted.
Performing fsck_exfat -y -x /dev/rdisk2s1
Checking volume.
Checking main boot region.
Checking system files.
No uppercase translation table was found.
Using default uppercase translation table.
No main bitmap was found.
Checking file system hierarchy.
Uppercase translation table must be replaced.`

Does anyone have same experience? Any suggestions? Thank you in advance :)

@minksW
Copy link

minksW commented Jul 5, 2023

halp pls

@berkeozkir
Copy link

I have been dealing with this error for almost 6 years now. My drives are big 6TB - 8TB I cannot use FAT32 for that reason I have to use exFat to make my drives compatible with both windows and Mac. The drives always mount on my windows machine but on Mac it randomly mounts. Apple needs to fix this. When I urgently have a need to access my data sometimes I cannot mount it on Mac so I have to use windows as a middle man or use virtual machine like parallels. It's interesting the Mac cannot mount but VM running on it can mount it. Anyways thanks for your help. It sucks that I always have to come here to check solutions because I forget the command prompts.

@dejanovicnenad
Copy link

dejanovicnenad commented Aug 16, 2023

@krsnk — Did you try from the Terminal:

diskutil list

The volumes listed should show your disk ("rdisk2s1") and possibly its partitions.

Then, copy paste this (replace "disk2") in the example below with your disk's or partition's name (of course, remove "(but your disk)").

sudo ps -ax | grep disk2 (but your disk)

you should get the process number keeping your disk busy:

13699 ?? 11:52.83 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2

Then execute:

sudo kill 13699

In the example above, "13699" refers to the process currently busy, but it should be a different number on your machine.

After killing the process, the drive should mount, with a Finder's warning.

This worked for me, but I had to use sudo kill -9 {PID} to kill the process successfully.

@Dax-87
Copy link

Dax-87 commented Nov 11, 2023

Thank you so much you saved my life.
I had 3 HDDs that failed at the same time.
With this guide I solved it.

@saxondigital
Copy link

Been fixing the OSX exFAT corruption using MS Windows 'chkdsk /r /f'

So far, has worked every time, but can take a couple hours on spinning disks.
The problem goes back many years (at least with OSX 10.11 - 10.14).

Next time (won't be long), I will try the Mac based method explained here.

@att11
Copy link

att11 commented Jan 2, 2024

Hi @scottopell, thanks, I tried this method, the result was:
** Checking volume.
** Checking main boot region.
fsck_exfat: Invalid jump or signature
Main boot region is invalid. Trying alternate boot region.
** Checking alternate boot region.
fsck_exfat: Invalid jump or signature
Alternate boot region is invalid.
** The volume could not be verified completely.

Any idea what might be wrong, how could I fix this? Thanks in advance, att

@Titencer
Copy link

Titencer commented Jan 6, 2024

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run 'sudo fsck_exfat -d '. eg 'sudo fsck_exfat -d disk1s3'
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
  6. Open Disk Utility and you should be able to repair here successfully.

Hey! Did this after getting my 6tb ExFat drive to at least be view only. Prior to this, I tried sudo pkill -f fsck but that did not allow the drive to mount, nor be repaired through First Aid. Since running the above command, it's been going files for a couple hours now. Is this supposed to take a super long time? Worried it's just stuck in fsck_exfat again. It's view only now but I won't be able to get another hard drive for a little bit.

@Titencer
Copy link

Titencer commented Jan 6, 2024

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run 'sudo fsck_exfat -d '. eg 'sudo fsck_exfat -d disk1s3'
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
  6. Open Disk Utility and you should be able to repair here successfully.

Hey! Did this after getting my 6tb ExFat drive to at least be view only. Prior to this, I tried sudo pkill -f fsck but that did not allow the drive to mount, nor be repaired through First Aid. Since running the above command, it's been going files for a couple hours now. Is this supposed to take a super long time? Worried it's just stuck in fsck_exfat again. It's view only now but I won't be able to get another hard drive for a little bit.

Adding to this - I'm running macOS Ventura 13.6.1 (22G313)

@heihaheihaha
Copy link

Hi @scottopell, thanks, I tried this method, the result was: ** Checking volume. ** Checking main boot region. fsck_exfat: Invalid jump or signature Main boot region is invalid. Trying alternate boot region. ** Checking alternate boot region. fsck_exfat: Invalid jump or signature Alternate boot region is invalid. ** The volume could not be verified completely.

Any idea what might be wrong, how could I fix this? Thanks in advance, att

My solution is link the disk to a Windows computer, it repaired the disk auto. Unbelievable.

@livingperson
Copy link

Also had issues mentioned above. My solution was to connect it to Windows, and do the following:

Run Disk Error Checking

  1. Plug in your external hard disk.
  2. Open File Explorer by pressing the Windows keys button + E.
  3. Go to This PC.
  4. Right-click your external hard disk under Devices and drives.
  5. Select Properties
  6. Go to Tools tab.
  7. Under Error checking, click Check.
  8. If prompted, click Yes or enter the administrator password.
  9. Click Scan drive > Repair drive.
  10. Wait for the process to finish.
  11. The scanning process may take a while depending on the size of your external hard disk and the specifications of your PC.

@suebphattana
Copy link

Also had issues mentioned above. My solution was to connect it to Windows, and do the following:

Run Disk Error Checking

  1. Plug in your external hard disk.
  2. Open File Explorer by pressing the Windows keys button + E.
  3. Go to This PC.
  4. Right-click your external hard disk under Devices and drives.
  5. Select Properties
  6. Go to Tools tab.
  7. Under Error checking, click Check.
  8. If prompted, click Yes or enter the administrator password.
  9. Click Scan drive > Repair drive.
  10. Wait for the process to finish.
  11. The scanning process may take a while depending on the size of your external hard disk and the specifications of your PC.

Saved my life! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment