[Voyage-linux] aufs and unionfs

n schembr (spam-protected)
Sun Feb 24 11:18:22 HKT 2008




	
	
	
	
	<!--
		@page { size: 8.5in 11in; margin: 0.79in }
		P { margin-bottom: 0.08in }
	-->
	

Is there a reason that voyage is not
using unionfs or aufs for the root file system?




I this is my pre-test how to use aufs
to create a voyage like read only root file system. 






background





I've used Voyage Linux on a few
machines for the last three years without issue. The voyage is small
and easy to use.  Voyage is the best embedded router/firewall I have
used.





Great job guys!





I just purchased an eee pc to play
with.  I want to replace the desktop with ubuntu or debian.  The eee 
mailing lists and howto are remastering a live cd or just set noatime
and moving a few files to tmpfs. I have loved the ease of use voyage
offers,  remountrw  and update.   






I could not find a good example of
unionfs or aufs on a root file system.





I found small diskless howto that used
unionfs to mount a tmpfs rw and nfs mounted file system ro. 






After a small post to I ubuntu irc I
found an example of using update-initramfs.





The Setup.





I'm using vmware to test. 






Install eeeXubuntu 7.10 on a vm using
the defaults.

change /etc/apt/sources.list from gutsy
to hardy.

apt-get update 


apt-get dist-upgrade





echo aufs
>>/etc/initramfs-tools/modules





touch
/etc/initramfs-tools/script/init-bottom/rootaufs

chmod 0755
/etc/initramfs-tools/script/init-bottom/rootaufs





cat <<EOF
>>/etc/initramfs-tools/script/init-bottom/rootaufs 


#! /bin/sh

#  Copyright 2008 Nicholas A. Schembri
State College PA USA

#

#   This program is free software: you
can redistribute it and/or modify

#   it under the terms of the GNU
General Public License as published by

#   the Free Software Foundation,
either version 3 of the License, or

#   (at your option) any later version.

#

#   This program is distributed in the
hope that it will be useful,

#   but WITHOUT ANY WARRANTY; without
even the implied warranty of

#   MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the

#   GNU General Public License for more
details.

#

#    You should have received a copy of
the GNU General Public License

#    along with this program.  If not,
see

#    <http://www.gnu.org/licenses/>.









case $1 in

prereqs)

        exit 0

        ;;

esac





export aufs





for x in $(cat /proc/cmdline); do

        case $x in

        aufs=*)

                aufs=${x#aufs=}

                ;;

        esac

done





if [ "$aufs" != "tmpfs"
]; then

        #not set in boot loader

        #I'm not loved. good bye

        echo    To activate read only
live file system add  aufs=tmpfs

        echo    to your bootloader
command line.

        exit 0

fi

#

# initramfs init-botton script

# move the root file system to unionfs
readonly





# the root file system has just been
mounted rw or ro by the stock init script

# root is mounted on ${rootmnt}

# create a unionfs and move rootmnt to
it

# move aufs to rootmnt to finish the
init process.









echo

echo            aufs setup on
${rootmnt}

echo





modprobe -Qb aufs

if [ $? -ne 0 ]; then

        echo    root-aufs error:       
  Failed to load aufs.ko

        exit 0

fi





#make the mount points for on the init
root file system

mkdir /aufs

mkdir /rw

mkdir /ro









# mount the temp file system and move
real root out of the way

mount -t tmpfs aufs-tmpfs /rw

mount --move ${rootmnt} /ro

if [ $? -ne 0 ]; then

        echo    root-aufs error:       
 ${rootmnt}  failed to move to /ro

fi





mount -t aufs -o dirs=/rw:/ro=ro aufs
/aufs

if [ $? -ne 0 ]; then

        echo    root-aufs error:       
  Failed to mount /aufs files system





fi









#test for mount points on real file
system

[  -d /ro/ro ] || mkdir /ro/ro

[  -d /ro/rw ] || mkdir /ro/rw





mount --move /ro /aufs/ro

if [ $? -ne 0 ]; then

        echo    root-aufs error:       
  Failed to move /ro /aufs/ro





fi

mount --move /rw /aufs/rw

if [ $? -ne 0 ]; then

        echo    root-aufs error:       
  Failed to move /rw /aufs/rw





fi





# fix fstab

#ROOTTYPE=$(/lib/udev/vol_id -t
${ROOT})

ROOTTYPE=$(cat /proc/mounts|grep
${ROOT}|cut -d' ' -f3)

ROOTOPTIONS=$(cat /proc/mounts|grep
${ROOT}|cut -d' ' -f4)

echo ${ROOT} /ro $ROOTTYPE $ROOTOPTIONS
0 0 >>/aufs/etc/fstab





echo aufs-tmpfs /rw tmpfs rw 0 0
>>/aufs/etc/fstab

# S22mount on debian systems is not
mounting  /ro correctly after boot

# add to rc.local to correct what you
see from df

#replace last case of exit with #exit

cat /aufs/ro/etc/rc.local|sed
's/\(.*\)exit/\1\#exit/' >/aufs/etc/rc.local

echo mount -f /ro >>/aufs/etc/rc.local

echo exit 0 >>/aufs/etc/rc.local









#build remountrw

echo \#!/bin/sh >/aufs/bin/remountrw

echo mount -o remount,rw ${ROOT}
>>/aufs/bin/remountrw

chmod 0700 /aufs/bin/remountrw





if [ "$debug" != "aufs"
]; then

         mount --move /aufs /root

fi





exit 0

EOF









update-initramfs -u





The system should boot without error. 
I'm going to write the howto in the AM.




note:  aufs was a 10 minute port and has worked as
advertised. Unionfs hung when the root file
system was in a read only state. I'm sure this could be corrected
with a simple patch.  

 








More information about the Voyage-linux mailing list