7

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?

9

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:

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.

3

Yes, this is like what a Live CD does. It's done using a special filesystem driver that's designed to overlay multiple filesystems on top of one another - in this case, a read-only file system with a RAM disk.

There are lots of different choices of overlay filesystems - try searching around for UnionFS, aufs, and overlayfs to get an idea of what your choices are, and what the tradeoffs between them might be.

  • 1
    Thanks for your suggestion. I have already looked around at some of the union file systems, but have found that almost all of them are not available in RHEL 6/7. I'm interested in developing a technical understanding of how Fedora Live CDs are created since UnionFS, AuFS, and etc, are not part of the kernel or installation packages. These file systems require a patch to work. But, something must exist for the Fedora Live CD to operate, since anyone can download and use one. So, I'm looking for how the Live CDs on Fedora/CentOS/RHEL/Red Hat derivatives work and ensure my system loads ro. – Kinetic Arc Jan 29 '15 at 3:50
  • @KineticArc, bugzilla.redhat.com/show_bug.cgi?id=465725 seems to indicate that RHEL does it with something called "LVM snapshot overlays" - that might be the direction to look in. Though, that defect seems to also indicate that they're a technically worse solution than union filesystems. – godlygeek Jan 30 '15 at 21:00
1

To follow-up to the answer provided by Kinetic Arc, the easier way to modify the system on subsequent reboots is to add "noreadonly" to the kernel command line. If this isn't something you expect to do very often, then just catching grub and adding it manually is probably sufficient. When developing our read-only systems, we added an entry into grub.conf with that added and increased the timeout slightly. Once development of the system image is complete, we then take the entry out before distributing the image.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.