Make a RAM drive
Spinning hard drives are slow. Solid state hard drives are fast, but have limited write cycles. Often times, you don't really need the hard drive at all: you just need a place to store temporary files. Enter the RAM drive!
A RAM drive lives on your computer's RAM (which can be pretty plentiful these days). On my machine, I have my browsers download all of my files to the RAM drive and do most of my compilation and script testing from within it. It's fast, and it preserves my hard drive.
An added, but dangerous, benefit is that all of the files are purged when you reboot your computer. This prevents you from ending up with masses of files whose purpose you no longer know, but it means you have to be careful with your battery life and thermal management (if your machine shutdowns when it overheats, like some of mine have done).
I prefer to keep my RAM drive in the /z
directory, which is easy to remember
and fast to type. Set it up as follows:
sudo mkdir /z
sudo chmod a+w /z
You can now make a temporary RAM drive with:
sudo mount -t tmpfs -o size=7g tmpfs /z
Note that the 7GB figure above is the maximum amount of RAM the drive can use. In reality, it uses only as much space as the files you have in it.
If you want the drive to be set up on every boot, add it to /etc/fstab
with
the line:
tmpfs /z tmpfs defaults,noatime,mode=1777,size=7g 0 0
Several RAM drives may already exist be default on your computer. For instance,
/dev/shm
has access to half of your RAM by default.
I also add the following line to my ~/.bashrc
file:
alias cdd='cd /z'
alias clearramdrive='rm -rf /z/*'
This gives me a quick way (cdd
) to switch to the RAM drive and a quick way to
purge it (because typing rm -rf *
by itself risks disaster, every time, even
if, like me, you never make mistakes).
If you have a lot of RAM, you can also use a RAM drive as your /tmp
directory
by adding the following to /etc/fstab
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=20G 0 0