Page 1 of 1

Boot rapberry on ram

Posted: Sun Dec 22, 2013 11:12 am
by marco_righe
Hello to everyone .
I have a question and i can't find the answer on internet.
How can i boot the rasberry with raspbian on ram?
I want to make a home automation system but i need to prevent the corruption of the sd filesystem from every problem may occours (but i need also to write the sd in order to update the software from internet)
So i think a good method , better than read only sd, would be copy the sd to the ram and after that boot from it.
I made the same thing with my pc and debian , the system improvement is great.
Someone know how to do what i ask?
I tried to modify the cmdline.txt but without results (did not boot).
I strip down raspbian to 280 MB then i tried this on cmdline.txt:

mkdir /mnt
mkdir /mnt/p1
mkdir /mnt/ram
mount -t ext3 /dev/mmcblk0p3 /mnt/p1
mount -t tmpfs -o size=100% tmpfs /mnt/ram
cp -rfa /mnt1/p1/* /mnt/ram/
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/mnt/ram/ rootfstype=tmpfs rootwait

After that i read that cmdline.txt must be one single line.
Please someone could help me?

Re: Boot rapberry from on ram

Posted: Sun Dec 22, 2013 4:41 pm
by rickseiden
I think that there is not going to be enough RAM for you to pull off what you're talking about. The RPi, Model B, Revision 2 only has 512megs of RAM. Probably a better idea is to get an external USB hard drive of some sort, and configure the SD card to point to that as the /root device. You have to boot from the SD card, but once you do that, you can specify any drive the system has access to as the /root drive.

Re: Boot rapberry on ram

Posted: Sun Dec 22, 2013 4:46 pm
by marco_righe
Thank you for the idea but i want to boot on ram to make the things the more stable possible , adding an usb disk will add other hardware and it will corrupt if i turn off an on like an arduino the rasberry.
If i could make the os more small i think it will be fine to run in ram.
But how can i run it in ram?
If some one knows how , please let me know.

Re: Boot rapberry on ram

Posted: Sun Dec 22, 2013 5:21 pm
by danjperron
Hi marco_righe ,

You don't need to put everything on ram.

I do have my Pond temperature controller with the SD card.

The trick I do is to minimize the write access on it. So /var/log is on ramdisk and any application I use store file in a temporary folder in ram.

This way I could power off the SD card and reboot multiple time without problems.

I add in the /etc/fstab the folder /var/log in "tmpfs" ramdisk and also some temporary folder which will be in tmpfs format.

Code: Select all

[email protected]:~# cat /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
tmpfs           /tmp		tmpfs   defaults,noatime,mode=1777 0    0
tmpfs		/var/log	tmpfs	defaults,noatime,mode=0755 0    0
#tmpfs           /var/lock	tmpfs   defaults,noatime,mode=0755 0    0
tmpfs           /var/www/chart/data tmpfs defaults,noatime,mode=0755,uid=www-data,gid=www-data 0 0
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
[email protected]:~# 
This is on a model B version 1 (only 256MB of ram) and it is still working since november 2012. I just upgrade the SD card this summer and I never had to re-flashing it. I got black-out, camera hang (-25Celsius) or wifi lost. The only thing I had to do was to kill the breaker and put power again.

I create a script to prepare the ramdisk mostly for lighttpd log file,

Code: Select all

[email protected]:~# cat /etc/init.d/prepare-dirs
# Provides:          prepare-dirs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Required-Start:  
# Required-Stop:   
# Short-Description: Create /var/log/lighttpd directory on tmpfs at startup
# Description:       Create /var/log/lighttpd directory on tmpfs at startup


# main()
case "${1:-''}" in
    # create the /var/log/lighttpd needed by webserver
    if [ ! -d ${DIR} ]; then
      mkdir ${DIR}
      chmod 755 ${DIR}
      chown www-data:www-data ${DIR}
   echo "Usage: $SELF start"
   exit 1
[email protected]:~# 

and register the script into the boot process

Code: Select all

update-rc.d prepare-dirs defaults 01 99
So just add what you need in the ramdisk folder using that script at startup and you are all set. Just verify that you don't write on the SD card. You could also remount the card to be read-only if you want.


Re: Boot rapberry on ram

Posted: Sun Dec 22, 2013 7:42 pm
by marco_righe
Thank you very much Danjperron i will use your guide ,it's very usefull.
But could you remove the sd while the system is running ? I need this kind of security...

Re: Boot rapberry on ram

Posted: Sun Dec 22, 2013 11:38 pm
by danjperron
No !

The system is using the SD card but mostly in read mode only. This way it is hard to have it corrupt.

I know that I'm doing it for some I386 system. I just prevent the system to mount root on CF card and let root "/" be a ramdisk.

This way the CF card is always on Read only mode. When I need to change something, I just remount it to Read/write access.

The Raspberry PI use SD card instead of Compact flash but it should be possible to do the same. I never look at it.

But why you want to remove it. How to you reboot ! You will have to re-install the SD card. That is not a good idea.

The better approach will be to look at some kind of net booting. Having the minimum on the SD card and load the necessary stuff from the ethernet.


Re: Boot rapberry on ram

Posted: Sun Dec 22, 2013 11:48 pm
by marco_righe
I just want know if i can remove and insert again the sd while the raspberry continues to run , and know if it will have problem or not doing so.
I will always shut down the raspberry removing the power so i need to make sure i can turn of and on how many times i want without problems.
If i could mount all the system on ram this will not be a problem.

Re: Boot rapberry on ram

Posted: Mon Dec 23, 2013 2:24 am
by danjperron
In /boot/cmdline.txt

The startup linux is set to use the SD card root=/dev/mmcblk0p2

But nothing protect you to create a ramdisk image. An "initrd.img" zip disk image instead. Maybe you will need to recompile the linux kernel to have ramdisk at startup. For this you will need a good knowledge of how to build a linux system.

There is some minimal linux version for the raspberry pi. ... mal-image/


Re: Boot rapberry on ram

Posted: Thu Mar 02, 2017 2:12 am
by paulwratt
Old topic yes, but still relevant

This can now be done in several ways:
piCore - TinyCore Linux for Raspberry Pi (you can remove SD card after boot)
dev/boot - a one time setting can be made to Pi3 (& Pi2 ?) allowing boot from: USB,NET

1. de/boot can only be set once, and only available on Pi3 (& Pi2 ?)
2. piCore will work on any Pi
3. in /boot/cmdline.txt, if you set root=/dev/sda1 on any SD card, it will boot from the 1st USB disk

if you have NFS (or another network shared drive - which is usuall faster than SD card access) you can set up Swap over nfs

There are (now) also alternatives to piCore, that use BusyBox loaded on a ram disk, that also allow SD card removal after boot. One alternative is SliTaz Pi.



Re: Boot rapberry on ram

Posted: Thu Mar 02, 2017 2:48 am
by Gavinmc42
piCore works great, been using it for years.
These days for faster booting I use Ultibo.
I remove SD card after boot and then can put new kernel file on it and reset/reboot

Re: Boot rapberry on ram

Posted: Thu Mar 02, 2017 8:15 am
by paulwratt
after reading the documentation of TinyCore, it appears that dCore (which uses Debian & Ubuto repos plus PPA's) is possible to run ontop of either piCore or the boot parts of piCore, however (maybe due to repo habits and lack of active devlopment) the current ARMv7 dCore is based on Wheezy, more dated than the current piCore v8 stable or v9 testing.

I like the idea of Ultibo
Ultibo core, a bare metal development environment for Raspberry Pi (all models)
Announcing Ultibo core


Re: Boot rapberry on ram

Posted: Thu Jun 27, 2019 8:34 am
by ako
I guess, with the arrival of the 4GB Pi4, it's time to bring this topic back up!

Re: Boot rapberry on ram

Posted: Wed Aug 07, 2019 1:29 pm
by SpikoPath
ako wrote:
Thu Jun 27, 2019 8:34 am
I guess, with the arrival of the 4GB Pi4, it's time to bring this topic back up!
Agreed! :D

Load OS into RAM, read/write speed increase.
Any Changes to RAM written back to SD Card or another boot device on shutdown/reboot.

The only snag is if the pi loses power or crashes, all data will be lost. Oh, and Boot/shutdown/reboot times will be slower.

Re: Boot rapberry on ram

Posted: Wed Aug 14, 2019 5:16 am
by Gavinmc42
What will boot times be like when USB3 booting is working?
The ram is much faster now on the Pi4, running the OS from there will be interesting.

Might be time to look at an UPS as well.
How much faster could those big compiles be?
Linux kernels, Buildroot, GCC etc.
I did a big 13hr compile of the complete RISC-V toolset on a 3B+.

How much faster will that be on an optimised Pi4B setup?
How much ram based swap can be used?
Need a Pi4B4, I only have 1GB and 2GB Pi4's.
What is the best config for each Pi4 version?