[Linux] Move your Firefox profiles to RAM
Firefox can write gigabytes of data to your hard drive every day, even if you barely use it. But you can completely eliminate this write activity if you move your Firefox profile from your hard drive into RAM. The downside is that you might lose your most recent activity if the computer shuts down unexpectedly.
The plan
When the computer starts up, we’ll copy your Firefox profiles from your SSD to RAM. That way, Firefox can write as much as it likes, and there will be no changes your SSD.
When the computer shuts down (or at regular points throughout the day), we’ll save your profiles back to the SSD, so your history and bookmarks will be remembered.
Create the backup scripts
Create these two scripts:
/usr/local/sbin/mozilla-start:
#!/bin/sh
rsync -Haq '/home/user/.config/mozilla/' '/home/user/.mozilla/'
/usr/local/sbin/mozilla-stop:
#!/bin/sh
if [ -n "$(ls -A '/home/user/.mozilla')" ]; then
rsync -Haq --delete '/home/user/.mozilla/' '/home/user/.config/mozilla/'
fi
…and make sure they’re executable:
chmod a+x /usr/local/sbin/mozilla-*
Backup your profile
Backup your Firefox profile by running this command:
/usr/local/sbin/mozilla-stop
You should see a copy of your profile at “/home/user/.config/mozilla/”.
Run the backups automatically
Create these two systemd unit files to run the backups automatically:
/lib/systemd/system/mozilla-start.service:
[Unit]
Description=Load Firefox and Thunderbird into RAM
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/mozilla-start
[Install]
WantedBy=sysinit.target
/lib/systemd/system/mozilla-stop.service:
[Unit]
Description=Save Firefox and Thunderbird to the hard drive
RequiresMountsFor=/home /home/user/.mozilla
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/usr/local/sbin/mozilla-stop
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
…and be sure to enable them both:
systemctl enable mozilla-start
systemctl enable mozilla-stop
Mount Firefox in RAM
Add this line to your “/etc/fstab” file:
tmpfs /home/user/.mozilla tmpfs defaults 0 0
…and that’s it! The next time you reboot your computer, Firefox will be running in RAM.