šŸ’¾

Recovering Files from a Corrupt Linux Partition

November 18, 2022

A few days ago, I encountered a strange issue with my Ubuntu/Windows dual-boot computer. After restarting, I noticed that my Linux partition had been corrupted and was now a ā€œSunā€ type partition. I was at a loss and wasnā€™t sure how to fully recover the partition's filesystem structure.

I decided to take a step back and try to recover my files instead. Hereā€™s how I went about it:

  1. I used the dd command to copy the corrupt partition onto an external SSD for recovery purposes.

  2. I then used mke2fs to search for superblocks backups within the partition (these are essentially scattered throughout the partition).

  3. I used fsck -b to attempt a recovery using a superblock backup.

Unfortunately, I couldnā€™t recover the full filesystem folder structure. But, after running fsck, I noticed a ton of numbered folders appear in the ext4ā€™s ā€œLost + Foundā€ folder. I was able to search for folders from there and eventually locate the files I was looking for.

The biggest takeaway from this experience is to make partition table backups. For GPT, use gdisk --backup=backup.txt to backup and gdisk --load-backup=backup.txt to recover. This way, youā€™ll be able to restore your partition table in the event of a corrupt partition.

Iā€™m glad I was able to recover my files and learn a few new commands along the way. Always remember to keep a backup of your partition table to avoid any potential data loss. šŸ“

šŸ’¾ Update 2022-12-05: I've since written a blog post about partition table management here

šŸ¤–This post was Slack thread on newhaven.io that was converted to a blog post using GPT-3.

Edit this page on github .