Why is OpenWrt's /dev/root/ turn to read-only mode?

Hello,

Sometimes my OpenWRT's /dev/root/ will go into read-only mode.

The specific phenomenon is that when I try to write to a file, "read-only file system" is displayed. At this point, the mode of /dev/root/ is "ro".

I have not figured out the conditions that triggered the problem. Sometimes because the disk is full, sometimes it is forcibly powered off, and sometimes it just runs some programs. I even wonder if it is because my flash memory is too weak.

But I found a solution. When this happens, I will run "e2fsck -y /dev/sda2" and reboot the device. After rebooting, everything is back to normal, and the "/dev/root" mode is restored to "rw".

Below is the log when I ran e2fsck. Please help me analyze why there is a problem with "read-only file system"? Is there any way to avoid this happening?

Thanks a lot.

root@OpenWrt:~# mount
/dev/root on / type ext4 (ro,noatime,block_validity,delalloc,barrier,user_xattr)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/sda1 on /boot type ext4 (ro,noatime,block_validity,delalloc,barrier,user_xattr)
/dev/sda1 on /boot type ext4 (ro,noatime,block_validity,delalloc,barrier,user_xattr)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)


root@OpenWrt:~# e2fsck -y /dev/sda2
e2fsck 1.44.3 (10-July-2018)
/dev/sda2 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Deleted inode 515 has zero dtime.  Fix? yes

Deleted inode 521 has zero dtime.  Fix? yes

Deleted inode 522 has zero dtime.  Fix? yes

Deleted inode 524 has zero dtime.  Fix? yes

Deleted inode 526 has zero dtime.  Fix? yes

Deleted inode 1559 has zero dtime.  Fix? yes

Deleted inode 1564 has zero dtime.  Fix? yes

Inode 1565, i_blocks is 3312, should be 3240.  Fix? yes

Deleted inode 1610 has zero dtime.  Fix? yes

Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences:  -904 -1024 -(9832--9848) -(9852--9855) -(9960--9961) -(9968--9972) -(9982--10207) -10226 -10238 -10259 -(10368--10745) -(10764--10767) -(10807--10928) -(11008--11263) -(11392--11775) -(11808--12415) -(12480--12511) -(12544--12799) -(12994--12995) -(13029--13030) -(13344--13439) -(14848--15359) -(15410--15412) -15423 -(15427--15428) -15434 -15438 -15442 -15445 -(17052--17053) -(18432--18943) -(20992--21049) -(28672--30207) -(30382--30390) -(32012--32017) -(32256--32767) -(49024--49054) -(49132--49149) -(50126--50127) -(50134--50138) -(50160--50166) -(50168--50173) -(50788--50803) -(50816--50820) -(51616--51652) -(51815--51819) -(51825--51830) -(52944--53074) -(53076--53116) -(53248--59391) -(59566--59575) -(61112--61142) -(61184--61439) -(62278--62282) -(62293--62296) -(63488--64511) -(67392--67410) -(70786--70790) -(72704--73117) -(74752--75690) -77376 -(81920--88025) -(90112--93187) -(94208--96255) -(136994--137017) -(137020--137085) -(137088--137215) -(145245--145381) -(157248--157406) -(157440--159244) -(161280--161637)
Fix? yes

Free blocks count wrong for group #0 (10831, counted=16387).
Fix? yes

Free blocks count wrong for group #1 (6198, counted=13982).
Fix? yes

Free blocks count wrong for group #2 (13075, counted=25680).
Fix? yes

Free blocks count wrong for group #4 (3965, counted=6651).
Fix? yes

Free blocks count wrong (108830, counted=137462).
Fix? yes

Inode bitmap differences:  -515 -(521--522) -524 -526 -1559 -1564 -1610
Fix? yes

Free inodes count wrong for group #0 (6473, counted=6481).
Fix? yes

Free inodes count wrong (63220, counted=63228).
Fix? yes


/dev/sda2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda2: ***** REBOOT SYSTEM *****
/dev/sda2: 2308/65536 files (0.7% non-contiguous), 124682/262144 blocks

This is not normal behavior and I suspect that the flash memory is not far from resting in peace.

4 Likes

I was having the same problem with my x86 box. but finally figure out the solution.
what we need to do is adding code to check and repair the device to the init script
We need to add these lines in /lib/preinit/80_mount_root

        if [ -x '/usr/sbin/fsck.ext4' ]; then
                if [ -e '/dev/sda1' ]; then
                        echo "Checking disk /dev/sda1...."
                        /usr/sbin/fsck.ext4 -y /dev/sda1
                fi
                if [ -e '/dev/sda2' ]; then
                        echo "Checking disk /dev/sds2..."
                        /usr/sbin/fsck.ext4 -y /dev/sda2
                fi
        fi

between lines "do_mount_root() " and "mount_root".

then every time the system boots, it will check and repair the disk .

3 Likes

This saved me so much time and hassle. Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.