[Voyage-linux] aufs: Sync to flash with our reboot ?

Guido De Rosa (spam-protected)
Fri Mar 27 10:17:58 HKT 2009


>> Any ideas about how I might be able to sync the aufs to flash with our a
>> reboot ?

> Currently it is not support, at least not the same way you can do like
> 0.5.2.  There are some problem on it once 0.6 is now using aufs.
>
> The /var/log you see in 0.6 is an aufs filesystem, which is mounted using
> two branches.  At the bottom the read-only /var/log and at the top a tmpfs
> /lib/init/rw/var/log.  All changes goes to /lib/init/rw/var/log.
>
> The problem is since there are running process are using files in /var/log,
> so you cannot unmount or remount /var/log after sync operations.

Hi all!

I've just written a slightly modified version of
/etc/init.d/voyage-sync which apparently makes sync'ing possible even
on a running system.

The trick is keeping /.sync directory across reboots and using it as a
"disk base" for the unionfs/aufs instead of just as a temporary place
to put files during the sync.

This implementation doesn't unmount anything, and call "rsync" just
one time per directory during a reboot (instead of two).

There's also a /usr/local/sbin/voyage-sync script, that you can easily
put as a cron job, if you like.

"Use at your own risk"  but HTH ;-)

####### BEGIN /etc/init.d/voyage-sync #######
#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=voyage-sync
DESC=voyage-sync

TMPFS_ROOT=/lib/init/rw
SYNCFS_ROOT=/.sync
SYNC_DIRS="/var/log /var/tmp"

RSYNC_OPTS=' -a -q --delete-after '

# using the following commands to install
#
#    update-rc.d voyage-sync start 36 S . stop 99 0 6 .

if [ -f /etc/default/voyage-util ] ; then
    . /etc/default/voyage-util;
fi
SYNC_DIRS="$SYNC_DIRS $VOYAGE_SYNC_DIRS"
UNIONFS=${VOYAGE_UNIONFS:=aufs}

mount_dirs()
{
    # $1 : aufs|unionfs|tmpfs
    # $2 : mount point (for example: /var/log)
    # $3 : in-memory, writeable fs (for example: /lib/init/rw/var/log)
    # $4 : on disk, read only dir (for example: /.sync/var/log)
    #
    # /etc/init.d/voyage-sync start:
    #     $2 is made the union-fs of $3 and $4
    #
    # /etc/init.d/voyage-sync stop:
    #     $4 is synchronized to $3
    #
    case $1 in
        'aufs')
            PERM=$(stat --format=%U:%G $2)
            chmod --reference=$2 $3
            chown --reference=$2 $3
            mount -t aufs -o dirs=$3:$4=ro aufs $2> /dev/null 2>&1
            chown $PERM $2
            ;;
        'unionfs')
            PERM=$(stat --format=%U:%G $2)
            chmod --reference=$2 $3
            chown --reference=$2 $3
            mount -t unionfs -o dirs=$3:$4=ro unionfs $2> /dev/null 2>&1
            chown $PERM $2
            ;;
        'tmpfs')
            echo not implemented
            ;;
        *)
            ;;
    esac
}

case $1 in
    'start')
        echo "Voyage is now setting up tmpfs for changed files..."

        for SYNC_DIR in $SYNC_DIRS; do
            [ ! -d $TMPFS_ROOT/$SYNC_DIR ] && mkdir -p
$TMPFS_ROOT/$SYNC_DIR
            mount_dirs \
                $UNIONFS \
                $SYNC_DIR \
                $TMPFS_ROOT/$SYNC_DIR \
                $SYNCFS_ROOT/$SYNC_DIR
        done

        echo "Done."
        ;;
    'stop')
        echo "Voyage is now synchroning changed files..."
        [ -f /usr/local/sbin/remountrw ] && /usr/local/sbin/remountrw
        for SYNC_DIR in $SYNC_DIRS; do
            if [ ! -d $SYNCFS_ROOT/$SYNC_DIR ] ; then
                                mkdir -p $SYNCFS_ROOT/$SYNC_DIR
                                PERM=$(stat --format=%U:%G $SYNC_DIR)
                                chown $PERM $SYNCFS_ROOT/$SYNC_DIR
                        fi

            echo "  Sync'ing $SYNC_DIR to `dirname $SYNC_DIR`    "

            rsync $RSYNC_OPTS $SYNC_DIR $SYNCFS_ROOT/`dirname $SYNC_DIR`
        done

        echo "Done."
        ;;
    *)
        ;;
esac
###### END  /etc/init.d/voyage-sync #################



#### BEGIN /usr/local/sbin/voyage-sync ##########
#!/bin/sh

# find out if / is read-only
RO='NO'
touch / 2> /dev/null || RO='YES'

# remounts rw and synchronizes
/etc/init.d/voyage-sync stop

if [ "x$RO" = "xYES" ]; then
    remountro
fi
#### END /usr/local/sbin/voyage-sync ##########




More information about the Voyage-linux mailing list