In part one we created a bare minimum custom installation of the Ubuntu Server software on a USB stick, now we will set up the stick such that depending on the boot option chosen, the entire system will either be read only but live, or read/write like normal.

Sometimes you need to carry a reliable Linux system around with you but don’t want to (or can’t) use those LiveCDs, or you don’t need a graphical desktop, or you need to ensure that whatever you do while the stick is running doesn’t impact the drive itself or alter anything. These installations can be used for working on clients computers to clean or detect a virus infection on any operating system, to copy or backup files, to check the health of a hard drive or the hardware itself using commonly available tools like memtest86 or smartmontools, or repair an installation of Linux or Windows. With this setup, changes take place in ram due to the magic of aufs.

This part is much more simple than creating the USB stick was in part one, there are only a few steps and a script to copy into the right place on the system.

First lets copy the script to your system, it is available here: http://tech.xerces.com/files/rootaufs

Put that file in /etc/initramfs-tools/scripts/init-bottom/

Now fix the permissions on that file:

root@live:/# sudo chmod 0755 /etc/initramfs-tools/scripts/init-bottom/rootaufs

Then we tell initramfs-tools to include the right kernel module for aufs:

root@live:/# sudo echo aufs >> /etc/initramfs-tools/modules

Now update the initramfs:

root@live:/# sudo update-initramfs -u

This processes the changes we just made such that this script is now included in the initramfs along with the right kernel modules needed for read-only operation.

Now we alter the grub default options with nano or another editor to create the 2 separate boot modes. Use sudo so you have correct permissions to edit the file.

Find this in /boot/grub/menu.lst:

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

And make the defoptions line look like this:

# defoptions=quiet splash aufs=tmpfs

Now change this section:

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(recovery mode) single

So it looks like this:

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(writable mode) quiet splash
# altoptions=(recovery mode) single

I found that the update-grub script didn’t like having 2 altoptions line so i removed the recovery mode from mine, so if your system doesn’t boot and give you these options try that.

Now we update grub:

sudo update-grub

When the system boots it will default to read only mode, if you need to update the system reboot in readwrite mode. You may need to hit esc during boot to see the menu. Comments are welcome :)