Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TIP: aufs and genkernel
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
E-Razor
n00b
n00b


Joined: 11 Jul 2004
Posts: 69

PostPosted: Mon Feb 23, 2009 4:01 pm    Post subject: TIP: aufs and genkernel Reply with quote

I just added some support for aufs in the genkernel- linuxrc.

To explain what and why:
I'm using some asus eeeBox- PC's as a desktop system and don't want to use the integrated harddisk. So I bought a 2Gig SD- card, put a nearly full desktop system (kde3, kde4, openoffice, gimp, cups and much more) in an 1.3 gig squash image.

The system boots from the SD- card and creates a virtual aufs- root with these branches:
/aufs_vertex
sdb2 -> /aufs_overlay
tmpfs -> /aufs_dynamic
/newroot/boot/images/* -> /aufs_static/*/

I put some images in /newroot/boot/images and they're all merged into the root-fs. So you can even expand your root-fs without copying a lot of files.

The sense of /aufs_overlay is, that you can remove the lock of the SD, so /aufs_overlay becomes writeable and everything you change is stored on /aufs_overlay and is still there after a reboot (since it's on the SD).

If you set the lock /aufs_overlay becomes ro and changes are stored in /aufs_dyamic (which is tmpfs).

I think it's quite an dynamic functionality so you may even can use it for other purposes.

To add the support you'll need aufs (i compiled it into the kernel) and some changes in /usr/share/genkernel/defaults/linuxrc after line 459:
Code:


      for x in ${CMDLINE}
      do
         case "${x}" in
            aufs_img_dir\=*)
               USE_AUFS=1
               AUFS_IMAGE_DIR=`parse_opt "${x}"`
            ;;
            aufs_overlay\=*)
               AUFS_OVERLAY=`parse_opt "${x}"`
            ;;
         esac
      done
      
      
      if [ "${USE_AUFS}" = '1' ]
      then
         mkdir /aufs_dynamic
         good_msg "Mounting tmpfs for aufs"
         mount -t tmpfs tmpfs /aufs_dynamic
         AUFS_DIRS="/aufs_dynamic=rw"

         if [ "${AUFS_OVERLAY}" != "" ]
         then
            good_msg "Adding aufs overlay (${AUFS_OVERLAY})"
            mkdir /aufs_overlay
            mount ${AUFS_OVERLAY} /aufs_overlay -o rw
            if [ "$?" = '0' ]
            then
               touch /aufs_overlay/writeable 2>/dev/null
               if [ "$?" = '0' ]
               then
                  rm /aufs_overlay/writeable
                  AUFS_DIRS="${AUFS_DIRS}:/aufs_overlay=rw"
               else
                  warn_msg "overlay is ro"
                  AUFS_DIRS="${AUFS_DIRS}:/aufs_overlay=ro+wh"
               fi
            else
                bad_msg"mount failed, skipping"
            fi
         fi
         if [ -d "${NEW_ROOT}/${AUFS_IMAGE_DIR}" ]
         then
            for x in $(ls ${NEW_ROOT}/${AUFS_IMAGE_DIR})
            do
               good_msg "Mounting file ${x}"
               mkdir -p /aufs_images/${x}/
               mount ${NEW_ROOT}/${AUFS_IMAGE_DIR}/${x} /aufs_images/${x}/ -o loop
               AUFS_DIRS="${AUFS_DIRS}:/aufs_images/${x}/=rr"
            done
         fi
   
         mkdir /aufs_vertex
         mount none -t aufs -o dirs=${AUFS_DIRS},noplink /aufs_vertex
         NEW_ROOT=/aufs_vertex
         CHROOT="${NEW_ROOT}"
      fi


Other changes are not necessary.
The new options for the kernel are:
aufs_img_dir=/boot/images (sets the image dir for your loop- files, this is a folder on the device you specified with root=...)
aufs_overlay=/dev/... (add an overlay- to the branch, if writeable, your changes will be written here)


It works quite fine her, only problem I've currently is the unmounting process. From aufs i need to remount /aufs_overlay readonly (/etc/init.d/localmount should do this) otherwise on a journaling file-system the journal wouldn't be cleared and after the next reboot with a locked SD mount will not succeed for /aufs_overlay. Maybe someone got an idea how to remount devices out of aufs.

Anyway, wisch you much fun with it and hope for some comments :-)
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 918
Location: Switzerland

PostPosted: Tue Feb 24, 2009 1:57 pm    Post subject: Reply with quote

Hi,

Nice, i always use unionfs & squashfs for my netboot images... maybe i should try aufs out?!? :roll:

For your remount-problem...
Put your dirs in /etc/init.d/halt.sh under RC_NO_UMOUNTS. Next you have the choice of either hack up "mount_readonly()" or just put a remount,ro at the end of that file (before the last source... :P )

You could also use the file /fastboot to avoid the fsck during boot. (And maybe the "sync" mount-option to avoid corruption on the SD)

Cheers
_________________
Power to the people!
Back to top
View user's profile Send private message
E-Razor
n00b
n00b


Joined: 11 Jul 2004
Posts: 69

PostPosted: Tue Feb 24, 2009 5:10 pm    Post subject: Reply with quote

Yeah, i tried this settings in /etc/conf.d/localmount but in the vertex mount does not know the previously mounted devices.

I played a bit and found out that this can be solved via mount --move in the linuxrc script.
I'm moving for example /aufs_overlay to /newroot/mnt/aufs/overlay .

Next thing would be something like mount /mnt/aufs/overlay -o ro,remount . But that does not work since /mnt/aufs/overlay is part of the vertex with rw - settings.

I suppose i can remove /mnt/aufs/overlay from vertex via auplink but here i ran to another problem, since etc_defaults_aufs is missing in the aufs- cvs. (see http://sourceforge.net/tracker2/?func=detail&aid=2631053&group_id=167503&atid=843212 )

Anyway, aufs seems very stable. I'm using it since about a year for some devices and never had kernel problems or anything else.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum