5

I'm using Ubuntu 14.04.

I have an SD card that I use with my camera, and I'm trying to delete photos from it. I was able to move them to the Trash, but when I try to delete any of the files out of the Trash I get Failed to delete the item from the trash.

I can navigate to the .Trash-1000/files directory on the device, but when I try to sudo rm the files, I get rm: cannot remove ‘IMG_1483.JPG’: Read-only file system.

mount gives me this:

/dev/sdb1 on /media/zack/6562-61611 type vfat (ro,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)

I tried re-mounting the device using sudo mount /dev/sdb1 /media/zack/SD -o rw,dmask=0000 and got the same error when I tried to delete the files.

Finally, I have checked the switch on the card itself and confirmed it's in the unlocked position. I tried switching it to locked just in case it was a goofy card and I couldn't delete off of it then either.

What's going on here? How can I get rid of these files?

Update 1: I tried a couple other things in response to aventurin's comment. I took a new picture, then tried to sudo rm it and that worked. When I went back to .Trash-1000/files and tried it again, I was able to delete some files but not others:

$ ls
100___12
101___01
102___02    # directories
103___03
...
IMG_1365.JPG
IMG_1374.JPG
IMG_1375.JPG
IMG_1380.JPG
...

$ sudo rm -rvf *.JPG
removed ‘IMG_1365.JPG’
removed ‘IMG_1374.JPG’
removed ‘IMG_1375.JPG’
rm: cannot remove ‘IMG_1380.JPG’: Read-only file system
rm: cannot remove ‘IMG_1381.JPG’: Read-only file system
rm: cannot remove ‘IMG_1383.JPG’: Read-only file system
...

...and so on. I did an ll right before I deleted those files, and the permissions for all of the .JPG files look exactly the same.

Update 2:

$ dmesg | grep sdb1
[  714.950034] FAT-fs (sdb1): error, invalid access to FAT (entry 0x6ce0c8c0)
... # a bunch more of those
[ 2192.017345] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[ 2192.663466] sdb1: rw=0, want=105540772768, limit=62325760
[ 2192.663470] sdb1: rw=0, want=105540772744, limit=62325760
[ 2192.663499] FAT-fs (sdb1): error, invalid access to FAT (entry 0xad23600b)
[ 2192.663501] FAT-fs (sdb1): Filesystem has been set read-only
[ 2192.663601] FAT-fs (sdb1): error, invalid access to FAT (entry 0x58f3a807)
[ 2271.537913]  sdb: sdb1
[ 2273.782060] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[ 2407.374492] FAT-fs (sdb1): error, fat_free_clusters: deleting FAT entry beyond EOF
[ 2407.374496] FAT-fs (sdb1): Filesystem has been set read-only

I tried sudo fsck /dev/sdb1 and got a lot of errors:

0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
? 1
...
/.Trash-1000/files/IMG_1483.JPG  and
/.Trash-1000/files/117___09/IMG_1737.JPG
  share clusters.
1) Truncate first to 5439488 bytes
2) Truncate second to 0 bytes
? 1

I told it to fix them all, but when I run it again they all show up again.

Update 3:

I unmounted the card, and ran sudo fsck /dev/sdb1 -a. It ran for about 6 hours and still wasn't finished so I eventually Ctrl-C'd it. It mostly seemed to be renaming files with corruped usernames, and was up to almost 18000 files renamed before I killed it (I've certainly never taken that many photos before...).

I then tried sudo mount /dev/sdb1 /media/zack/SD -v -o rw and got this output:

$ sudo mount /dev/sdb1 /media/zack/SD -v -o rw
mount: you didn't specify a filesystem type for /dev/sdb1
       I will try type vfat
/dev/sdb1 on /media/zack/SD type vfat (rw)

Despite not having an error, I still cannot delete the files and get the same old "read-only file system" error.

11
  • Does rm as root work? Does rm work for files not in trash?
    – aventurin
    Commented Sep 5, 2016 at 16:57
  • @aventurin, sorry, I should have specified that I was using sudo for just about everything. I've updated the question with that change, as well as the results of your second suggestion.
    – Zack
    Commented Sep 5, 2016 at 17:13
  • Does dmesg show any errors related to the SD card?
    – aventurin
    Commented Sep 5, 2016 at 17:19
  • @aventurin, updated the question again.
    – Zack
    Commented Sep 5, 2016 at 17:28
  • 1
    Some SD cards have an mechanical RW lock. Does yours?
    – Serge
    Commented Sep 5, 2016 at 19:05

5 Answers 5

0

Your filesystem seems to be corrupted. If you can't let fsck run until the end, I suggest reformating the card with mkfs.vfat. But to avoid later corruption, I advise you to check your SD card with badblocks first (you can use the destructive -w option, but you will need to recreate the partition table afterwards - with cfdisk, for instance). Then, if you have any bad blocks, you can pass them to the mkfs command like so:

badblocks -w -o ~/badblocksList /dev/sda
mkfs.vfat -l ~/badblocksList /dev/sda

Note: alternatively, you can use mkfs.vfat -c to perform a simple bad blocks check when formatting. Please also note that FAT is not a journaling filesystem, and, as such, is quite sensitive to corruption if not properly unmounted. If possible, try to avoid its use on devices you carry around.

2
  • I tried this, and it didn't find any bad blocks. mkfs.vfat also returned an error, though I don't remember now what it was. I decided to just use gparted to reformat the card to FAT32, and it seems like everything's working now. Thanks for your help, everyone!
    – Zack
    Commented Sep 8, 2016 at 23:48
  • Your partition table might have been corrupted, then. It might have been possible to generate a new one that matched the existing filesystem, but it is likely that both were corrupt. gparted was a good call. fdisk or cfdisk can do that too, but gparted (or parted) handles everything from the partition table to formatting partitions.
    – MayeulC
    Commented May 4, 2021 at 11:33
0
rm: cannot remove '/XXX/.Trash-1000/files/XXX.rtf': Read-only file system

Hours ago, on a USB stick, I got the same error as shown above. By googling, I found this webpage. I tried the suggested methods but to no avail. Then I started Windows in VirtualBox. Windows successfully deleted the ".Trash-1000" folder and everything inside it.

0

Actually hdparm -r0 /dev/sda1 (modify to your device path as appropriate), then ejecting and re-inserting the card worked for me. Simply remounting with the mount command didn't.

Got the answer from https://askubuntu.com/a/342448/638715

0

Similar issue on xfce-debian happened.

I remove some files with long name and Persian name from A fat32 flash memory. When mount it thunar shows them in Trash and ready to restore them, but if I try to restore or just remove them permanently it cant do any things and show ReadOnly file system then abort operation.

This steps fix it

  • Unmount flash drive

umount /dev/sdx

  • Use fsck on partiotion

fsck.vfat /dev/sdx1

Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.

Choose Remove dirty bit

And

Bad short file name ( ).

Choose Auto-rename

After that accept them with y

-1

I had the exact same problem. This worked for me:

  • Put the SD card in a USB reader

  • mount it

  • go to its folder in terminal

sudo rm -Rf .Trash-1000/

1
  • This removes your trash. Why on earth would this work?
    – knezi
    Commented Jan 21, 2019 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .