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




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

Advantages:
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!

Disadvantages:
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.
http://reboot.pro/topic/14547-linux-load-your-root-partition-to-ram-and-boot-it/

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}
else
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 {
load_video
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:
initrd.img-ramboot
My menuentry is like this:
menuentry 'Debian GNU/Linux,Linux3.2.0-4-amd64 RAM!!!' --class debian --class gnu-linux --class gnu --class os {
load_video
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...
Change: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" >> GRUB_CMDLINE_LINUX_DEFAULT=""
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


        






Comments:

Ivar:


If /home is mounted as a separate partition, I guess only the root and binaries would be copied to ram, so that files in the users home folder would be persistent? In that case, one only needs to boot normally if one wants to change the configuration of the PC.





jose:


Execellent, It works!!!





marco_admin:


Ivar you are right if the /home is mounted as a separate partition then only the binary will be loaded to ram. So the configuration can be modified in the home and will last after the reboot. The negative part is that a program that looks for the configuration in the home partition will read it from hard disk. So the program will be just a little slower than in full ram configuration. I used this type of configuration for a long time but i prefer the full ram mount. Jose thank you for the comment i'm glad to hear that!





vicky:


i only want to run linux as a router...only the static routes need to be persistent..is it possible to make a RAM linux save some config to hard disk and read the config during boot ??





Marco_admin:


Yes is possible! you could make a new partitions mount it as read and write,and then read it at boot time. You could also mount some partitions as read and write like /den or what else and mount all the others partitions in ram But if you need to set some files only one time you could follow my guide..





luca:


Usare sempre gksudo e kdesu per i programmi grafici (a seconda se gtk/qt) mai sudo, perché talvolta crea problemi di permessi che possono perfinmo bloccar eil login in un secondo momento.





luca:


Aggiungere "ldd nomeprogramma" in uno script di avvio (quindi senza copiare niente in RAM) rende istantaneo l'avvio dei programmi, senza attendere ben 10' in fase di boot e senza sprecare preziosa RAM. Questo perché Linux manda in page cache il contenuto del programma e decide se e quali pagine di memoria mantenere in RAM con politica LRU ottimizzata. Quanto alle scritture su disco, si regoli /proc/sys/vm/swappiness che, a dispetto del nome, regola la proporzione tra page cache (copie dei dati del disco mantenute in memoria) e pagine anonime (cioè memoria allocata dai programmi) incrementando la prima a seconda dell'uso che si fa del computer. Questo permette anche di cambiare "profilo" dinamicamente a seconda dell'esigenza.





luca:


(continua) ... e si regoli la mount option "commit" (sia in ext4, sia in btrfs) che stabilisce quanto spesso le modifiche al file system saranno salvate su disco (per ext4 il default è 5' mi pare). Naturalmente fanno eccezione le operazioni di fsync (= aggiornamento dei pacchetti, comando "sync", ecc.) che per natura richiedono un salvataggio istantaneo delle modifiche sul disco. Non ha senso usare un kernel ottimizzato per reggere i server su cui si basa l'infrastruttura Internet, se poi si aggirano le ottimizzazioni del suo memory manager e del buffer manager copiando direttamente tutto in RAM, mi sbaglio?





Tibor Áser Veres:


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... Change: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" >> GRUB_CMDLINE_LINUX_DEFAULT="" 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





Marco_admin:


Ciao Luca grazie per le informazioni aggiuntive!Devo provarle ma sono sicuro che mi saranno molto utili! In ogni caso far partire tutto in ram ha senso se si vuole "smanettare" su linux sapendo che al riavvio si avrà un sistema pulito e ancora funzionante. Inoltre io faccio partire tutto tramite ssd quindi in meno di un minuto parte.. E non mi devo preoccupare di corrompere l'ssd perchè viene letto e basta.. Inoltre se su debian si può cambiare il tipo di scheduler così: echo deadline >/sys/block/sda/queue/scheduler non centra con il memory manager di cui parli tu ma penso aiuti con ssd o ramdisk. In ogni caso proverò la tua guida che sembra molto più mirata grazie ancora!





Marco_admin:


Hello Tibor Áser Veres thank a lot for your guide!!! , i will add it to the main article, which version of ubuntu did you try?





Tibor Áser Veres:


Ubuntu 16.04 LTS, which outgrew my 8GB of ram, after I updated, and installed my frequently used programs... The same procedure I posted works for UbuntuMATE 17.04, And I'm working on a script that does the transformation almost automatically. I'll post it here when I'm done.





Tibor Áser Veres:


Here's a picture of that working: https://drive.google.com/file/d/0By4lbiJ8iarUT1JDVTBYT1ZPVE0/view?usp=sharing





Tibor Áser Veres:


I've promised to post the script when I'm done: https://github.com/RPBCACUEAIIBH/Volatizer Enjoy! :D





Marco_admin:


Thank you for the script Tibor Áser Veres !!! nice work! I hope that using your script even more people will try the awesome experience of ramboot linux system!





Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>