Debian Server Showing Read-Only File System Repeatedly – Fix Guide

debianmemoryread-only

I am having issues with being unable to SSH into my server, running Debian 11. If I try to make a folder or file, I get an error that says mkdir: cannot create directory ‘/tmp/test’: Read-only file system.

As suggested by this link, and a large swath of others, I can fix this by entering safe mode and running fsck.ext4 /dev/sda, but it only helps for 24-48 hours.

I got a new SSD about two weeks ago (smartctl is showing power-on hours of 442), because I was having similar errors and I thought I could be having a bad hard drive, but the same problems are happening with the new one.

Here is the results from sudo smartctl -t long -C /dev/sda: https://pastebin.com/LpHGJTx8

Does anyone happen to know why this may be happening? I can provide any other logs as well, I'm not sure what may be needed

I appreciate any help!

EDIT: I ran a badblocks -sv /dev/sda test and got the following result: Pass completed, 0 bad blocks found. (0/0/0 errors)

EDIT 2: I ran sudo memtest 2048 2 (from this link). These were the results: https://pastebin.com/auUJzvWy

Best Answer

Bad RAM is the usual cause of the unexpected file system corruption. This seems to be your case too, according to the memtester run.

It is so common so it is recommended to automatically check the file system at regular intervals even if it is marked as clean. For example, please read tune2fs manual. It is mentioned right in the beginning of the page, in the -c option description, and also later, in the -i option.

If you are brave, you may use Linux BadRAM or memory map feature, to tell it to not to use certain memory addresses at all. It'll use only the parts of memory that are healthy. But I wouldn't do that on the computer of non-negligible importance.