Attempting to create a directory, edit a configuration file, or install a package in Ubuntu can sometimes fail abruptly with the critical kernel error: “mkdir: cannot create directory: Read-only file system” or “touch: cannot touch ‘file’: Read-only file system”. Even the root superuser account is blocked from writing data to the drive.
When this happens, the Linux kernel has deliberately remounted your storage partition into a protective read-only state. By default, ext4 and other Linux filesystems are configured with the safety rule errors=remount-ro. If the kernel detects storage I/O errors, metadata corruption, or broken journal blocks, it immediately halts write operations to prevent irreversible data loss. This guide explains how to diagnose the underlying cause, run safe filesystem checks, and restore write access to your Ubuntu system.
Method 1: Check Kernel Diagnostic Logs for Filesystem Errors
Before attempting to force write operations, inspect the Linux kernel ring buffer (dmesg) to determine why the kernel locked the partition.
- Press Ctrl + Alt + T to launch the terminal (or access a recovery shell if the desktop environment fails to load).
- Query the kernel buffer for filesystem and I/O error messages:
sudo dmesg | grep -iE 'error|ext4|remount-ro|read-only' - Look for log entries such as
EXT4-fs error (device sda2): remounting filesystem read-only. - Identify the exact block partition affected (e.g.
/dev/sda2or/dev/nvme0n1p2). This information is crucial for running disk repair tools.
Method 2: Attempt a Temporary Read-Write Remount
If the error was triggered by a temporary storage controller glitch or a clean recovery remount, instructing the kernel to remount the partition read-write may restore access immediately.
- In the terminal, run the following remount command on your root partition:
sudo mount -o remount,rw / - If the filesystem remounts without errors, test write access by creating a temporary file:
touch /tmp/testfile && rm /tmp/testfile - If the command fails with “Cannot remount read-write: Filesystem has errors”: Do not attempt to force write operations; proceed immediately to Method 3 to repair the filesystem using
fsck.
Method 3: Run Filesystem Check and Repair (fsck)
Crucial Rule: Never run fsck on a mounted filesystem that has write permissions enabled, as doing so can corrupt directory trees. Because the partition is already read-only, or when booting from a Live USB, running fsck is completely safe.
- If the root partition is currently running, the safest method is to reboot your machine into Ubuntu Recovery Mode.
- Restart your PC. As the computer boots, hold down the Shift key (or press Esc repeatedly on UEFI systems) to display the GRUB boot menu.
- Select Advanced options for Ubuntu.
- Select the entry ending in (recovery mode).
- From the Recovery Menu, use the arrow keys to highlight fsck (Check all file systems) and press Enter.
- The utility will prompt you to confirm remounting read-only; select Yes.
fsckwill scan block allocations, fix corrupted inodes, and repair damaged ext4 journal blocks.- Once complete, select resume to boot into Ubuntu normally.
Method 4: Repair Using an Ubuntu Live USB
If you cannot access the GRUB recovery menu, booting from any standard Ubuntu Live USB allows you to repair the unmounted drive safely.
- Boot your computer from an Ubuntu Live USB and choose Try Ubuntu.
- Open the terminal (Ctrl + Alt + T).
- Identify your primary drive partition by running:
lsblk -f - Run a comprehensive filesystem check with automatic repair:
(Replacesudo fsck -fy /dev/nvme0n1p2/dev/nvme0n1p2with your actual root ext4 partition identifier). - Once the check reports that the filesystem was modified and is clean, reboot your PC without the USB drive.
Method 5: Verify SMART Disk Health for Hardware Failure
If a filesystem repeatedly locks into read-only mode after every reboot, your physical SSD or HDD may have developed bad sectors and is reaching end-of-life.
- Install the smartmontools hardware auditing utility:
sudo apt-get install smartmontools - Run a health assessment on your physical storage drive:
(orsudo smartctl -H /dev/sda/dev/nvme0n1for NVMe SSDs). - If the overall health assessment reports FAILED or shows numerous reallocated sectors, back up your files immediately and replace the physical drive.
Ubuntu Read-Only Filesystem Troubleshooting Reference
The table below provides a quick reference for understanding and addressing read-only mount conditions:
| Observed Trigger | Kernel Mechanism | Resolution |
|---|---|---|
| Read-only after unclean shutdown | Orphaned journal inodes flagged dirty | Run sudo fsck -fy /dev/sdX from Recovery Mode |
| External USB drive mounts read-only | NTFS/FAT dirty bit set by Windows fast startup | Disable Windows Fast Startup or run ntfsfix |
| /etc/fstab misconfiguration | Invalid mount options or wrong UUID | Verify UUID in /etc/fstab matches blkid |
| Kernel I/O timeout on SSD | Failing NAND controller or damaged SATA cable | Check SMART health and replace storage hardware |
Protecting Ubuntu Systems from Filesystem Corruption
To prevent ext4 filesystems from dropping into read-only mode, always shut down your system gracefully using sudo shutdown -h now rather than holding down the physical power button. Ensuring that desktop uninterruptible power supplies (UPS) or healthy laptop batteries prevent sudden power interruptions will keep your disk journaling structures pristine.