
Ramroot – Run Arch Linux Entirely from RAM (2017) - e18r
https://www.ostechnix.com/ramroot-run-arch-linux-entirely-ram/
======
puppetmaster
Many OS out there take advantage of RAM Disks. Alpine Linux for instance
allows you to boot your root device on ram as a default. SmartOS runs a boot
image completely on RAM, and keeps your storage free for a few configs and
VMS.

Virtually all network booted computers run their OSs from RAM. If you have
never pxe booted a machine, it is a beautiful experience once you overcome a
few challenges: easy upgrades and rollbacks, being able to use a machine with
different contexts/platforms by just rebooting, and having your servers
cleaned up just by cycling (assuming you don't have local storage)

If you enjoy the idea of RAM root devices, please try pxe/ipxe to boot your
computer from a network. Also, if you have a sufficiently fast network... it
is probably faster than booting from disk!

EDIT: I missed the word "all" on the second paragraph, and another typo...
sorry!

~~~
jandrese
Sadly PXE boot of a modern Linux OS is easier said than done. Gone are the
days of just handing out the kernel over tftp and providing a NFS root.
SystemD gets super cranky and you can't even boot the thing without setting
some undocumented flags.

~~~
gmueckl
How did the systemd cabal manage to mess that up? I ditched that thing a while
ago for good reasons, so I don't keep track anymore.

~~~
jandrese
I'm not entirely sure of everything, but problems with UUIDs (which we
expected), and some dbus signals not being generated when run over a NFS
mounted root causing the boot to hang. We hacked some timeouts to get around
the problem but never figured out exactly where the signals were supposed to
be generated from.

A hint if you're doing this on Linux. We PXEBoot an iPXE loader to boot the
machines. Doesn't work properly on UEFI unfortunately, gotta use BIOS boot.

If it helps, I have notes on how to set that up:

