1

This just happened on my server a few days ago, it's an Ubuntu server and there is only one hard drive on it. I am logged in as root, and I cannot write to any place on the drive. I can't even use chmod, or chown anywhere in the entire drive.

When I try something like sudo chmod -R -v 755 * I get an error on every single directory saying failed to change mode of <directory>: Read-only filesystem

I am the only one who uses and has access to this server, I have no idea what I did to make this happen but I really need to fix this.

8
  • Is your file system local or remote?? It looks as if you need to remount the Filesystem as read/write. What is the result of sudo mount -o remount,rw / NEVER EVER use the command you posted, because if that does succeed, the only way to reset the permissions to the default is a full reinstall.
    – eyoung100
    Aug 27 '16 at 19:47
  • @eyoung100 Thanks for the information, and using that command gives me mount: cannot remount block device /dev/vda1 read-write, is write-protected Aug 27 '16 at 19:50
  • 1
    Then you need to remove the write protection on the drive. I'll leave that up to you, as it's BIOS and drive dependent.
    – eyoung100
    Aug 27 '16 at 19:58
  • @eyoung100 Also it's a remote server hosted on DigitalOcean. Aug 27 '16 at 19:58
  • @eyoung100 Sorry how do I do that? Aug 27 '16 at 20:01
1

First of all when you see a read-only filesystem error, your first step should always be to run an fsck (filesystem check) on the affected drive. That's because Linux has mounted the filesystem as read-only because it detected an issue on boot, and if that error was something like corruption then remounting as read/write could damage your disk beyond recovery.

Second of all, as Eyoung100 mentioned, you should NEVER run a recursive command on the root of your filesystem. You're extremely lucky that in this case Linux didn't let you actually execute that command or your Droplet would probably be messed up such that a repair would be unreasonably difficult for you.

Third you don't actually need the rw portion of eyoung's command, as it's the default in these cases. You can get away with just sudo mount -o remount / which will attempt to remount your filesystem.

Typically the write-protected error isn't the problem with these, that is odd. But you should be able to get around it by running:

blockdev --setrw /dev/vda1

Then try the previous command:

mount -o remount /

Please let me know what you see when you try that. If it doesn't work, you'll probably need to request the recovery ISO and just migrate your files off the Droplet.

3
  • Wow okay, so doing fsck and rebooting did actually fix everything haha. But can you give me any insight as to what actually happened? Aug 27 '16 at 21:39
  • @chrispytoes I'm glad it wasn't an attack. Had this not been answered, I was going to do a writeup on how to disable remote root access via SSH. Instead, see How do I disable remote SSH login as root from a server? Put your user in the wheel group, and add said user to the Allow List as per the link, and from now on, use sudo -i
    – eyoung100
    Aug 27 '16 at 23:02
  • This particular issue (read-only filesystem) is very common with upgrades from 14.04 to 16.04. Did you recently run a dist-upgrade? I'd also like to note that running a dist-upgrade on a production server is never a good idea, you should instead migrate to a newer server if you must use the newer version.
    – Darian
    Aug 28 '16 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.