This is my current partition structure:

Filesystem            1K-blocks      Used Available Use% Mounted on
tmpfs                   127428         0    127428   0% /lib/init/rw
udev                    122976        96    122880   1% /dev
tmpfs                   127428         0    127428   0% /dev/shm
rootfs                  127428     11008    116420   9% /
/dev/sda1              1827534    933144    800029  54% /ro
rootfs.tmpfs            127428     11008    116420   9% /rw
rootfs.aufs             127428     11008    116420   9% /

I want to set up another system exactly like that, or at least close. The other disk looks like this, as shown by df:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda3               678551    594050     84501  88% /
tmpfs                   124004         0    124004   0% /lib/init/rw
udev                     10240       520      9720   6% /dev
tmpfs                   124004         4    124000   1% /dev/shm
/dev/hda1                19515     15940      3575  82% /boot
/dev/hda2               253807      7002    246805   3% /var/log_compressed
tmpfs                   124004         0    124004   0% /tmp
tmpfs                   124004      3552    120452   3% /var/log
tmpfs                   124004         0    124004   0% /var/tmp
tmpfs                   124004        20    123984   1% /var/run
tmpfs                   124004         0    124004   0% /var/lock
tmpfs                   124004         0    124004   0% /var/spool

I read a lot, but I don't know how to set this up using unoinfs or initramfs.

I will really appreciate help and explain I did read a lot and but I don't get how to do it by unoinfs or initramfs .

  • 3
    That is essentially what all LiveCDs do...
    – vonbrand
    Feb 25, 2013 at 16:00
  • @vonbrand Good point, although I can imagine a case where a system is already installed and a user wants to make it readonly. That situation is sort of what Lethe is used for, although it's certainly not as simple as using a live cd (but arguably much simpler than rolling your own live CD). Performance would probably be better on an installed system too. Feb 25, 2013 at 19:33
  • i just was clarifying by examples how look like the read only system which i got and the other system whic i want to turn to read only ... both installed on cf cards and dd command will not work cuz the difference of size . and both on small linus box with no resources any solution had live cd would be hard i tried to read that link but i couldnt get how to do it logicsupply.com/blog/2009/01/27/… ,,, if there is way to get an image from the read only system can fit 1G it will work too
    – mado saif
    Feb 26, 2013 at 14:05

3 Answers 3


I don't know witch distro you are on. On gentoo I am used to writing an own initramfs init script. Initramfs is just a tiny root fs with only essential tools installed on it to mount your root partition and switch_root to your real rootfs and execute the real init to take over.

For a ro root base system, I suggest using squashfs. It has full main line kernel support and makes your system fast. For your RAM overlay you can use tmpfs, also supported by the kernel.

Then you need to "unify" them to be as a single filesystem. I use aufs. It is not supported by main line kernel and if it is not supported in the kernel patches of your distro, you need to do the patching yourself. (There is not a single union FS supported in main line)

You are probably best of writing one yourself. (I tried dracut and genkernel, but they don't provide the neccesary modules to handle any of my cases)

  • Create a directory (I use /usr/src/initramfs)
  • Download static busybox to above directory. This is a static shell providing you al the linux_utils neccesary to fsck, mount etc.

  • mkdir /usr/src/initramfs/{bin,dev,lib,mnt,sbin,tmp,etc,proc,sys} For the base structure

  • Create a script /usr/src/initramfs/init and put all the commands in to mount your partitions, ro filesystem and rw overlay
  • Unify the ro and rw with the aufs mount syntax.
  • Don't forget to --move your mount point over to the newly created root and umount the things you don't need anymore
  • exec switch_root /sbin/init clears (deletes) everything in the loaded initramfs and switches root to continue your boot.
  • If you have any kernel modules you can't compile into the kernel, but still need (like aufs): copy them to /usr/src/initramfs/lib
  • Create an compressed archive with the contents of /usr/src/initramfs you can use gz, xz, cpio or wathever you like
  • Put the created archive in your /boot directory and edit grub to load it as initrd.

To make sure your system boots with your custom image, compile your own kernel as well. (Really it is not difficult): Gentoo kernel docs. At the point you have to install the sources, just replace the command by you package manager. Most distributions provide kernel source packages.

If you are willing to change distros to get it done, I would suggest changing to Gentoo or Arch. They are more flexible for the "manual stuff" then others and they both provide exellent documentation to hack it in any form you like.


Although it might not be a perfect solution to your main problem (creating a read-only Linux system), you could explore using Lethe. You can find an installation guide here, but the automatic translation isn't terrific and I don't have the time to post a complete translation at the moment. Sin embargo, to summarise:

1) Install the necessary dependencies:

sudo aptitude install aufs-modules-`uname-r` aufs-tools

2) Install the package from here, if a version exists for your distribution.

3) By default, Lethe freezes all partitions, but you can edit the configuration file to change that (see the setup guide I linked to)

4) Installing the package adds aufs = tmpfs to your kernel line in your GRUB menu, which boots the system into a frozen state (where all changes are discarded upon reboot). To make changes to your system, press e when you see the GRUB menu and remove this line, or remove it from within the system and update GRUB.

  • Does it still work?
    – Anwar
    Jul 2, 2019 at 11:43

This excerpt is from /etc/initramfs-tools/scripts/init-bottom/__rootaufs:

# This is a simple overview of the steps needed to use aufs on the root file system and see the /rw and /ro  branches.
# initramfs init-botton script 
# move the root file system to aufs/unionfs readonly /ro
# root is mounted on ${rootmnt}
# create tmpfs on /rw
# create a aufs using /ro and /rw
# put some files on the tmpfs to fix mtab and fstab 
# move aufs to rootmnt to finish the init process.
# No changes to the root file system are made by this script.
#  Why!
#  This will allow you to use a usb flash drive and control what is written to the drive.
#  no need to rebuild the squashfs file just to add a program. 
#  boot to single user mode.  The system works the way you expect. boot aufs=tmpfs and no changes are written to the flash.
#  run ubuntu on an eeePC .

# Install 
# Install ubuntu 8.04 Hardy. Hardy has aufs installed by default
# apt-get update
# apt-get dist-upgrade
# apt-get install aufs-tools
# echo aufs >> /etc/initramfs-tools/modules
# put this file in /etc/initramfs-tools/scripts/init-bottom/rootaufs
# chmod 0755 rootaufs
# # clean up menu.lst 
# update-grub
# update-initramfs -u
# vi /boot/grub/menu.lst
# add aufs=tmpfs to the default entry. 
# do not add this line to single user mode.
# boot to single user mode in order to install software. 
# note: if your home account is on the root file system, your files are in ram and not saved.

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.