How to Check and Fix an SD Card with fsck
In this article
Yes, you can check and fix an SD card using the fsck command on Linux (or macOS with some adjustments). This tool scans the card's file system for errors and repairs them, which can resolve corruption, unreadable files, or cards that won't mount properly. Before you start, back up any data you can access—fsck can sometimes make things worse if the card is severely damaged. You'll need a card reader, a computer running Linux (or macOS with the built-in fsck_hfs for HFS+ cards), and the card itself.
What You'll Need
- An SD card reader (built-in or USB)
- A computer running Linux (or macOS, with steps noted)
- The SD card you want to check
- Access to a terminal (command line)
- Optional: a backup location for any recoverable files
Step-by-Step
- Insert the SD card into your card reader and plug it into your computer. Wait a few seconds for the system to detect it.
- Identify the device name of the SD card. Open a terminal and run
lsblk(Linux) ordiskutil list(macOS). Look for a device like/dev/sdbor/dev/disk2that matches the card's size. The card usually appears as a whole disk (e.g.,sdb) with partitions (e.g.,sdb1). If unsure, remove the card, run the command again, and note which device disappears. - Unmount the card (or at least the partition you'll check). On Linux:
sudo umount /dev/sdb1(replace with your partition). On macOS:diskutil unmount /dev/disk2s1. Do not skip this—fsck cannot run on a mounted file system. - Run fsck on the partition. For Linux, use
sudo fsck /dev/sdb1. If the card is formatted as FAT32 or exFAT (common for SD cards), you may need to specify the type:sudo fsck -t vfat /dev/sdb1(for FAT) orsudo fsck.exfat /dev/sdb1(if exfat-utils is installed). For macOS, if the card is HFS+, usefsck_hfs /dev/disk2s1(you may need to runsudo fsck_hfs -f /dev/disk2s1). For exFAT on macOS, usefsck_exfat /dev/disk2s1. - Follow the prompts. fsck will ask if you want to fix errors—type
y(yes) for each. If you want to auto-fix without asking, use the-yflag:sudo fsck -y /dev/sdb1. - Wait for the scan to complete. It may take several minutes depending on card size and damage. When done, fsck will report how many errors were fixed.
- Remount the card. On Linux:
sudo mount /dev/sdb1 /media/mountpoint(or just unplug and replug the card). On macOS:diskutil mount /dev/disk2s1. - Check the card's contents. Try accessing the files. If it mounts and reads normally, the repair worked. If not, see Troubleshooting below.
Common Mistakes
- Running fsck on a mounted card—this can cause further corruption. Always unmount first.
- Using the wrong device name—running fsck on your hard drive instead of the SD card can be disastrous. Double-check with
lsblkordiskutil listbefore proceeding. - Ignoring the file system type—fsck might misdetect the type, especially on exFAT cards. Use the
-tflag or the specific fsck variant (likefsck.exfat) to avoid errors. - Not backing up first—fsck can sometimes make files unrecoverable if the card is failing. Always copy what you can before running it.
- Using
-yblindly—while convenient, it can delete files that fsck considers unrecoverable. Use it only if you're okay with losing those files.
Tips
- If the card is used in a camera or phone, try formatting it in that device after a successful fsck—this often clears lingering issues.
- For cards that fail to mount, try a different card reader or USB port—sometimes the reader is the problem.
- Use
sudo fsck -f /dev/sdb1to force a check even if the card appears clean. - If the card is write-protected (has a physical lock switch), make sure it's unlocked before running fsck.
- On Linux, you can also use
fsck -nto do a dry run (no changes) to see what would be fixed.
Troubleshooting
fsck says “No such file or directory”—the device name is wrong or the card isn't recognized. Re-run lsblk and verify the name. If the card isn't showing at all, try a different reader or check if the card is physically damaged.
fsck reports “Superblock invalid” or “Can't read superblock”—this indicates serious corruption. Try using fsck -b 32768 (or other backup superblock locations) on Linux. For exFAT, use fsck.exfat -s to search for backup boot sectors.
The card still won't mount after fsck—the file system may be too damaged. Try formatting the card (this erases all data) using a tool like mkfs.vfat (Linux) or Disk Utility (macOS). If formatting fails, the card is likely dead—replace it.
fsck hangs or takes forever—this can happen with a failing card. Wait a bit longer, but if it's stuck for more than 30 minutes, cancel with Ctrl+C and try a different approach (like formatting).
macOS: fsck_hfs says “Invalid key” or “Volume is too large”—run it in single-user mode by restarting and holding Cmd+S, then typing fsck -fy at the prompt. This is the most thorough way on macOS.
Frequently Asked Questions
Will fsck delete my files?
fsck can delete files that it considers unrecoverable, but it usually preserves them in a lost+found directory. Always back up first.
Can I run fsck on a Windows-formatted SD card?
Yes, on Linux you can run fsck.vfat or fsck.exfat for FAT32/exFAT cards. On Windows, use chkdsk instead—fsck isn't native.
How long does fsck take?
It depends on card size and damage. A 32GB card with minor errors might take 5–10 minutes; a severely corrupted card can take much longer.
What does “clean” mean in fsck output?
It means the file system has no detected errors—no fixes were needed.
Can I use fsck on a card that's write-protected?
No, fsck needs write access to fix errors. Unlock the card's physical lock switch first.
Is fsck safe for SD cards?
Yes, when used correctly. It's a standard tool for file system repair. However, it's not a substitute for a hardware test—if the card keeps failing, it may be physically damaged.