How to recover a broken FAT filesystem using FatCat
FatCat is a tool designed to manipulate FAT filesystems, in order to explore, extract, repair, recover and forensic them.
FatCat is developed and mantained by Grégoire Passault, and currently supports FAT12, FAT16 and FAT32.
(more information about FAT filesystem here)
# git clone https://github.com/Gregwar/fatcat && cd fatcat # mkdir build && cd build # cmake .. # make # make install
or, on Debian/Ubuntu:
# sudo apt install fatcat
Now, using fatcat, let’s try to repair a broken FAT filesystem and recover orphaned files.
Repair a FAT filesystem
If you do have a broken hard drive, you will have to save everything before start a FAT repair.
You can either copy your data to another drive or to a file.
Assuming your damaged hard drive is
/dev/sdb, you can do this using
$ ddrescue /dev/sdb disk.img rescued.log
Then you should backup your FAT tables to another file before trying to fix it using fatcat, this can be done with
fatcat disk.img -b backup.fat
This will backup your FAT tables in
backup.fat. You can at any moment restore it with
fatcat disk.img -p backup.fat
Note that all operations below will only change your FAT, not your data.
2: Merge FAT tables
FAT tables in a broken disk could differ. You can compare them using
fatcat disk.img -2
This will outputs the differences. You can then try to merge the tables using
fatcat disk.img -m
This is not supposed to be very risked, and you could repair files using this.
3: Fix the FAT
Fatcat can autofix some parts of your FAT tables, to this, you can try
fatcat disk.img -f
This will walk your directories and search for entries (directories or files) which are unallocated in the FAT. Then, it will try to fix the FAT to re-allocate these entries, assuming its contiguous in the disk.
4: Find orphan files/directories
This last step will explore allocated files that are not reachable from your directories.
You can use
-o for this:
fatcat disk.img -o
5. Recover orphaned files
Now we’ve fixed the FAT, there may still have data on the disk that are still here but unreachable: there are still allocated, somewhere on the disk, but is no longer reachable, and its name does not exist anymore.
This kind of files and directory are called “orphaned data”
To find this data, fatcat will compare what’s reachable from the root directory (/) and what’s allocated on the disk, and will try to find directories that are allocated but not reachable.
This is done using
$ fatcat disk.img -o There is 1 orphaned elements: * Directory clusters 33 to 33: 2 elements, 30B Estimation of orphan files total sizes: 30 (30B) Listing of found elements with known entry: In directory with cluster 33: f 27/10/2013 16:32:54 orphan_file.txt c=51 s=30 (30B)
This means that there is one directory found that is orphaned.
Now you can list its entry by using
-L, which lists a directory using its cluster number:
$ fatcat disk.img -L 33 Listing cluster 33 Directory cluster: 33 d 27/10/2013 16:32:26 ./ c=33 d 27/10/2013 16:32:26 ../ c=0 f 27/10/2013 16:32:54 orphan_file.txt c=51 s=30 (30B)
Inside the orphaned directory there is also an orphan file in it, named
You can use
-s, in order to read a file using its cluster number and its size (in this case we read 30 bytes of the file in cluster 51):
$ fatcat disk.img -R 51 -s 30
You can also extract the whole directory using
$ mkdir output/ $ fatcat disk.img -x output/ -c 33