68

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
  • 59,332
MathCubes
  • 5,732

7 Answers7

43

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,890
  • 56
  • 97
  • 151
27

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,890
  • 56
  • 97
  • 151
15

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,890
  • 56
  • 97
  • 151
Prejith P
  • 261
11

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, then:

$ 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 .Trash-1000

GL

Vulcan
  • 3
Braian Coronel
  • 403
  • 4
  • 7
5

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.

Hrishikesh Kadam
  • 359
  • 5
  • 14
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,732