Your Linux Disk Went Read-Only? Here's the Real Fix
Your Linux filesystem switched to read-only mode. We'll fix it step by step, from a quick remount to checking disk health. No fluff.
Disk Filesystem Read-Only Mode Activated – What Happened?
You're trying to save a file or create a folder, and you get Read-only file system. Your whole drive or partition stopped accepting writes. This usually happens after a crash, a bad shutdown, a failing disk, or a forced unmount. I've seen it on Ubuntu servers and Raspberry Pi SD cards – it's always the same story: the OS detected something wrong and flipped the switch to protect your data.
The Quick Fix: Remount as Read-Write (30 seconds)
Before you panic, try this. It works maybe 60% of the time when the filesystem isn't actually damaged.
- Open a terminal.
- Find the partition that's read-only. Run
mount | grep ro. You'll see something like/dev/sda1 on / type ext4 (ro,errors=remount-ro). That ro is the problem. - Remount it with write access:
Replacesudo mount -o remount,rw /dev/sda1 //dev/sda1and/with your actual device and mount point. - Check with
mount | grep roagain. If it shows rw, you're done. If it still says ro or throws an error, move to the moderate fix.
Had a client last month whose Ubuntu server went read-only after a power flicker. This remount got them back up in under a minute. But if it fails, it's usually because the filesystem has actual errors.
The Moderate Fix: Check and Repair with fsck (5 minutes)
When a simple remount doesn't work, it's time to check the filesystem for corruption. The tool is fsck. You must unmount the partition first – don't run fsck on a mounted filesystem unless it's the root partition in recovery mode. For root, you'll need to boot from a live USB or use single-user mode.
- Unmount the partition:
sudo umount /dev/sda1. If it says target is busy, stop all processes that use it:sudo fuser -km /mount/point. - Run fsck:
The -y flag auto-answers yes to all repair prompts. If you want to see what it finds first, skip -y and answer manually.sudo fsck -y /dev/sda1 - Let it finish. It'll show things like Inode count or Block bitmap errors. That's normal. When it's done, remount:
sudo mount /dev/sda1 /mount/point. - Test with
touch testfile– if it creates the file, you're good.
I've fixed hundreds of SD cards on Raspberry Pi this way – they corrupt all the time from improper shutdowns. The -y flag saves time, but be careful: it'll delete unrecoverable files without asking. If you have critical data, back it up first.
What if fsck can't unmount the root partition?
For root filesystem (/), you can't unmount it while the system is running. Two options:
- Boot into recovery mode (hold Shift at boot on GRUB) and run fsck from there. It'll remount as read-only automatically.
- Use a live USB – boot from an Ubuntu installer, open a terminal, find your partition with
lsblk, then run fsck.
The Advanced Fix: Check Hardware and SMART (15+ minutes)
If fsck finds the same errors every time you run it, or the disk keeps going read-only again, the drive is failing. Time to check the hardware.
- Install smartmontools if you don't have it:
sudo apt install smartmontools(on Debian/Ubuntu) orsudo yum install smartmontools(on RHEL). - Run a quick test:
Look for SMART overall-health self-assessment test result: PASSED. If it says FAILED, that drive is on its way out.sudo smartctl -H /dev/sda - For more detail, check the error log:
If you see Read Error or UNC (Uncorrectable) errors, the disk has bad sectors.sudo smartctl -l error /dev/sda - If you find bad sectors, back up your data NOW. Then replace the drive. You can try
badblocksto mark bad sectors, but it's a temporary fix.
What about SD cards or USB drives?
Same deal. But they don't usually have SMART support. For SD cards, the failure mode is often the card dying slowly. If it keeps going read-only after fsck, toss it and get a new one. I've seen too many clients lose data because they kept repairing a dying card.
Extra Tip: Prevent Read-Only Mode in the Future
If this is a server, set your filesystem to auto-remount on errors. Edit /etc/fstab and add errors=remount-ro to your options. That's already the default for many distros, but check:
# Example fstab entry
/dev/sda1 / ext4 defaults,errors=remount-ro 0 1
Also, get a UPS if power outages cause this. For Raspberry Pis, always shut down properly with sudo shutdown -h now – pulling the plug is the number one cause of read-only corruption.
Summary – Don't Overthink It
Start with the remount. That's the 30-second fix. If it fails, run fsck – that fixes 95% of corruption cases. If errors come back, check SMART and replace the drive. That's it. Don't waste time with fancy tools or recompiling kernels. Just follow these steps and you'll be back to writing files in no time.
Was this solution helpful?