Ubuntu goes into read-only mode randomly

27,170

The Issue

The reason it randomly switches to read-only is that if the kernel detects a filesystem error, it immediately switches to read-only mode to prevent further trashing the disk. (That is, the problem isn't with the hard disk itself, but with the filesystem on the hard drive.) If you continue using such a corrupted filesystem, it will only get worse, not better. The easiest way to fix it is to use a live CD/DVD; the Ubuntu install disk will do.

The Fix

It goes without saying, but step zero is, Ensure you have a backup of vital data.

  1. Boot your computer from the live disk.
  2. The easiest way to perform these operations is in the terminal, so go ahead and open one with Ctrl-Alt-T.
  3. Run sudo blkid to get a list of all the block devices on the computer. You are looking for the partition you installed Ubuntu to; it will likely be /dev/sdaX, where X is some number. If you have absolutely no idea which one it is, it will likely be the only one formatted as ext3 or ext4 (TYPE="ext4").
  4. Run sudo umount <your partition> to ensure the partition is unmounted; the filesystem checker will refuse to operate on a mounted disk.
  5. Run sudo fsck -Cy <your partition>. The -C option displays a progress bar and is entirely for show. -y tells fsck to go ahead and fix everything it finds. If it comes back with errors, use your best judgement, or post them here and I'll look at them.
  6. Reboot; hopefully, you're done! If you'd like, you can run fsck more than once to ensure that it really did fix everything.
Share:
27,170

Related videos on Youtube

user1730404
Author by

user1730404

Updated on September 18, 2022

Comments

  • user1730404
    user1730404 over 1 year

    For the last few days, my Ubuntu 12.10 has been going to read-only mode randomly, making me unable to save any edited files, and forcing me to restart my computer, which is a pain because this is the platform on which I do all my programming work. When I do restart into Ubuntu (I have a dual-boot with Windows 7), it tells me that it detected a disk error, and that I have to press f to fix it, after which it will restart successfully.

    My Windows 7 doesn't have any problems with it, so it can't be the hard disk. I also saw on a forum that I should run these commands to fix the issue: mount --options remount,rw / and mount --all, but these just say that I cannot mount the device on a read-only system. I'm a Linux newbie (and a newbie with computers in general) so any help would be greatly appreciated!

    EDIT 1:

    Okay, so I ran fsck from the boot CD… Is it supposed to only take two seconds? 'Cuz mine did. Anyway, it came back with two errors:

    Superblock last mount time is in the future (hardware clock incorrect)
    

    and

    Superblock last write time is in the future (hardware clock incorrect)
    

    It fixed both of them, apparently.

    EDIT 2:

    I just ran sudo fsck -Cf /dev/sda5. Found a lot more this time.

    Is fsck supposed to take only a few seconds?

    EDIT 3:

    I just ran sudo badblocks -v /dev/sda5 and badblocks found four bad sectors:

    27238968  
    27238969  
    27238970  
    27238971  
    

    What do I do with this knowledge? The guide bodhi linked says to write them to a file, but I'm in LiveCD - I can't write anything to the hard disk.

    • Panther
      Panther about 11 years
      I disagree, sounds very much like a problem with your hardware. could be the bad sectors do not affect Windows, who knows. I suggest you test the hard drive - howtogeek.com/howto/37659/…
    • user1730404
      user1730404 about 11 years
      Ubuntu 12.10 doesn't seem to have any of the tools mentioned in the link. Any other advice?
    • Andrea Corbellini
      Andrea Corbellini about 11 years
      Windows and Ubuntu are on different partitions, and different partitions span different sectors. This is way you can't be sure that your hardware is OK. Anyhow, it'd be helpful you post some logs to shed some light on the problem: when the issue occurs, could you paste the output of the command dmesg and maybe the output of the file /var/log/kern.log?
    • user1730404
      user1730404 about 11 years
      Small update: when it's in read-only mode, I'm unable to open a browser window or save the text in a file, so no way of getting the information on here. However, this has happened twice today so far, and both times it occurred right as I opened Firefox.
    • Admin
      Admin almost 11 years
      We are many that are affected by this problem with recent ubuntu kernels. Let's hope someone figures it out soon. See bugs.launchpad.net/ubuntu/+source/linux/+bug/1063354
    • heena bawa
      heena bawa over 7 years
      if you have two operating system on laptop and your file is saved in one e.g. windows and you are opening that file in ubuntu then the system randomly goes into read only mode for such files. copy and Save the work in the ubuntu directory (in the memory where ubuntu is installed) then it will work.
  • user1730404
    user1730404 about 11 years
    Okay, so I ran fsck from the boot CD... is it supposed to only take two seconds? 'Cuz mine did. Anyway, it came back with two errors: Superblock last mount time is in the future (hardware clock incorrect) and Superblock last write time is in the future (hardware clock incorrect) It fixed both of them, apparently.
  • user1730404
    user1730404 about 11 years
    An update - the problem persists >_<
  • thirtythreeforty
    thirtythreeforty about 11 years
    Those errors are usually fairly harmless; it just means your clock got out of sync. Try doing a sudo fsck -Cf, which omits the -y and -forces fsck to check it, even if it thinks it is clean.
  • user1730404
    user1730404 about 11 years
    Quick question before I proceed: upon entering sudo fdisk -l, I see a drive (/dev/sda4) that I don't see when I do sudo blkid. It has 4000 more blocks than what I thought was my Linux drive (/dev/sda5) and is located in the same range of blocks (plus 4000 more, obviously), but unlike that drive, it is labelled "Extended", rather than "Linux". Which one should I tinker with? Correction: 4 million more blocks... whoops
  • thirtythreeforty
    thirtythreeforty about 11 years
    That is the extended partition, which exists to get around the 4-partition limit of the MSDOS-style partition table (which most PCs use). Use /dev/sda5. sda4 is just a container of sda5, and perhaps others.
  • warsong
    warsong over 7 years
    I'm guessing by the lack of a resolution on this issue that it still hasn't been resolved yet. I ask as I have recently been having the same problem. Pretty sad that 4 years have passed and still no solution to this (this issue dates to 2012 bugs.launchpad.net/ubuntu/+source/linux/+bug/1063354)