corrupted usb disk? linux can fix

Recovering Data from a Corrupted Flash Disk on Linux

🔧 Step 1: Install the Recovery Tools

Install GNU ddrescue and testdisk (which includes photorec):

sudo apt-get install gddrescue testdisk

💽 Step 2: Make a Full Disk Image with ddrescue

Do NOT work on the damaged flash drive directly. Instead, make a safe copy:

sudo ddrescue -n /dev/sdX rescued.img rescued.log

Replace /dev/sdX with your actual USB device (e.g. /dev/sdb). Use lsblk to check.
This may take a while — especially if the disk has errors.

🧠 Step 3: Mount the Image (If Possible)

Try mounting the recovered image:

mkdir /mnt/recovered
sudo mount -o loop rescued.img /mnt/recovered

If that fails with a superblock error, try:

sudo mount -t vfat -o loop rescued.img /mnt/recovered

Still not working? The partition table might be corrupted.

🔍 Step 4: Inspect the Partition Table

Run:

fdisk -l rescued.img

If you see absurd sizes (e.g. hundreds of GB on an 8GB drive), your partition table is toast.

🧰 Step 5: Recover Files with photorec

Launch photorec:

sudo photorec rescued.img

Then:
1. Use the arrow keys to select the partition labelled FAT32.
2. Press Enter.
3. Choose [Other] (for non-ext filesystems).
4. Select Whole disk or the visible partition.
5. Choose a destination directory to save recovered files.

Let it run. It will copy recovered files into that folder.

🔁 Step 6: Format the Flash Disk (Optional)

Once recovered, you can safely erase the flash disk:

sudo wipefs -a /dev/sdX
sudo mkfs.vfat -F 32 /dev/sdX

Mount to copy files back:

sudo mount /dev/sdX /mnt
cp --sync /your/recovered/files/* /mnt/
sync

🖥 Step 7: Fixing USB Drives That Mount on Linux but Not macOS/Windows

If Linux mounts the disk fine, but Windows/macOS don’t, check the partition type:

sudo fdisk -l /dev/sdX

If it's listed as 83 Linux, retag it as FAT32:

sudo parted /dev/sdX set 1 lba on
sudo parted /dev/sdX set 1 boot on
sudo sfdisk --part-type /dev/sdX 1 b

Then reinsert the drive. It should now mount on Windows and macOS.

✅ Summary

- ddrescue protects your data by making a full image.
- photorec recovers files from broken partitions.
- Linux is tolerant of partition errors; macOS/Windows are picky about partition types.
- Use sync before ejecting USB drives!

Popular posts from this blog

Can send GSM/SMS but can't receive on MTN

Spotting a phishing (hacker) email

Adding your email service to Gmail under Google's professional suite (Workplace)