Go to [http://rom-o-matic.net](http://rom-o-matic.net) and choose gPXE git.
Click on the "Customize" button to expand all of the options.

Choose: 1\. PXE bootstrap loader image [Unload PXE stack] (.pxe)

2\. all-drivers

3\. PCI VENDOR CODE: [blank] PCI DEVICE CODE: [blank]

X CONSOLE_PCBIOS

_ CONSOLE_SERIAL

BANNER_TIMEOUT [20]

_ NET_PROTO_IPV6

(Serial Port Options are irrelevant)

X DOWNLOAD_PROTO_TFTP

X DOWNLOAD_PROTO_HTTP

_ DOWNLOAD_PROTO_HTTPS

_ DOWNLOAD_PROTO_FTP

_ SANBOOT_PROTO_ISCSI

_ SANBOOT_PROTO_AOE

X DNS_RESOLVER

X IMAGE_ELF

X IMAGE_NBI

X IMAGE_MULTIBOOT

X IMAGE_PXE

X IMAGE_SCRIPT

X IMAGE_BZIMAGE

X IMAGE_COMBOOT

X AUTOBOOT_CMD

X NVO_CMD

X CONFIG_CMD

X IFMGMT_CMD

X IWMGMT_CMD

X ROUTE_CMD

X IMAGE_CMD

X DHCP_CMD

_ SANBOOT_CMD

X LOGIN_CMD

_ TIME_CMD

_ DIGEST_CMD

X PXE_CMD

_ IPV6_CMD

_ CRYPTO_80211_WEP

_ CRYPTO_80211_WPA

_ CRYPTO_80211_WPA2

Embedded Script:

\-----------------------------------------------------------------------------

#!gpxe

dhcp any

initrd
[http://<your_server_here>/initrd.img](http://<your_server_here>/initrd.img)

kernel
[http://<your_server_here>/pxelinux.0](http://<your_server_here>/pxelinux.0)

imgargs pxelinux.0 root=/dev/nfs rw boot=nfs
nfsroot=<your_nfs_server_here>:/netroot root ip=dhcp nfsrootdebug

boot pxelinux.0

\-----------------------------------------------------------------------------

------
codezero
I built something like this back in 2002 when I was at Red Hat for a client
that wanted to have their firewalls to have read-only configurations on a
diskless system. They would update the rules/config/system by burning a new CD
and booting it up.

It worked basically how a Live CD worked - creating a temporary filesystem in
ram, and I only learned later that they already existed (I didn't know at the
time and the Internet wasn't as good at finding things as it is today :) )

------
cjbprime
I wonder whether this achieves anything performance-wise that just cat'ing
every file to /dev/null to warm up the buffer cache wouldn't achieve.

In theory, the kernel uses a buffer cache that will hold on to disk pages
until they're invalidated by writes. It'll evict the cache if there's memory
pressure. But this setup will presumably just crash if there's memory
pressure, so that doesn't seem like a win for the RAM disk.

~~~
jerf
I can't hard-core prove anything, but I've read the theory on how if I'm
accessing warm disk cache, putting things into a RAM disk shouldn't speed them
up, and every time I've done it and tested it, putting things in a RAM disk is
faster than having it on disk, even when the very act of copying the stuff
into RAM should definitely have just warmed everything up just before the
test. I've not done it very often, but every time I've tried it in the last
~15 years it's been the case. I don't know exactly why. I don't think I've
done this test with my NVMe disk, though. Nominally, since the entire point of
this exercise is that we never physically touch the drive it shouldn't matter
what sort of drive it is we aren't touching, but reality and theory can
differ.

~~~
cjbprime
Interesting! Did you make sure there aren't any writes happening in the warm
disk cache case, even for things like atime?

~~~
jerf
Not in the rigidly scientific sense, but on a Linux system where you are the
only user and nothing else "major" is happening, there isn't that much writing
of any kind going on.

------
iguessthislldo
This is neat, but nothing new. I remember using this builtin feature on live
distros like Slax and DSL over a decade ago. It was fun to see old computers
run (comparably) blazingly fast.

~~~
Spivak
The new thing is that it can be just be switched on/off on an existing
install.

Sure people have been running distros from ram for a while but getting the
tooling situated to make it like any other feature it super cool.

~~~
vanderZwan
> _The new thing is that it can be just be switched on /off on an existing
> install._

Is that only true for Arch, or is that also working on other distros?

------
manelmt
Alternatively, one could use NBD (network block devices) to create a network
block device that resides entirely on a server's RAM.

The nice thing about NBD is that its a super simple protocol, the server runs
in user space, and it's easy to modify to suit own needs. I built sometime ago
a version with block deduplication for a farm of disk-less clusters that had
very little ram in ~1k LOC. Main disk had persistence activated, while swap
drives were pure RAM.

------
VictorSCushman
It's worth mentioning Tiny Core Linux[1] which runs entirely from RAM as well!
It's a wonderful little destro with a small footprint. I boot TCL off of a
USB, load it entirely into RAM, and am able to use it as my daily driver.

[1]: tinycorelinux.net

~~~
yellowapple
I always keep TCL around as an emergency boot environment, Just In Case™.

------
arcmags
Author here. Awesome to see some interest in my project.

I'm currently working on the next version in my spare time (you'll see it in
the dev branch). Improvements include: configuration now done via
/etc/ramroot.conf, ability to specify actions taken for other partitions,
ability to copy files to any location only when booting from RAM (allowing
custom configs and whatnot to be used when in the live environment), new
install hook that includes binaries and modules rather than adding them to
/etc/mkinitcpio.conf, sudo will no longer be a required package, custom memory
requirement settings, and more...

Also, I have gotten this to work on Debian, Ubuntu, and Kali with minor
modifications. I plan to include a makefile for installing to these distros
but don't plan on packaging for them at this time.

[https://github.com/arcmags/ramroot](https://github.com/arcmags/ramroot)

------
adolph
Once upon a time I did this using Mac OS 6 on a PowerBook 100. The 100 had
pseudostatic RAM so the RAM disk would persist between shutdowns. Using OS6
left enough space on the disk to also run an old-for-the-time version of Word,
a perfect silent student writing machine.

Some info about it here:

[http://www.pugo.org/collection/faq/21/](http://www.pugo.org/collection/faq/21/)

------
equalunique
Surprised no one here has mentioned mfsBSD. It's an unofficial FreeBSD answer
to this problem. Works very well for some maintenance tasks, like ensuring a
new install's disks are clear of partitions/zpools. I have even booted it's
ISO via IPMI over the internet with OpenVPN.

[https://mfsbsd.vx.sk/](https://mfsbsd.vx.sk/)

~~~
jlgaddis
Nowadays, there's "mfslinux" [0] (based on OpenWRT) as well (also by Martin).

[0]:
[https://github.com/mmatuska/mfslinux](https://github.com/mmatuska/mfslinux)

~~~
equalunique
Thank you. Wasn't aware of this. Will certainly try it out.

------
nathanasmith
I'm on mobile so I'll keep this short but I found this[0] a long time ago and
it still seems to work. It uses strace, mmap, and mlock to load any program
you want and it's libraries, etc. into RAM but only those programs so if
you're short on memory, no problem. During the setup, you can even mouse
around in the program and preload anything involved in that. Back in the day I
used it on really slow stuff like OpenOffice, Firefox, GIMP, etc. and it sped
the opening of those programs significantly. The great thing, again, is you
set it to preload only the specific things you need into RAM and nothing you
don't. And, once done, it's pretty much set and forget.

[0][https://forums.gentoo.org/viewtopic-t-622085-start-0.html](https://forums.gentoo.org/viewtopic-t-622085-start-0.html)

------
ryanmjacobs
I run Arch Linux and I'm really excited to try this out tonight. I always make
huge /tmp ramdisks (50 GB+) and run everything in there that's filesystem
intensive. It's so much faster. This could be perfect for easy, stateless Arch
Linux servers.

------
benj111
"Please note that this prompt (y/N) defaults to yes with a 15 second timeout
if 4G or more of RAM is detected"

I understood the capitalisation to indicate the default. Or does the default
change? That seems bad if you're intending to wrap this in a script.

~~~
jlgaddis
The author's demo/test machine only had 2 GB of RAM so perhaps it defaulted to
"N" for that reason.

------
v8engine
[https://en.wikipedia.org/wiki/List_of_Linux_distributions_th...](https://en.wikipedia.org/wiki/List_of_Linux_distributions_that_run_from_RAM)

I came to know about this from Puppy Linux.

------
calebm
In college, I would use computer lab computers as a proxy for my...
experiments. I would just load up a small Linux distro from a CD into ram.
That way, I could just reboot the computer when done, and it would reboot into
Windows.

------
LinuxBender
I would love to see this feature added to CentOS/RHEL. In the past, we used
NFS Diskless which is anything but diskless. Hacking together an initrd that
loads everything into ram is, well, hacky. To have a dracut function or a
toggle to enable this would be great for lightweight deployments, testing,
labs, vagrant, etc... I'm sure that RHEL must have been contemplating it
because there is /etc/sysconfig/readonly-root unless that was just a better
way to do NFS diskless...

~~~
jabl
We use warewulf (via openhpc) for diskless centos 7 compute nodes at work.
Basically initramfs creates a tmpfs, downloads the OS image to it, switches
root to it.

~~~
LinuxBender
Oh nice, I thought it was also using NFS diskless. I will take a look at it.
Thankyou!

------
bfgpereira
This is nothing new, or exciting. Most Linux distros will do this either via
PXE, with NFS root, or rsync a rootfs to RAM and then boot, etc etc etc. There
are literally so many ways of doing this, it would take me eons to stop the
creativity kill.

What do so something cool? Boot a whole computer cluster using BitTorrent as a
backend, diskless, diskfull, at lightning speeds:
[https://github.com/dchirikov/luna](https://github.com/dchirikov/luna)

------
wil421
I believe FreeNAS does something like this during startup. You can “install”
it on mirrored USB drives in case you run out of power. The redundant USBs are
used to install the OS back into RAM. An extra USB in case of corruption and
they’re way cheaper than SSDs. I’m assuming you still need to write config
files back to the USB.

FreeNAS prefers ZFS so it’s RAM hungry anyway. The article recommend 500mb
more than you need.

Can you do this to an Arch VM?

~~~
imtringued
SSDs cost 26€ for 128GB and offer significantly more performance and
reliability. USB drives are not significantly cheaper.

~~~
wayoutthere
USB thumbdrives _are_ far more portable than NVMe or PCIe SSDs though.
Performance doesn’t matter too much in this type of setup; once the OS is
loaded into RAM it shouldn’t hit the thumb drive again.

------
pknopf
Darch does this as well: [https://godarch.com/](https://godarch.com/)

However, you can use Ubuntu/Debian/Void as well.

Here are my personal recipes: [https://github.com/pauldotknopf/darch-
recipes](https://github.com/pauldotknopf/darch-recipes)

PS: I'm the author of Darch.

------
lordleft
Out of curiosity, does data persist after a shutdown when an OS runs on RAM?
Are there dumps to a HDD?

~~~
monocasa
Nope.

The piratebay used to run their servers like this. They'd boot off of a USB
stick, pivot root to a ram disk, and then unmount the USB stick. Then when the
cops would seize the machines and cut power to save as much evidence as they
could, they'd actually be doing the opposite.

~~~
hnarn
> Then when the cops would seize the machines and cut power to save as much
> evidence as they could, they'd actually be doing the opposite.

Let's for a second assume that forensic computer technicians aren't completely
incompetent and actually understand that you do _not_ pull the plug on a
system that potentially contains evidence the first thing you do.

While this has been known to happen in the past, I can almost guarantee it's
because of "helpful" police officers, much in the same way the job of any
forensic technician can be ruined by good intentions of those who don't know
better.

~~~
monocasa
Lol, forensic technicians are pretty incompetent overall. Like I remember a
peer reviewed article on PS3 forensics where they explicitly have a section on
trying to run a PS3 disk image in VMWare and didn't understand why they
couldn't get it to work.

And this piratebay mitigation was in the early 2000s. At that point most of
the anti forensic mitigations were booby traps on input channels (keyboard,
console, etc) and maybe a tilt sensor that'd wipe the drive if anyone tried to
access it. Under that scheme, pulling power before inspection is what you want
to do.

~~~
hnarn
> Under that scheme, pulling power before inspection is what you want to do.

Why? Are you saying there were no measures to make data inaccessible in case
of power failure?

------
mlurp
Does TAILS not do this? Forgive my ignorance, I only know the basic idea of
it.

~~~
mikepurvis
Most live distros do this— rather than have an initramfs that finds and mounts
the removable media, they just put everything in the initramfs itself.

What's new here is being able to optionally and seamlessly copy the regular
disk install into RAM on boot.

~~~
lallysingh
What do you mean by "flip to an existing install?"

~~~
wyldfire
I think the mechanism is that it's installed in a normal persistent fashion,
but per-boot you can opt-in to loading the current install into memory.

------
mehrdadn
Can you use this to repartition your disk?

------
igou
I remember this feature on Xubuntu circa 2009. Not sure why this is
noteworthy.

------
WC3w6pXxgGd
Why would this be useful?

~~~
LinuxBender
Many reasons, but the ones that come to mind are:

\- Testing - quickly deploy a version of an OS and software to a fleet, then
reboot into a pristine state or new state.

\- Lab cost reduction. No hard drives in most of the fleet. Less power used.

\- Consistent version across many test servers. People change things, reboot
or power cycle and you are back into the same state.

I've used something like this in production before using NFS diskless. That
was a bit messy. For labs, testing, it is great.

------
swiley
A lot of modern laptops come with 32 GB of ram on the lower end. With
something like syncthing you only need permanent storage as a cache.

~~~
grosswait
Time traveler from the future brags about lower end laptops!

~~~
AnIdiotOnTheNet
And I'll bet his system still takes 3 whole seconds to launch a word
processor.

