Hello everyone,
RPi4 user here. I keep some of my userdata on a USB thumb drive, partly to minimize the writes/ rw on the SD card containing the root FS (though I think I have an SD card designed for dashcams and hence have higher r/rw scores), and partly to avoid running into lack of space which can happen if you are using Sonar, Radar, etc.).
Now a couple of weeks ago, I noticed that my USB drive was not getting mounted and was flagged as read-only. It has happened to me once before and I replaced the USB thinking that the previous one had gone bad. However now on this second one, I have the same problem, and as a result of which certain apps cannot run since their userdata is on the USB drive. The system itself is running fine. The USB is ext4 and the check shows issues. Any idea how to fix these? I have access to an Ubuntu machine if need be. Many thanks in advance.
Faisal
│ e2fsck 1.44.5 (15-Dec-2018)
│ Warning: skipping journal recovery because doing a read-only filesystem check.
│ Pass 1: Checking inodes, blocks, and sizes
│ Inode 2360134, end of extent exceeds allowed value
│ (logical block 256, physical block 3354368, len 26)
│ Clear? no
│
│ Inode 2360134, i_blocks is 2096, should be 2056. Fix? no
│
│ Inode 2757330, end of extent exceeds allowed value
│ (logical block 512, physical block 3370496, len 532)
│ Clear? no
│
│ Inode 2757330, i_blocks is 5928, should be 4104. Fix? no
│
│ Pass 2: Checking directory structure
│ Pass 3: Checking directory connectivity
│ Pass 4: Checking reference counts
│ Pass 5: Checking group summary information
│ Block bitmap differences: -(3157704--3158378) +(3342448--3342463)
│ +(3351744--3351807) +(3354405--3354623) +(3355136--3355647) +(3356672--3362540)
│ +(3362816--3363839) +(3369184--3369215) +(3370112--3370239) -(3370496--3371027)
│ +11047293 +(11296068--11296070) +(11296422--11296437) -(11296438--11296445)
│ +(11303860--11303865) -11303868 +(12719986--12719992) -(12719993--12720006)
│ Fix? no
│
│ Free blocks count wrong for group #96 (19013, counted=19010).
│ Fix? no
│
│ Free blocks count wrong for group #102 (16040, counted=16034).
│ Fix? no
│
│ Free blocks count wrong (12952171, counted=12976295).
│ Fix? no
│
│ Free inodes count wrong (3701304, counted=3701878).
│ Fix? no
Yes, fix those better earlier than later. But good to try a backup of the content first. Run fsck interactively or with -p flag first to have errors resolved automatically which can be resolved safely, then again without the flag to check whether there are still some left. Afterwards check the lost+found directory for files/inodes which lost their links to the filesystem.
Thanks but that is the problem. The system has marked it as read only so whenever I run fsck, I get:
root@DietPi:~# fsck /dev/sda
fsck from util-linux 2.33.1
e2fsck 1.44.5 (15-Dec-2018)
fsck.ext2: Read-only file system while trying to open /dev/sda
Disk write-protected; use the -n option to do a read-only
check of the device.
Any idea how to remove the read-0nly flag? Thanks.
Firstly, it is better to specify the partition (/dev/sda1) you want to check and fix the file system, not on the whole drive (/dev/sda), as there might be other file systems there.
Second, make sure it is not mounted.
Third, if everything else fails, you can always run the fsck on the Ubuntu.
root@DietPi:~# fsck /dev/sda1
fsck from util-linux 2.33.1
e2fsck 1.44.5 (15-Dec-2018)
fsck.ext4: Read-only file system while trying to open /dev/sda1
Disk write-protected; use the -n option to do a read-only
check of the device.
Also, when I did cat /var/log/messages, it showed, among other things:
Oct 12 21:46:16 DietPi kernel: [ 2.729210] scsi 0:0:0:0: Direct-Access PNY USB 3.0 FD PMAP PQ: 0 ANSI: 6
Oct 12 21:46:16 DietPi kernel: [ 2.730039] sd 0:0:0:0: [sda] 121061376 512-byte logical blocks: (62.0 GB/57.7 GiB)
Oct 12 21:46:16 DietPi kernel: [ 2.730514] sd 0:0:0:0: [sda] Write Protect is on
Oct 12 21:46:16 DietPi kernel: [ 2.730918] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn’t support DPO or FUA
Okay, at least now fsck.ext4 is correctly invoked, previously it showed fsck.ext2. The read-only is on a different level, because fsck doesn’t require a filesystem to be mounted at all. [sda] Write Protect is on sounds like the drive itself is somehow write protected, but not sure if this is still due to filesystem or partition table corruption .
Thanks, I read somewhere that if the drive is failing or encounters errors, the system marks it as read-only. Anyway, here is the rather strange result of your suggestion
root@DietPi:~# root@DietPi:~# hdparm -r0 /dev/sda
/dev/sda:
setting readonly to 0 (off)
readonly = 0 (off)
root@DietPi:~# fsck /dev/sda1
fsck from util-linux 2.33.1
e2fsck 1.44.5 (15-Dec-2018)
fsck.ext4: Read-only file system while trying to open /dev/sda1
Disk write-protected; use the -n option to do a read-only
check of the device.
root@DietPi:~#
What I know is that a mounted filesystem is re-mounted as read-only, when critical filesystem errors are found, but I didn’t see this kind of write-protection yet that blocks all kind of writes outside of the mount. hdparm -r allows to set/unset a device-level read-only flag, but obviously that either was not the case of reverted directly.
Yes makes sense to try it on a different system. Next would be to try rewriting the partition table, if not prevented for the same reason.
Thanks everyone. Well the result is the same. Ubuntu also recognizes the USB as in need of repair but it can neither mount it nor can it remove the read-only flag Seems like quite a few people had this issue but with little success. Most cases just ended up formatting the USB.
Is there any way I can salvage the data from it? Or is there a possibility of a backup of userdata might be in Dietpi?
Thank you and looking for suggestions.
Good idea, probably a loop device does not suffer from such read-only flag. Whether it can then be mounted is another question, but probably it can be repaired (fsck) then.
Thanks everyone, so I have managed to make a couple of images of the said USB. The USB itself is a write off I guess. I mounted the image in Ubuntu but it wont let me do anything probably due to ownership. I then mounted the same image to dietpi and copied the files from dietpi-userdata folder to another USB device, albeit with some copying errors. In the end however, the apps with their user data on the USB (Sonarr, Radarr, NzbGet, Jellyfin, etc) still cannot be accessed, though unlike before, they are running and not inactive.
Is there a way to fix those? Or the files within the image? The image still mounts as a read-only device (just like the USB it came from) if I remember correctly.
Many thanks for your help and time.