0
0
Iot-protocolsHow-ToBeginner · 3 min read

Raspberry Pi SD Card Corruption Fix: How to Repair and Prevent

To fix Raspberry Pi SD card corruption, first run fsck on the SD card from another computer to repair file system errors. Prevent corruption by always shutting down the Pi properly with sudo shutdown -h now and using a high-quality SD card.
📐

Syntax

Use the fsck command to check and repair the SD card file system. The basic syntax is:

  • sudo fsck /dev/sdX - Replace /dev/sdX with your SD card device identifier.
  • sudo shutdown -h now - Properly shuts down the Raspberry Pi to avoid corruption.
bash
sudo fsck /dev/sdX
sudo shutdown -h now
💻

Example

This example shows how to safely repair an SD card on a Linux computer after corruption and how to properly shut down the Raspberry Pi to prevent future issues.

bash
sudo umount /dev/sdb1
sudo fsck -y /dev/sdb1
sudo shutdown -h now
Output
fsck from util-linux 2.36.1 /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb1: 1234/65536 files (0.5% non-contiguous), 56789/262144 blocks
⚠️

Common Pitfalls

Common mistakes include:

  • Removing the SD card without shutting down the Pi properly, causing corruption.
  • Using low-quality or counterfeit SD cards that fail easily.
  • Not unmounting the SD card before running fsck, which can cause damage.

Always unmount the SD card before repair and use sudo shutdown -h now to power off safely.

bash
Wrong way:
sudo fsck /dev/sdb1  # without unmounting

Right way:
sudo umount /dev/sdb1
sudo fsck /dev/sdb1
📊

Quick Reference

Summary tips to fix and prevent SD card corruption on Raspberry Pi:

TipDescription
Use sudo shutdown -h nowAlways shut down the Pi properly before removing power.
Run fsck to repairCheck and fix file system errors on the SD card from another computer.
Use high-quality SD cardsChoose reliable brands to reduce failure risk.
Avoid sudden power lossUse a UPS or power supply with stable output.
Backup regularlyKeep copies of important data to recover quickly.

Key Takeaways

Always shut down your Raspberry Pi properly using sudo shutdown -h now to prevent SD card corruption.
Use fsck on another computer to repair corrupted SD cards safely after unmounting them.
Choose high-quality SD cards to reduce the chance of corruption and failure.
Avoid sudden power loss by using stable power sources or UPS devices.
Regularly back up your Raspberry Pi data to recover quickly from corruption.