Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 .

share|improve this question
That is essentially what all LiveCDs do... –  vonbrand Feb 25 '13 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. –  Ricardo Altamirano Feb 25 '13 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 '13 at 14:05

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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