64

When I try to save something or rename a file/folder it say this error " Read-only file system" or run something as root in the terminal it say this error

sudo: unable to open /var/lib/sudo/"My User Name"/0: Read-only file system 
W: Not using locking for read only lock file /var/lib/dpkg/lock
E: Unable to write to /var/cache/apt/  
E: The package lists or status file could not be parsed or opened.

When I make a Folder the error dialog in the details with Nautilus is this:

Error creating directory: Read-only file system

I would show you I picture of it but it isn't even letting my save onto my flash drive. Please help me.

Seth
  • 58,122
MathCubes
  • 5,666

7 Answers7

42

This worked for me:

First, run this command with sudo permission:

sudo fsck -n -f

Then reboot the machine.


The options -f and -n are documented directly under man fsck, but under the filesystem-specific fsck subcommand. The fs-specific-options part alludes to this:

SYNOPSIS

fsck [-lsAVRTMNP]
     [-r [fd]]
     [-C [fd]]
     [-t fstype]
     [filesystem...]
     [--]
     [fs-specific-options]

From man fsck.ext4 (a.k.a. e2fsck):

-f — Force checking even if the file system seems clean.

-n — Open the file system read-only, and assume an answer of no to all questions. Allows e2fsck to be used non-interactively. This option may not be specified at the same time as the -p or -y options.

Further comments to option -n from this Unix & Linux stackexchange answer:

If you meant fsck -n, then the filesystem-specific programs are called and passed the -n option, which for most of them means “look but don't touch”. If the filesystem is mounted, fsck will usually find spurious errors, because a mounted filesystem tends to be in an inconsistent state as write operations are happening. It won't lock up your system, but it won't report anything useful either.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • 54
    @sudodus You are way out of line to criticize someone for answering an old question on a stackexchange site. The whole point is for these questions and answers to to remain indefinitely as a resource. This isn't some forum site with their typical bias against resurrecting old threads. If you have a reason why a filesystem check would not help the user's situation, explain it. You should not discourage a new user from trying to help. And whoever else downvoted this, explain to us what you downvoted for, don't just mindlessly follow the herd. – msouth Jan 28 '17 at 23:52
  • 22
    @msouth, I accept your critical comment. My comment was mainly trying to make the author of the answer improve it - add more details, because I think it is not complete enough to be useful for a beginner. (And I did not downvote it, someone else did). I am sorry that my intention was not clear - the intention was definitely not to discourage anybody, not the author of the answer, and not you. I will try to change my commenting style to make it more positive. – sudodus Jan 29 '17 at 07:48
  • 18
    @sudodus my phrasing was too harsh, I'm sorry for that (the site doesn't let you edit comments, but when I realized that, I should have just deleted it and made another comment). My respect to you for taking it so well. – msouth Jan 30 '17 at 00:26
  • I'm getting: warning: option -f is not implemented, ignoring error: container /dev/rdisk2 is mounted with write access; please re-run with -l. – ScottyBlades Sep 29 '19 at 00:22
  • 3
    This just saved me! Since I couldn't do anything on my server filesystem. I booted into rescue mode. 'fsck -f /dev/sda2', (my server drive is /dev/sda2), and it fixes all the errors that caused the read-only mount. I then rebooted. Thanks, aplenty! – ADEBISI Foluso A. Nov 20 '19 at 08:09
  • Is it okay to run this command before each reboot ? – alper Dec 01 '20 at 15:53
  • what does this command do? – dekuShrub Apr 09 '21 at 13:16
  • This doesn't work, it just gives an error message: fsck.ext4: Unable to resolve 'LABEL=cloudimg-rootfs' – Andrew Koster May 22 '23 at 21:05
  • I just given it to you because you simply has the most upvotes. I never accepted an solution because well nothing worked due to the flash drive was bad and at the time I was a kid and couldn't just buy another one. I was looking for an magical answer. – MathCubes Dec 06 '23 at 22:44
25

When the system enters a read-only state, it does so to prevent damage to the system. Make sure your HDD is working properly and/or backup your data before doing anything.

I suggest to boot a live USB/DVD, open GParted, and use the check/repair feature.

This is the command to enable writing:

sudo mount -o rw,remount /
David Foerster
  • 36,264
  • 56
  • 94
  • 147
14

If you are dual booting Windows with Ubuntu and you do not have any error in dmesg, then the problem could very well be caused by Windows.

In Windows go to Control Panel → Power Options and disable Fast Startup. Now boot into Ubuntu.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
Prejith P
  • 251
  • Are you implying that either 1) Windows had the ext4 root file system of OP's Ubuntu installation mounted or 2) the root file system of OP's Ubuntu installation was NTFS? I find that very unlikely. -1 – David Foerster Jul 16 '18 at 17:45
  • 3
    I am not implying both. What I mean is that if you can't mount a file system as write on a dual booted system and there are no visible issues with the file system, then the problem could be caused by the Windows Fast Startup You may downvote as you wish, but this is a valid solution for people who dual boot. – Prejith P Jul 17 '18 at 17:52
  • Not for this question though because your solution doesn't apply to it. – David Foerster Jul 17 '18 at 18:04
  • As I had mentioned in my original post, this is the 2nd solution on search for the error "read only file system", which is the same error that you get when trying to mount an external drive in dual boot – Prejith P Jul 18 '18 at 00:45
  • This is a problem when trying to write, not mount. This answer is unrelated. – Glorious Kale Dec 10 '18 at 11:15
  • 3
    This really worked for me (Ubuntu 19.04). Even though, I wasn't for sure that it'll work but it does. – HV Sharma Oct 28 '19 at 18:12
  • This solved my issue, I have Ubuntu 18.04 with Windows 10. – Sachith Muhandiram Apr 20 '20 at 05:25
  • Solved my issue for Ubuntu 22.04 – Raju Ahmed Oct 24 '23 at 07:07
9

When accessing an HDD from different OS (Windows & Linux) the disk could contain an unclean file system. So the metadata cached in the OS, deny mounting the disk

To try to correct the mistakes, identify the path of your partition disk in the Disk app (i.e: /dev/sdb1 found by lsblk) and use ntfsfix.

sudo ntfsfix /dev/sdb1

If the disk is not mounted automatically, so:

$ sudo mkdir /media/[mount point]
$ sudo mount -o rw /dev/sdb1 /media/[mount point]

If you get the error Read-only file system then you should delete the following directories from Windows:

  • .Tash-1000
  • $RECYCLE.BIN/

In Git Bash as Admin:

Identify your disk. In my case is /f

$ cd /f
$ rm -R \$RECYCLE.BIN/ && rm -R .Tash-1000

GL

Amin Ya
  • 113
Braian Coronel
  • 385
  • 3
  • 6
4

If someone using dual OS(Ubuntu, Windows) like me, NTFS filesystem is the main reason of this problem. Inspect the path of disk like "/dev/sda3", unmount the disk and run:

sudo ntfsfix /dev/sda3
1

In my case, I have a common drive between Windows and Ubuntu.

On Ubuntu, I had installed trash-cli and had trashed some files.
When I booted in Windows, I did some defragmentation on that drive.
But when I went back to Ubuntu, then it started giving me Read-only file system error on any write operation.

After reading @Braian Coronel's answer, I went back to Windows and permanently deleted .Trash-1000 folder which solved my issue.

1

TDLR; After many years I never posted this. The flash drive was bad, had basically no more write cycles to it and was literally read only.

MathCubes
  • 5,666