Building a Read-Only Linux System With a Writable Layer in RAM
I have a requirement to boot RHEL 6.6/7.0 into read-only mode with a writable layer only in RAM. I believe this is similar to how live CDs work, in that the file system is read-only, but certain parts of it are writable after being loaded into RAM. Here, any changes written to the file system are lost on reboot (since only RAM is updated in the writable layer). While looking around the net, I haven’t found a guide on configuring my own «live CD» without helper tools so that I can mimic this process in an existing installed system. Does anyone know where I might be able to get some resources on either building my own live CD or making a read-only Linux with a writable layer only in RAM?
3 Answers 3
OK, so I do have a working read-only system on an SD card that allows the read/write switch to be set to read-only mode. I’m going to answer my own question, since I have a feeling I’ll be looking here again for the steps, and hopefully this will help someone else out.
While setting various directories in /etc/fstab as read-only on a Red Hat Enterprise Linux 6.6 system, I found the file /etc/sysconfig/readonly-root . This piqued my interest in what this file was used for, as well as any ancillary information regarding it. In short, this file contains a line that states, » READONLY=no «. Changing this line automatically loads most of the root file system as read-only while preserving necessary write operations on various directories (directories and files are loaded as tmpfs). The only changes I had to make were to set /home , /root , and a few other directories as writable through the /etc/rwtab.d directory and modify /etc/fstab to load the root file system as read-only (changed » defaults » to » ro » for root). Once I set » READONLY=yes » in the /etc/sysconfig/readonly-root file, and set my necessary writable directories through /etc/rwtab.d , as well as the fstab change, I was able to get the system to load read-only, but have writable directories loaded into RAM.
For more information, these are the resources that I used:
- http://www.redhat.com/archives/rhl-devel-list/2006-April/msg01045.html (specifies how to create files in the /etc/rwtab.d/ directory to load files and directories as writable)
- http://fedoraproject.org/wiki/StatelessLinux (more information on readonly-root file and stateless Linux)
- http://warewolf.github.io/blog/2013/10/12/setting-up-a-read-only-rootfs-fedora-box/
- And, of course, browsing through /etc/rc.d/rc.sysinit shows how files and folders are mounted read-only. The readonly-root file is parsed within the rc.sysinit , for those who are looking for how readonly-root is used in the init process.
Also, I did a quick verification on Red Hat Enterprise Linux 7.0, and this file is still there and works. My test environment was CentOS 6.6 and 7.0 in a virtual machine as well as RHEL 6.6 and 7.0 on a VME single-board computer.
NOTE: Once the root is read-only, no changes can be made to the root system. For example, you cannot use yum to install packages and have them persist upon reboot. Therefore, to break the read-only root, I added a grub line that removes rhgb and quiet (this is only for debugging boot issues, you can leave them if you want), and added » init=/bin/bash «. This allowed me to enter into a terminal. Once at the terminal, I typed, » mount — / -oremount,rw » to have the system writable. Once writable, I modified (using vim ) /etc/sysconfig/readonly-root to say » READONLY=no » and rebooted the system. This allows me to perform maintenance on the system by turning off read-only. If you are using an SD card like I am, then the read/write switch on the SD card needs to be set to writable.
Is there a linux OS that can be loaded entirely into RAM?
I have 32 GB of memory in my PC. This is more than enough for a linux OS. Is there an easy to use version of Linux (Ubuntu preferably) that can be booted via optical or USB disk and be run completely within RAM? I know a live disc can be booted with a hard disk, but stuff still runs off the disc and this takes a while to load. I’d like everything loaded into RAM and then run from there, completely volatile. Any files I need to create would be saved to a USB disk. I’m aware of http://en.wikipedia.org/wiki/List_of_Linux_distributions_that_run_from_RAM but these all depend on a little bit of RAM. I’d prefer something like Ubuntu instead of these light versions.
The SysRescueCd has a load to memory option, docache causes the CD-ROM to be fully loaded into memory. A slower start but once complete, programs start faster and the CD drive will be released allowing normal access to other CDs. This requires 400MB of memory to cache everything (including the bootdisks and isolinux directories).
I don’t know if Ubuntu supports it but IIRC Linux Mint does support toram parameter e.g. at the boot menu edit the entry and append toram to the kernel command line.
Ha, I was looking for a flavor «IIRC Linux Mint». Just occurred to me that was shorthand. Mint is good, I like that. It’s been a while since i’ve used puppy. I’ll have a look there too.
Not an answer, just a comment: almost any distro can be modified to run directly from ram. Only a minor difference is needed in the boot sequence to mount tmpfs (or a compressed version) and load a disk image into it. I’ve seen an (almost) standard debian system that boots from a network image and runs from RAM, and using a LAN package repository (mirror) to quickly install larger applications on demand (to save space). I didn’t set it up personally so I can’t post precise instructions, but it is something that can be done for any distro.
9 Answers 9
I think all distros can be run from RAM, you only need to do some changes. Read this link
You need to have in mind that any changes (updates, and the like) that you do to the filesystem that is in memmory are lost when you turn of your machine, so you need to stablish a mechanism to update your HD with those changes BEFORE the system goes down, that will delay the shutting down of the system.
not that much RAM is needed. if i can install and run a FULL Slackware in QEMU in tmpfs in 12GB of RAM then that much should be enough to run it direct.
i used to run just /etc in /tmps ages ago without an auto-save. one day it saved me from stupid blunder
@YoMismo, That link you posted is gold! The great thing about it is that you can customize your system anyway you want and then run it from RAM without fear of having your disks being thrashed by anything without your consent. Perhaps it would be a good idea to copy the steps here, just to be safe.
Any distro is capable, since the fundamental principles of the linux file system is not specific to any distribution. Recognize what INITRAMFS stands for, emphasis on the RAM part. Not to mention diskless nodes in a cluster setup which is nothing new.
Ubuntu can run on RAM, but it requires some manual changes:
This helps, thank you. I was hoping for something more out of the box though. If this is my only recourse, I’ll give it a go and mark this as the answer.
this appears to assume one is booting a LIVE CD where running in RAM would be very useful. i have run Slackware in QEMU with all disks in RAM and it was much faster. a FULL install finished in 3 minutes. the hardware had just 12GB of RAM. my newest laptop has 64GB and i am exploring how to boot from its SSD and run from RAM.
It’s outdated because it’s not needed anymore. Just add toram to the kernel parameters and you are done. Take note that this is not a linux kernel parameter though, but it’s specific to the ubuntu/debian live initramfs (see casper and live-boot).
Parrot Security OS. You have the option to load the OS directly into RAM, I believe MXLinux also allows that, no config files, straight from the boot loader you select load OS into RAM.
The Parrot & MX boot menu actually have a ton of options for different ways to run the OS. There are two versions ‘home’ and ‘security’, either one is suitable for a daily driver, unlike similar distros like Kali. Its basically a Debian MATE desktop and in the menu one of the tabs says parrot OS, in that tab you will find all of your hacker/cracker utils. Otherwise its just Debian MATE, a very nice looking Desktop.
Also it simplifies networking and starting/stopping processes in the applications menu. I loaded it into 10gb of ddr3 ram on a computer from 2012 and it runs fast. Also DietPi makes an X86 version that is crazy fast and runs in RAM.
If you do not care about package managers tiny core also runs in RAM its just and ‘odd’ distro.
How to get Ubuntu system to boot and run entirely in RAM?
I want to dual boot Ubuntu and have it run in RAM. I have used Puppy Linux from live USB stick which ran completely in RAM, but a lot of things didn’t work and so I decided to just go with a full system. With Puppy Linux, literally EVERYTHING was in RAM, but now that I want a full Ubuntu install, I only want the Ubuntu system (system files) and not all documents and files (like documents I create, save or download) in RAM. I’d like to get as much speed as possible from Ubuntu, and don’t need folders such as documents, downloads, etc. loaded into RAM. I am not technical enough to create a custom Ubuntu image as some have suggested. Is there a way to achieve this?
What problem are you trying to solve by having the system run entirely in RAM? Also, can you perhaps edit your question to clarify the distinction between «the Ubuntu system» and «all documents and files«? Thanks.
You want a full Ubuntu install but at the same time you want it to run from the RAM. This is technically not possible since RAM data is erased everytime you power off.. If you run a live Ubuntu disk, that is a different matter but there is actually no way to do this if you want to perform a full install. Also, as @Michael Kjörling said, it would be useful if you clarified what you mean by «All documents and files». The best thing you can do is run Ubuntu on an SSD, which is pretty fast.
I have no idea how to answer this question, but I’m struggling to believe that only the initial kernel can boot out of a ramdisk. While the ramdisk wold need to be stored on a drive somewhere, it seems like ti should be possible to boot a fully functional (albeit immutable) system that runs from a ramdisk.
Your request of «to boot and run in RAM» is not clear. The kernel (once loaded during boot) is always in RAM (except for loadable modules). Do you mean that the root filesystem should also be in RAM? The modern version of ramdisk is ramfs and tmpfs, which can be used for a RAM-resident rootfs aka initramfs. Distros publish such versions as LiveCDs.
2 Answers 2
You could run a Live Ubuntu, which can be made to boot from a USB stick or a hard disk partition, and use a persistent storage partition for your documents. Ubuntu comes with a «Startup Disk Creator» that makes this fairly easy.
This will make the documents you safe to the persistent storage partition survive a reboot, but it will reset the whole rest of your system every time you reboot. So, you can’t install updates or new programs and have them survive a reboot.
This strikes me as extremely cumbersome.
However, if that’s the way you want to go, you can also customize such a live system, but you’ll have to know quite a lot about how Ubuntu works, how it boots, how initial ram drives work etc. Ubuntu has a help page about customizing it’s Live environment (see https://help.ubuntu.com/community/LiveCDCustomization). I did this a few years ago for a group of students and even though it worked nicely, I decided it was too much work to repeat the experiment.
It would be interesting to know why you need such a strange setup.
If you’re worried about the speed of running a linux system from a hard drive, don’t be. Nowadays you can even run Linux over a local network link and never notice your not working on your own machine. You can even run GUI applications over an internet connection (though there the lag is noticeable).
There are a few alternatives you might consider if you’re asking out of privacy needs:
A standard Ubuntu Installation comes with a «Guest User» functionality that keeps a guest’s home folder in memory, so whenever you log in as a guest user, once you reboot, all the changes he made are lost.
You can encrypt either your home directory or your whole system partition. In fact, you could set it up so your system boots from an USB drive you keep on your keychain and keeps its root file system encrypted on your hard drive.