Today i am going to show you how to create a ramdisk in Ubuntu, but the same applies for other Linux Distributions also. Before going to point i want to make clear why you need ramdisk in first place.
ramdisk is useful in many places like if you are watching an HD movie from harddisk. The disk always keeps up spinning, which may reduce the life of the hard disk, other place is in software applications, if you move ide like Android Studio or Intellij IDEA to ramdisk they offer more performance
In order to get full performance you need to have more ram like 8 GB. its not like if you have less ram you cannot create ramdisk, you can create but you cannot load big files to ram.
Create a directory first
mkdir -p /home/shrey/Others/Ramdisk
we use mount command -t specifies type is tmpfs is temporary filesystem source is tmpfs destination is my home directory and the size is 2GB.
sudo mount -t tmpfs tmpfs /home/shrey/Others/Ramdisk -o size=2048m
Note the destination directory should be created first then run this command, Ramdisk are volatile after you shutdown the data will be lost, so be careful do not copy original files to disk as they will lost after shutdown,crash,reboot.
To easily use this command we create an alias for this
alias ramdisk="sudo mount -t tmpfs tmpfs /home/shrey/Others/Ramdisk -o size=2048m"
paste this in your .bashrc or .zshrc or .alias file. Restart the terminal and run ramdisk command, ramdisk will be created. Go the destination directory copy a movie file over there mine is in
/home/shrey/Others/Ramdisk play the movie from there. You can see the movie is loaded from ram so it will be faster. and no hard disk is used here to play the movie.
If you want ramdisk to be created at every startup or reboot
vim /etc/fstab Add
tmpfs /home/shrey/Others/Ramdisk tmpfs rw,size=2048M 0 0
at the end of the file. Now you don need to run the command ramdisk every time.
I mostly use ram disk for watching movies for 2+ hours best use of ramdisk is loading the static files like html, js, fonts & images in ramdisk it could increase the server response time and disk performance of web server .
For ease of access in Ubuntu Desktop open the folder Ramdisk in Files app or Nautilus in menu Bookmarks -> Bookmark this Location you will get the directory in left sidebar.