How to Fix "Read-only file system" error when I run something as sudo and try to make a folder/file?

453,798

Solution 1

This worked for me:

First, run this command with sudo permission:

sudo fsck -n -f

Then reboot the machine

Solution 2

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 /

Solution 3

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.

Solution 4

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) 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

Share:
453,798

Related videos on Youtube

Sch-Tomi
Author by

Sch-Tomi

Updated on September 18, 2022

Comments

  • Sch-Tomi
    Sch-Tomi over 1 year

    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.

  • Sch-Tomi
    Sch-Tomi about 11 years
    I can't because I need sudo access and I can't get it. "sudo: unable to open /var/lib/sudo/mathcubes/1: Read-only file system mount: cannot remount block device /dev/sda6 read-write, is write-protected "
  • GM-Script-Writer-62850
    GM-Script-Writer-62850 about 11 years
    as i said boot up a live disk and use gparted to check/repair the partition, if you don't have a disk you can use partedmagic it is under 500MB in size
  • Sch-Tomi
    Sch-Tomi almost 11 years
    How? Do I repair the partition in gparted?
  • GM-Script-Writer-62850
    GM-Script-Writer-62850 almost 11 years
  • Sch-Tomi
    Sch-Tomi almost 11 years
    But What do I do in gpared, reformat it NO!
  • GM-Script-Writer-62850
    GM-Script-Writer-62850 almost 11 years
    right click a partition and click check, the partition must be unmounted
  • GM-Script-Writer-62850
    GM-Script-Writer-62850 almost 11 years
    Apparently I am unable to use the chat, as i don't have any reputation on stackexchange
  • Sch-Tomi
    Sch-Tomi almost 11 years
    It doesn't work it only work for a tempory amount of time. :(
  • msouth
    msouth about 7 years
    @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.
  • sudodus
    sudodus about 7 years
    @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.
  • msouth
    msouth about 7 years
    @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.
  • Etienne Gautier
    Etienne Gautier over 6 years
    Underrated answer.
  • David Foerster
    David Foerster almost 6 years
    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
  • Prejith P
    Prejith P almost 6 years
    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.
  • David Foerster
    David Foerster almost 6 years
    Not for this question though because your solution doesn't apply to it.
  • Prejith P
    Prejith P almost 6 years
    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
  • Glorious Kale
    Glorious Kale over 5 years
    This is a problem when trying to write, not mount. This answer is unrelated.
  • ScottyBlades
    ScottyBlades over 4 years
    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
    ScottyBlades over 4 years
    I'm getting the following: mount_apfs: unrecognized option 'remount' mount_apfs: [-o options] [-u UID] [-g GID] [-c [-r] | [-C|-F <tier2 device>]] [-s snapshot] <volume | device> <directory> mount: / failed with 64
  • HV Sharma
    HV Sharma over 4 years
    This really worked for me (Ubuntu 19.04). Even though, I wasn't for sure that it'll work but it does.
  • ADEBISI Foluso A.
    ADEBISI Foluso A. over 4 years
    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!
  • Sachith Muhandiram
    Sachith Muhandiram about 4 years
    This solved my issue, I have Ubuntu 18.04 with Windows 10.
  • alper
    alper over 3 years
    Is it okay to run this command before each reboot ?
  • dekuShrub
    dekuShrub about 3 years
    what does this command do?