How to load all linux system in ram and increase considerably the pc speed

2013-11-16 11:44:20

Hello to everyone in this article i'm going to show you how to load all your linux system os to the ram
in order to get a outperforming pc with a incredible velocity.
Warning :
I recommend you to make a back up of yours systembefore to try this guide.
I do not assume any responsibility for the loss of your data.

Requiroment :
--At least 8 Gb of ram

--A operative system debian based , i tried on debian 7.02 and debian 6.06
   probably will work also on Ubuntu and others distro derived from debian.

--Medium knowledge of the linux terminal

At the end of this guide you will have the faster system you have ever seen!!
Faster than any system installed on ssd!
In addition we will create 2 grub entries that will permit you to choose
to run the system on hard disk or on the ram.
When you choose to start on ram all changes made to the system in this mode will be
forgotten once restarted.
This means that you can install programs, test terminal commands
and other such things without fear of corrupting your system!

The startup may take up to 10 minutes depending on which hard drive you have and how much space occupies your linux system.
During startup you will see a black screen with a blinking white cursor.
When you reboot you lose all data and changes that you have saved on the hard disk
you can avoid this problem in various ways which I will explain later.

Why on earth i think to run the entire system on ram?
Why after having bought and assembled the pieces of my pc this riusultava not be
as fast as I wanted.
My pc is as follows:
Amd Phenom 2 X6 Black Edition
Scheda madre asrock 890GX Extreme3
16 GB G.SKILL DDR3 1600
I recently added a Ati 7970xfx Ghost Edition

After installing Mint Debian Edition i had an average fast system but i don't build
my pc in order to have a "only" average fast system.

So i decided to investigate and discover what did slow down my pc.
I found out that the problem are my hard disks.
I found an interesting post where they teach me how to remedy.

I decided to try the post's guide.
The first time i thought the pc was not going to boot so i restart it.
After that i understood that the pc needs more time to copy all the data from the hard disk to the ram.
I waited with the black screen and after about 12 minutes the pc showed me the login screen.
I tried the system and i was very amazed from the responsiveness of the pc!
It was instantaneous !
You click to run a program and after you released the click the program was already there! Wonderful!
So i decided to write thi guide.

Why loading on your ram all your system the pc become so faster?
Becouse the slower part fo the pc is the only mechanical part! the pc hard disk!!!
Every time you run a program it is read from the hard disk.
Also the faster hard disk is a bottleneck for the nowadays PCs
Removing all the hard disk reading and writing you remove a long waiting time!

The Ram is a lot faster than any hard disks.
A DDR3 ram is rated from 6400 MB/s to 12800 MB/s varying from the model.
A solid state disk is rated from 250MB/s to 600 MB/s varying from the model.
A rotary hard disk is rated from 50 to 150MB/s varying from the model.

Now you can see that the velocity of the slower DDR3 ram is about 42 times faster
than the faster rotary hard disk!

Your pc will not run 42 times faster but you will notice a great difference
and it is worth the work to gain that.

Lets start the guide

Let's start with the guide:

I started with a version of Debian 7.2 installed from netcd so i install
the bare minimum programs and Mate.

Open a terminal

Write the following in order to make a back up of the fstab file:

sudo cp /etc/fstab /etc/fstab.bak

Now open with your favorite text editor as an administrator the file:
sudo pluma /etc/fstab oppure sudo gedit /etc/fstab oppure sudo nano /etc/fstab

Look for the line where it is the root partition /

Mine was written like this:
UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 / ext4 noatime,errors=remount-ro 0 0

Make sure that on your old line of the root is either disabled fsck so that there are 2 zeros
as the end of my line of example, if they are not replace the numbers with two zeros
after that restart your PC.
Reopen the file and proceed as before.

At this point, replace the line of the root with:
none / tmpfs defaults,noatime,nodiratime,discard 0 0

Save and close the file.
Move yourself typing in the terminal:
cd /usr/share/initramfs-tools/scripts/

Make a copy of the file local with:
sudo cp local local.bak

Open with your favorite text editor as an administrator the file:
sudo pluma local oppure sudo gedit local oppure sudo nano local

Search a part like this:
# FIXME This has no error checking
# Mount root
if [ "${FSTYPE}" != "unknown" ]; then
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
fi[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && log_end_msg}

In particular, you should find the line # Mount root that tells you that you are in the right place.
Replace the lines with following ones :

