Read-only filesystem
Possible reasons:
- Damaged filesystem
- Incorrect shutdown
- Configuration mistake
Although most file systems are designed to prevent errors, they can still occur. In such cases, Linux triggers a protection mechanism by mounting a failed block device as read-only. This allows for problem localization and prevention of further data destruction. Therefore, the first and most obvious option would be to check the file system and fix all errors, if any are found.
Diagnostics
Start with a quick look at the attached disks:
sudo fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors Disk model: EXAMPLE HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 147676BD-7D65-4290-91F0-B45ACD9E360B Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 83884031 83879936 40G Linux filesystem Disk /dev/sdb: 25 GiB, 26843545600 bytes, 52428800 sectors Disk model: EXAMPLE HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x880bd48d Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 52428799 52426752 25G 83 Linux
There are two disks presented. The first one is /dev/sda with two partitions: /dev/sda1 and /dev/sda2. This disk is used for the system and is permanently mounted. It’s impossible to fix errors without shutting down the operating system. However, there’s a trick that allows you to assess the condition of the system disk.
Check a file system
Run fsck with the -n option and examine the output:
sudo fsck -n /dev/sda2
fsck from util-linux 2.37.2 e2fsck 1.46.5 (30-Dec-2021) Warning! /dev/sda2 is mounted. Warning: skipping journal recovery because doing a read-only filesystem check. /dev/sda2: clean, 118002/2621440 files, 1794718/10484992 blocks
The inscription «clean» indicates that there are no problems with the filesystem of the system disk. If the error is caused by this particular drive, then you can try to remount it without the risk of losing data:
sudo mount -o remount,rw /dev/sda2 /
This can help in a number of cases. You can also try rebooting the server:
sudo shutdown -r now
Let’s examine another disk, /dev/sdb. Proceed with quick diagnostics:
sudo fsck -n /dev/sdb1
fsck from util-linux 2.37.2 e2fsck 1.46.5 (30-Dec-2021) ext2fs_open2: Bad magic number in super-block fsck.ext2: Superblock invalid, trying backup blocks... /dev/sdb1 was not cleanly unmounted, check forced. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: +(32768--33796) +(98304--99332) +(163840--164868) +(2 29376--230404) +(294912--295940) +(819200--820228) +(884736--885764) +(1605632-- 1606660) +(2654208--2655236) +(4096000--4097028) …
Fix the corrupted file system
Here, we see what the command output looks like if the filesystem on the first partition, /dev/sdb1, is indeed corrupted. However, the -n option works only for diagnostic purposes and does not make any changes. Use the -f option to fix broken filesystem:
sudo fsck -f /dev/sdb1
fsck from util-linux 2.37.2 e2fsck 1.46.5 (30-Dec-2021) ext2fs_open2: Bad magic number in super-block fsck.ext2: Superblock invalid, trying backup blocks... Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: +(32768--33796) +(98304--99332) +(163840--164868) +(229376--230404) +(294912--295940) +(819200--820228) +(884736--885764) +(1605632--1606660) +(2654208--2655236) +(4096000--4097028) Fix[y]? yes Padding at end of inode bitmap is not set. Fix[y]? yes /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb1: 11/1638400 files (0.0% non-contiguous), 146893/6553344 blocks
Voila! It works! Let’s check again:
sudo fsck -n /dev/sdb1
fsck from util-linux 2.37.2 e2fsck 1.46.5 (30-Dec-2021) /dev/sdb1: clean, 11/1638400 files, 146893/6553344 blocks
The filesystem is clean, indicating that the problem is solved.
Sometimes, a similar error message can be a result of an option (errors=remount-ro) specified for a particular non-system partition in /etc/fstab. This option proves valuable when the system encounters an error that poses a risk to the filesystem. It prevents any additional modifications that could worsen the issue or lead to data loss. To solve this error, simply remount the filesystem for read-write, as mentioned above.
See also:
Updated: 12.03.2025
Published: 22.05.2024