File system readonly in ubuntu 20.04

8,514

Solution 1

Let's first check your file system

  • boot to a Ubuntu Live DVD/USB in “Try Ubuntu” mode
  • open a terminal window by pressing Ctrl+Alt+T
  • type sudo fdisk -l
  • identify the /dev/sdXX device name for your "Linux Filesystem"
  • type sudo fsck -f /dev/sdXX, replacing sdXX with the number you found earlier
  • repeat the fsck command if there were errors
  • type reboot

Then let's check your HDD

Open the Disks application. Select your HDD. Go to the "hamburger" icon and select SMART Data & Tests. Take screenshot(s) of the SMART Data and edit them into your question for me to review. "Current Pending Sector Count" = 240 indicates the problem.

Bad Block

"Current Pending Sector Count" = 240 indicates the problem.

Note: do NOT abort a bad block scan!

Note: do NOT bad block a SSD

Note: backup your important files FIRST!

Note: this will take many hours

Note: you may have a pending HDD failure

Boot to a Ubuntu Live DVD/USB in “Try Ubuntu” mode.

In terminal...

sudo fdisk -l # identify all "Linux Filesystem" partitions

sudo e2fsck -fcky /dev/sdXX # read-only test

or

sudo e2fsck -fccky /dev/sdXX # non-destructive read/write test (recommended)

The -k is important, because it saves the previous bad block table, and adds any new bad blocks to that table. Without -k, you loose all of the prior bad block information.

The -fccky parameter...

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

   -c    This option causes e2fsck to use badblocks(8) program to do
         a read-only scan of the device in order to find any bad blocks.
         If any bad blocks are found, they are added to the bad block
         inode to prevent them from being allocated to a file or direc‐
         tory.  If this option is specified twice, then the bad block scan
         will be done using a non-destructive read-write test.

   -k    When combined with the -c option, any existing bad blocks in the
         bad blocks list are preserved, and any new bad blocks found by
         running badblocks(8) will be added to the existing bad blocks
         list.

   -y    Assume an answer of `yes' to all questions; allows e2fsck to be
         used non-interactively. This option may not be specified at the
         same time as the -n or -p options.

Solution 2

For those like me who are experiencing a filesystem that consistently mounts into a read-only mode but luckily the filesystem is not the one that houses your Ubuntu installation.

The filesystem repair can be done via the graphical Disks tool by selecting Repair Filesystem from the drop-down of the relevant filesystem.

enter image description here

Share:
8,514
razieh babaee
Author by

razieh babaee

working as a sysadmin and senior web developer eager to learn and code

Updated on September 18, 2022

Comments

  • razieh babaee
    razieh babaee over 1 year

    I upgraded to ubuntu desktop 20.04 about two weeks ago. Since then, my filesystem keeps on getting into a readonly state, sometimes while I'm in the middle of working with the system and I often see the initramfs screen on system startup. It takes a while for my system to shutdown and sometimes I have to force power off by holding the power button.

    My system is dual-boot and I have windows and ubuntu side-by-side. I have no problem with windows partitions . The ubuntu partition gets readonly all the time.

    How can I solve or diagnose what is causing this problem?

    Edit:
    Here is the Smart data and self-test result. I took the screenshot after recovering from another crash on boot:

    Smart data and self tests screenshot

    • vanadium
      vanadium almost 4 years
      Have your file systems checked. Especially the "force power off" can damage your root file system. It may by times be broken to the extent that it is mount read only.
  • razieh babaee
    razieh babaee almost 4 years
    I added Smart test results to the question.
  • Boris Hamanov
    Boris Hamanov almost 4 years
    @raziehbabaee You did the fsck, yes? Please do the "Bad Block" portion of my answer. Maybe we can save the HDD.
  • razieh babaee
    razieh babaee almost 4 years
    It worked! Thanks!
  • Boris Hamanov
    Boris Hamanov almost 4 years
    @raziehbabaee Good news! Thanks for the update.