# FIXME This has no error checking
# Mount root
mkdir /ramboottmp
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ramboottmp
mount -t tmpfs -o size=100% none ${rootmnt}
cd ${rootmnt}
cp -rfa /ramboottmp/* ${rootmnt}
umount /ramboottmp
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && log_end_msg

Depending on the version of Linux you have ,you could have to change the lines
but should not differ by much.

Save and close the text editor.

Now run from terminal:
sudo mkinitramfs -o /boot/initrd.img-ramboot

May print 2 warning but is usual.

Restore now the old local with:
sudo cp -f local.bak local

Open the file /boot/grub/grub.cfg with your favorite text editor as an administrator :
sudo pluma /boot/grub/grub.cfg oppure sudo gedit /boot/grub/grub.cfg

Find the first part that look like this:
menuentry 'Debian GNU/Linux, con Linux 3.2.0-4-amd64' --class debian --class gnu-linux --class gnu --class os {
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd2,msdos1)'
search --no-floppy --fs-uuid --set=root b4a375f0-3cae-41ec-a130-fd9fa5207b07
echo 'Caricamento Linux 3.2.0-4-amd64...'
linux /boot/vmlinuz-3.2.0-4-amd64 root=UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 ro quiet
echo 'Caricamento ramdisk iniziale...'
initrd /boot/initrd.img-3.2.0-4-amd64

Copy and paste it just above modifying it as following

In menuentry add a label that let you know that is the entry to run the system on ram :
I added RAM!!! (make sure to not made it too long or maybe will not work)
Now where is written :
initrd /boot/something
replace something with:
My menuentry is like this:
menuentry 'Debian GNU/Linux,Linux3.2.0-4-amd64 RAM!!!' --class debian --class gnu-linux --class gnu --class os {
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd2,msdos1)'
search --no-floppy --fs-uuid --set=root b4a375f0-3cae-41ec-a130-fd9fa5207b07
echo 'Caricamento Linux 3.2.0-4-amd64...'
linux /boot/vmlinuz-3.2.0-4-amd64 root=UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 ro quiet
echo 'Caricamento ramdisk iniziale...'
initrd /boot/initrd.img-ramboot

We created another grub entry equal to the original but that start with:
initrd /boot/initrd.img-ramboot
instead to start with
initrd /boot/initrd.img-3.2.0-4-amd64

So it load the system on Ram

At this point save and close the file.

Reboot and now you should have a new entry in the grub

Choose it and after 10 -15 minutes your pc will show you your linux system.

Now you have an extremely fast system

Rebooting and choosing the old grub entry you can run the old system .

Changing this system you will change also the on ram system.

I have the home folder almost empty and my system occupies 3.7 Gb then for me
6 Gb of ram would be enough to run the whole system in ram.
Becouse my system would use 4 Gb of ram to store the os files and the others 2 Gb as usual ram.

With 8 Gb you could probably run almost any os linux system in ram. 

I recommend you to store all the files in a different partition.
So store only the programs configurations in your home folder.

In order to have a faster boot (from 15 minutes to 1 minute) i use a ssd .
Doing so the copying time from the ssd to ram is reduced a lot

I discovered recently that the suspend to ram feature works good on my linux pc .
So in 20 seconds my pc is ready after been suspended to ram!

If you have some questions ,suggestion ,corrections or you just like my articles please leave a comment.
Share this article to improve the velocity of computers and to spread the linux use.

Thanks to Tibor Áser Veres here the guide to run Ubuntu 16.04 LTS on ram:

Here is an Ubuntu version I made:
Step 1:
Make a copy of your initrd.img just in case...
you use a live session to restore it if it won't boot
sudo cp /boot/initrd.img-x.x.x-xx-generic /boot/initrd.img-x.x.x-xx-generic.old replace the "x" characters with your system specific numbers...

Step 2:
Edit: /etc/default/grub in order to see the prompt form normal/ramboot mode...
Edit it with nano: sudo nano /etc/default/grub
Step 3:
Run update-grub after changes to take place... sudo update-grub

Step 4:
Edit: /usr/share/initramfs-tools/scripts/local You may want to use gedit,
so that you can search with ctrl+F in the file
Find this 2 lines in the script(search for: "# Mount root" FIXME line appears at more places, and it may be temporary until it's fixed...):
# FIXME This has no error checking # Mount root Paste this under "# Mount root" line: ### Custom modification starts ### read -t 10 -p 'Do you want to boot normally? (enter Y if so...)' Yy case $Yy in [Yy]* ) clear echo 'Booting normally' mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt} ;; *) clear echo 'Booting in RAM' mount -t tmpfs -o rw,noatime,nodiratime,size=100% tmpfs ${rootmnt} mkdir /ramboottmp mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} /ramboottmp cp -rfa /ramboottmp/* ${rootmnt} umount /ramboottmp rm /ramboottmp ;; esac ### End of custom modifications ###

Remove or uncomment these lines: mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt}

Step 5:

sudo mkinitramfs -o /boot/initrd.img-x.x.x-xx-generic replace the "x" characters with your system specific numbers...

Final step: sudo reboot


< prev