Hello everyone!
I suppose several of you had to deal with errors on your drives when you boot. Or found your file systems boot up as Read Only. There is a reason for that. It’s called Write Cache. It’s a process that can speed up the writing speeds of your drive, but if something happens, like a power outage or you are forced to do a hard reset, errors may occur and your system will need to do a file check.
In harsher scenarios, the device is mounted as Read-Only, which stops you from doing any updates or creating files/folders.
In this small tutorial, I will show you how to disable Write-Cache. Your drive may become slightly slower, but it will be nothing noticeable. Especially on an SSD. That way, no matter if you have to do hard resets or power-downs, you will suffer no errors.
Okay, let us begin.
First, you will need a small utility called hdparam.
UBUNTU/MINT/ZORIN
You can install it by typing:
sudo apt install hdparm
ARCH/MANJARO
The command here is:
sudo pacman -S hdparm
SETTING UP THE CONFIGURATION
Now that the utility is installed, we can create a configuration file that will tell your system to keep Write-Cache disabled on boot.
First, you will need to identify the device that your Linux is installed on. You do not need the actual partition, just the device. Open up your trusty terminal and type:
lsblk
The one that appears to have 3 partitions (i.e. sda1, sda2, sda3) is your Linux OS. That’s if it’s the first drive. If it’s the second drive, it will be sdb1, sdb2, sdb3. In case you have an NVme, then the device will be nvme0n1p1, nvme0n1p2, nvme0n1p3.
For this case, let’s assume your Linux system is installed on the sda device (which is described as /dev/sda).
While on your terminal, execute:
sudo nano /etc/hdparm.conf
Normally, this will be a new file. If not, then don’t worry. Just make sure that the file has the following line (without a # comment line):
write_cache = off
Hit CTRL+O and then Enter to save. Then, CTRL+X to exit.
That does it!
Now, if you want to disable the cache on the spot, execute:
sudo hdparm -W 0 /dev/sda
That should disable write-cache on your current session.
You can always verify that it is done, by typing:
sudo hdparm -i /dev/sda
And that is it!
RE-ENABLE WRITE-CACHE
If you ever need to re-enable Write-Cache, you can edit the .conf file above and set the write_cache = on. Alsol for the current session, you can execute:
sudo hdparm -W 1 /dev/sda
Remember to replace the /dev/sda with the actual device that your Linux is installed on, something you can learn via the lsblk
command.