DEV Community

Chris Thompson
Chris Thompson

Posted on

Reduce disk writes for Ubuntu, save your USB stick

I run a few Ubuntu/Mint distributions off of USB sticks (for example, DragonOS) and want to reduce the number of writes to the USB stick. My laptop has plenty of RAM so I'll make use of that.

/tmp to ramdisk

No need to keep temporary files around between reboots. Storing this in RAM instead of on disk is really easy.

sudo systemctl enable /usr/share/systemd/tmp.mount
Enter fullscreen mode Exit fullscreen mode

By default, this uses half my RAM. I can edit that file if I want to use less; 50% is probably overkill. Reboot your machine once you've made your changes.

/var/log

Log files are a bit trickier. I want these to stick around between reboots, so just storing them on a ramdisk wouldn't really work. Thankfully, log2ram solves this problem. Written primarily for Raspberry Pi machines, it works fine on x86-64 laptops. This stores /var/log in RAM but will sync the contents to disk from time to time, ideal for our needs.

echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg  https://azlux.fr/repo.gpg
sudo apt update
sudo apt install log2ram
Enter fullscreen mode Exit fullscreen mode

Reboot your machine once log2ram is installed.

Firefox

The Firefox browser caches data to disk. I'm happy setting aside a bit of RAM for this instead. In the URL bar, type about:config. Acknowledge the warning, then in the filter bar, enter browser.cache. You want to change the browser.cache.disk.enable setting from true to false (double-click on the setting to change it), ensure browser.cache.memory.enable is true (the default value), and then modify browser.cache.memory.capacity from the default value of -1 to 1048576, allocating 1GB of RAM to the cache.

Close down and restart Firefox for the settings to take effect.

More reading

Easy Linux Tips has some other suggestions based around SSDs rather than USB sticks. Limiting swappiness may be worth considering if your computer regularly hits swap. Setting noatime may be helpful, too.

What settings have you found useful?

Top comments (0)