How to fix "sudo: unable to open ... Read-only file system"?
Solution 1
The filesystem will usually go into read-only while the system is running if there is a filesystem consistency issue. This is specified in fstab
as errors=remount-ro
and will occur when a FS access fails or an emergency read-only remount is requested via Alt+SysRq+U. You can run:
sudo fsck -Af -M
to force a check of all filesystems. As one of the other answers states, looking at dmesg
is also very helpful.
Edit: Don't forget the -M
on the command-line.
NOTE: As mentioned by Bibhas in his answer: If fsck
gets stuck after its version banner:
$ sudo fsck -Af -M
fsck from util-linux 2.20.1
you may want to try using the EXT4-specific fsck
$ sudo fsck.ext4 -f /dev/sda1
Provided the partition in question /dev/sda1
was an ext4 filesystem.
Solution 2
The answer by hexafraction didn't work for me. Every time I tried executing sudo fsck -Af -M
it just showed
$ sudo fsck -Af -M
fsck from util-linux 2.20.1
and nothing else. No error or anything. For me, booting into a live disc and executing this worked -
sudo fsck.ext4 -f /dev/sda1
Provided the partition in question /dev/sda1
was an ext4 filesystem.
Solution 3
Here is the command that solved my problem :
mount -o remount /
better than a reboot or sudo fsck -Af
Solution 4
If you want to force your root filesystem to remount as rw, you can do the following.
mount -o remount,rw /
Solution 5
Try running dmesg | grep "EXT4-fs error"
to see if you have any issues related to the filesystem / journaling system itself. I would recommend you to restart your system, then. Also, sudo fsck -Af
answer by ObsessiveSSOℲ won't hurt.
Related videos on Youtube
John
Updated on September 18, 2022Comments
-
John over 1 year
The title might not be as descriptive as I would like it to be but couldn't come up with a better one.
My server's file system went into Read-only. And I don't understand why it does so and how to solve it.
I can SSH into the server and when trying to start apache2 for example I get the following :
username@srv1:~$ sudo service apache2 start [sudo] password for username: sudo: unable to open /var/lib/sudo/username/1: Read-only file system * Starting web server apache2 (30)Read-only file system: apache2: could not open error log file /var/log/apache2/error.log. Unable to open logs Action 'start' failed. The Apache error log may have more information.
When I try restarting the server I get :
username@srv1:~$ sudo shutdown -r now [sudo] password for username: sudo: unable to open /var/lib/sudo/username/1: Read-only file system
Once I restart it manually it just start up without any warning or message saying something is wrong.
I hope somebody could point me into the right direction to resolve this issue.
-
Forty-Two over 9 yearsI recommend to @John to change the answer to the last posted answer by Bibhas as it actually works where the other answers are not helpful at all actually.
-
Ciro Santilli OurBigBook.com over 7 yearsFor MicroSD: askubuntu.com/questions/213889/…
-
vanduc1102 almost 6 yearsEveryone, this question is for a server, not a PC. If you have this issue on your dual boot PC, Please check
The **quick start** option can be found in **power options** in the control panel of Windows
. I'm having the same issue with an Ubuntu on AWS -
Parisa.H.R over 2 yearsI have this problem too, and non of solutions work fo me i use ubuntu 18.04 , and i don't know what makes this happened , I should restart my system and then it show me page that contain (initramfs) there when I run
fsck /dev/sda1 -y
and reboot os work and again after 30 minutes to 1 hour problem happens. -
Admin almost 2 yearsif disk is NTFS and used by Windows - run from it
shutdown /f /r /t 0
, it helped for me
-
-
Drew Noakes about 11 yearsNot better if the OS made your disk read-only to prevent possible corruption.
-
isomorphismes about 11 yearsWhat should one look at /
grep
for indmesg
output? -
gertvdijk almost 11 yearsI think you should not force a filesystem check on other r/w mounted filesystems. That will potentially corrupt your data. Add the
-M
option to skip mounted filesystems. (-M Do not check mounted filesystems and return an exit code of 0 for mounted filesystems.
from FSCK(8)) -
Nathan Osman over 10 yearsNot only that - only root will be able to remount the filesystem and
sudo
isn't going to work if the filesystem is read-only. -
Nathan Osman over 10 yearsUnfortunately if you opted to encrypt your home folder,
dmesg
is bound to be full of useless errors fromecryptfs
. -
Mark Kramer over 10 yearsThis doesn't help, I just get the same error when trying to run that command.
sudo: unable to open /var/lib/sudo/kuplack/1: Read-only file system
fsck from util-linux 2.20.1
-
Mark Kramer over 10 yearsDoesn't help, I just get the same message:
sudo: unable to open /var/lib/sudo/kuplack/1: Read-only file system
mount: cannot remount block device /dev/sda2 read-write, is write-protected
-
Forty-Two over 9 yearsThank you for this answer. This is the only thing that had actually worked
-
naught101 about 9 yearsBut... -M will skip mounted file systems, including /dev/sda1 (or what ever mounted drive includes /var/lib/sudo/... ). @MarkKramer: I highly recommend always setting the root password when installing linux, with
sudo su; passwd
. Then you can usesu -c fsck -Af -M
. -
dalore about 9 years-M means not to do mounted filesystems. Your filesystem /dev/sda1 was mounted (I'm guessing at /). So it was skipped.
-
R T over 8 yearso yes this one worked.
-
David Foerster about 8 yearsWelcome to Ask Ubuntu! I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)
-
FreeSoftwareServers almost 8 yearsYea for me I needed to remove -M since /dev/sda1 was mounted, and to make your life easier, add -Afy (The y means answer yes to all prompts)... I play fast and loose with VM's so I'm usually ok with this type of solution, but if this is unbacked up hardware, might take a different approach and read dmesg.
-
efkan about 7 years
sudo fsck.ext4 -f /dev/sda1
works. Still a restart needs. -
Darshan Chaudhary about 7 yearsrunning fsck on a mounted filesystem is not a good idea
-
nanofarad about 7 years@DarshanChaudhary The
-M
flag causes fsck to skip mounted filesystems. See thefsck (8)
manpage. -
Sinan Gül about 7 yearscommand succeed after reboot the system.
-
Eduardo Lucio over 6 yearsUP! For -> "The filesystem will usually go into read-only while the system is running if there is a filesystem consistency issue."
-
Rosário Pereira Fernandes over 6 yearsIt worked for me on ubuntu 16.04.3 Thank you
-
nomen over 6 yearsI am fairly certain this is happening to me right now, given that my computer told me it forgot its time this morning.
-
Rishabh Agrahari almost 6 years
mount: cannot remount /dev/sda8 read-write, is write-protected
-
Fathur Rohim about 5 yearsthis was solved my problem, I use hetzner cloud with 160gb ssd, never had such error before
-
birdman almost 5 yearsThis answer does not work for me. After executing the suggested command I receive
fsck from util-linux 2.29.2
-
Blairg23 almost 5 yearsThis actually did end up corrupting my filesystem :(
-
NelsonGon almost 5 yearsOnly one that worked. At the cost of startup speed.
-
Pranav almost 5 years@hexafraction many humans don't have "SysRq" keyboard buttom in their laptop keyboard, I am one of them. How do I pull this off?
-
nanofarad almost 5 years@PrabeshBhattarai SysRq is the same (physical) key as PrintScreen, even if your laptop manufacturer didn't physically print "SysRq" on it; alternatively you may need Fn+[something]. That said, you don't need to press that key combination; I mention that keyboard shortcut as an example of something that can cause a filesystem to fail read-only, not as a step that you need to take.
-
ScottyBlades over 4 years
sudo fsck -Af -M
gives me:fsck: illegal option -- A fsck: ? option?
-
ScottyBlades over 4 years
fsck from util-linux 2.20.1
gives me:fsck usage: fsck [-fdnypqL] [-l number]
-
ScottyBlades over 4 years
sudo fsck.ext4 -f /dev/sda1
gives me:sudo: fsck.ext4: command not found
-
ScottyBlades over 4 years
mount_apfs: unrecognized option 'remount'
-
nanofarad over 4 years@ScottyBlades This answer is seven years old, and the flags have likely changed--I don;t have a copy of fsck from util-linux 2.20.1, and my copy handles -A just fine, so I don't have any great advice, aside from manually invoking on each volume that needs to be checked.
-
ScottyBlades over 4 years@hexafraction, it's cool. I'm new to web dev. So I think I'm making more obvious/basic mistakes that would go under most seasoned developer's radars. MY SOLUTION: When I clicked "save as" I was saving to the root directory, not the directory I actually wanted to save in. Making sure I saved to the correct location solved the problem.
-
nanofarad over 4 years@ScottyBlades Understood. Looks like your situation was mostly unrelated to actual file system corruption then, meaning that there was no need to get fsck involved.
-
ScottyBlades over 4 years@hexafraction, good to know
-
Farid Chowdhury almost 4 yearsAwesome brother 💪
-
Forty3 almost 4 yearsHere we are, 2020, and this saved my Ubuntu laptop. Thanks @Bibhas!
-
Salem F over 3 yearsIm on virtual machine (KVM VPS) and I got this error
mount: /: cannot remount /dev/mapper/vg_jh-root read-write, is write-protected.
-
Coconut over 3 yearsIf someone needs to remount the disk in read/write mode, try this:
$ sudo mount -vo remount,rw /
-
Òscar Raya over 3 yearsTY, I had a problem with snappy daemon and tryied a lots of things. Your sudo fsck.ext4 -f /dev/sda1 saved me (in my case on sda2).
-
Muhammad bin Yusrat over 3 yearsThanks! This worked! :)
-
Heisenberg over 3 yearsDidn't worked but I think windows is causing this issue
-
Sarato about 3 yearsThis worked for me, when my off-brand mp3 player switched to "read-only" all of a sudden
-
Bhuwan Adhikari almost 3 yearsthis was kind of similar for me too.
-
Yinon_90 almost 3 yearsI solve my issue in a similar way, I posted here: askubuntu.com/a/1346172/1330220
-
Mark E almost 3 years¡CAUTION! I was fixing a remote server and it didn't turn on after reboot which made things way harder, I recommend testing other solutions before trying to rebbot specially if you're not physically with the computer. For the first time in the engineering world, turning it off and on again was a big problem instead of a solution :(
-
flm over 2 yearsI get mount: /: cannot remount /dev/sda2 read-write, is write-protected.
-
Aleks over 2 yearsOh, this is perfect.
-
Zaman Oof over 2 years@MarkE Rebooting Against Availability so should be the latest solution
-
lightonphiri over 2 yearsThank you for this: I urgently need to pull files from my problematic installation and this helped tremendously! Incidentally, I ran fsck.ext4 via my "(Initramfs)" shell and it worked perfectly!
-
kyriakosSt about 2 yearsThis answer should have more upvotes. It is the most failsafe option, that requires far less understanding from the user. Thank you.
-
Fathy about 2 yearsthis solved my problem i remount the partition only aka
sudo mount -o remount, rw 0A4819AC48393