Mount FAT32 loopback as writeable

1

I'm trying to fix a corrupted FAT32 partition. The partition is working again, but I want to delete the remaining files containing wrong names and similar.

I have a full dump of the SD-card in question, but even if I try to mount it as writable, it's still read-only:

# losetup -o 4194304 /dev/loop0 sdcard.img
# mount -o rw,loop /dev/loop0 /mnt/sdcard
# cd /mnt/sdcard/Android/data
# rm $'\265'LI@BO\~1.APP
rm: cannot remove '\265LI@BO~1.APP': Read-only file system

Any idea how I can mount it as writable?

EDIT:

The following doesn't work either

mount -t vfat -o rw,offset=4194304,utf8,umask=0000,uid=1000,gid=1000 sdcard.img /mnt/tmp

simendsjo

Posted 2015-06-18T13:00:26.417

Reputation: 411

Answers

0

I think you need to mount it as a fat32 filesystem (-t vfat option to mount) to access the files in it (otherwise how do you know what the data in it represents?)

The filesystem also has to be fixed otherwise it will be automatically switched to read-only mode whenever a corruption is detected during accesses - to prevent further corruption (happens for any filesystem, not only for fat32).

If that's the case you need to unmount it and fix it (using fsck.vfat in linux or scandisk in windows). Make a copy beforehand.

Dan Cornilescu

Posted 2015-06-18T13:00:26.417

Reputation: 802

That doesn't work either - see my update to my question. The partition is mounted correctly, and I can browse files as normal. The thing is that it's read-only although all files looks writable. – simendsjo – 2015-06-18T14:03:18.200

googling shows lots of such cases caused by corrupted filesystems. Here's an example: http://www.linuxquestions.org/questions/linux-general-1/mounted-read-write-fat32-partition-suddenly-becomes-read-only-166190/. Unmounting it then fixing it (using fsck.vfat in linux or scandisk in windows worked for many). Make a copy beforehand.

– Dan Cornilescu – 2015-06-18T14:20:00.477

Cornielscu: Yes, I found out fsck.vfat had to be run many times until all errors were fixed, but forgot to update my question. Only when I looked at certain filenames would the filesystem become read-only, so I guess the driver noticed the corruption and put it in read-only to avoid further dataloss. Add an answer, and I'll accept it. – simendsjo – 2015-06-19T05:41:22.717