I want to find a cross-distro solution for setting linux up to boot from RAM. What this involves in essence would be copying an existing installation of linux one way or another over to the RAM (to ramfs or tmpfs; that would be user preference, although I prefer ramfs, because after doing some minimal benchmarking it seemed to me to be quicker than tmpfs), then booting off the RAM as if it were a normal disk. This naturally has to happen while the bootloader is starting the system up (before or after loading the kernel from /boot).

The second part would involve periodically (say once per hour perhaps) and on shutdown, saving the data from the RAM to the disk, so that system changes won't be lost upon restart due to the volatile nature of modern RAM.

The ideal bootloader to do this from would be Grub2 and the way I envisioned this happening is thus:

First, prepare the system (copy the system to a different folder/hard drive), make all the symlinks for the directories you do not want on the ramdrive (like /boot and /usr/share/man (and on arch, /var/cache/pacman)), then edit the fstab appropriately for this boot setup, after that compress this modified version of the system into an image file (.iso or .img or similar) or into an archive (tar.gz2, lzma, bz2...) and then on boot, load the contents of that image/archive onto a ramfs/tmpfs (and then on shutdown, backup(rename) the image/archive that was booted from, then compress the contents of the ramfs to an image/archive to replace the old one.)

I imagine it shouldn't be very hard to achieve this, if one knows how, and of course, I'm open to alternative approaches than the approach I described, if it gets the job done.

I need to know what system files would need to be altered for this to work (the only one I am aware of is fstab), how to make the iso/img or archive, how to load it onto a ramdrive at boot time, and how to finally boot from it.

(Note: For those unaware of why I would want to do this, it is for the speed benefit. Any file loaded onto the RAM will load/execute almost instantly. It is many times over faster than any SSD, but of course comes at the price that you need to have enough RAM to spare to contain your system on it)

  • 1
    You've described most of it. I think the missing link is using an initramfs to uncompress the image. Or likely you could just use an initramfs for the whole thing (it pretty much is what you want), I do not think they are limited in terms of scope nor do they have to hand off to anything (I could be wrong). Getting it to save state at shutdown (no matter how you do this) is probably going to be an awkward task, however... – goldilocks Feb 24 '15 at 11:55
  • 1
    You have a step-by-step guide in the next link: reboot.pro/topic/… – YoMismo Feb 24 '15 at 12:20
  • 1
    Puppy Linux does this sort of thing, using squashfs and aufs. See the somewhat out of date How Puppy Works for a general overview. – PM 2Ring Feb 24 '15 at 13:57
  • 1
    tinycore also does it. – Cestarian Feb 24 '15 at 16:38
  • 1
    To decompress initrd you can gzip -dc initrd|cpio -id to compress once you have modified it go to the directory where you decompressed initrd and execute find . |cpio -H newc -o > YourNewinitrd;gzip YourNewinitrd;mv YourNewinitrd.gz YourNewinitrd you have the guide to do it in the next link openvz.org/Modifying_initrd_image – YoMismo Feb 25 '15 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.