I have an application which will search for a corrupted FAT file system and repair it.

For testing the application I will need a corrupted file system.

What is a good and reproducible way for corrupting a FAT file system? Creating bad sectors for example.


a partial solution

 dd if=/dev/zero count=100 bs=1k of=fs.fat
 mkfs -t vfat fs.fat
 mount fs.fat /mnt ## as root
 # cp some file
 umount /mnt ## as root

 cp fs.fat fs.ref
 vi fs.ref ## change some bytes
 cp fs.ref fs.sampleX

now you have a good fs (fs.fat) and a corrupted one (fs.ref)

sudo mount -t vfat fs.ref /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
  • you can try to fix fs.sampleX
  • knowing a bit about fat (or filesystem layout) might help to "cleverly corrupt" fs.ref
  • this can be applied to any fs type (extX, xfs, ... )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.