persistent changes

pull/5/head
Tomas M 2012-09-27 10:22:03 -05:00
parent 7f9aecfc3a
commit 1633d3369e
3 changed files with 74 additions and 14 deletions

1
build
View File

@ -29,6 +29,7 @@ cd ..
rm -Rf "$LIVEKITDATA" rm -Rf "$LIVEKITDATA"
BOOT="$LIVEKITDATA"/"$LIVEKITNAME"/boot BOOT="$LIVEKITDATA"/"$LIVEKITNAME"/boot
mkdir -p "$BOOT" mkdir -p "$BOOT"
mkdir -p "$BOOT"/../changes
mv "$INITRAMFS" $BOOT/initrfs.img mv "$INITRAMFS" $BOOT/initrfs.img
cp bootfiles/* $BOOT cp bootfiles/* $BOOT
cat bootfiles/syslinux.cfg | sed -r "s:/boot/:/$LIVEKITNAME/boot/:" > $BOOT/syslinux.cfg cat bootfiles/syslinux.cfg | sed -r "s:/boot/:/$LIVEKITNAME/boot/:" > $BOOT/syslinux.cfg

View File

@ -26,25 +26,25 @@ init_devs
init_aufs init_aufs
init_zram init_zram
init_union "$CHANGES" "$UNION"
# find data dir with filesystem bundles # find data dir with filesystem bundles
DATA="$(find_data 60 "$DATAMNT")" DATA="$(find_data 60 "$DATAMNT")"
debug_shell
# setup persistent changes, if possible
persistent_changes "$DATA" "$CHANGES"
debug_shell
# copy to RAM if needed # copy to RAM if needed
DATA="$(copy_to_ram "$DATA")" DATA="$(copy_to_ram "$DATA" "$CHANGES")"
debug_shell
debug_shell # init aufs union
init_union "$CHANGES" "$UNION"
debug_shell
# add data to union # add data to union
union_append_bundles "$DATA" "$BUNDLES" "$UNION" union_append_bundles "$DATA" "$BUNDLES" "$UNION"
debug_shell
# create empty fstab # create empty fstab
fstab_create "$UNION" fstab_create "$UNION"
debug_shell
header "Live Kit done, starting $LIVEKITNAME" header "Live Kit done, starting $LIVEKITNAME"
debug_shell
change_root "$UNION" change_root "$UNION"
header "!!ERROR occured, you shouldn't be here.!!" header "!!ERROR occured, you shouldn't be here.!!"

View File

@ -176,7 +176,7 @@ init_aufs()
} }
# Setup empty union # Setup empty union
# $1 = memory directory (tmpfs will be mounted there) # $1 = changes directory (ramfs or persistent changes)
# $2 = union directory where to mount the union # $2 = union directory where to mount the union
# #
init_union() init_union()
@ -187,7 +187,7 @@ init_union()
echo "Setting up union using AUFS 3" echo "Setting up union using AUFS 3"
mkdir -p "$1" mkdir -p "$1"
mkdir -p "$2" mkdir -p "$2"
mount -t aufs -o xino="$1/.xino",br="$1" none "$2" mount -t aufs -o xino="/.xino",br="$1" none "$2"
} }
# Return device mounted for given directory # Return device mounted for given directory
@ -282,24 +282,83 @@ find_data()
} }
# Activate persistent changes
# $1 = data directory
# $2 = target changes directory
#
persistent_changes()
{
local CHANGES T1 T2
CHANGES="$1/$(basename "$2")"
T1="$CHANGES/.empty"
T2="$T1"2
# Setup the directory anyway, it will be used in all cases
mkdir -p "$2"
# If persistent changes are not requested, end here
if grep -vq perch /proc/cmdline; then
return
fi
# check if changes directory exists and is writable
touch "$T1" 2>/dev/null && rm -f "$T1" 2>/dev/null
# if not, simply return back
if [ $? -ne 0 ]; then
echo "* Persistent changes not writable or not used" >&2
return
fi
echo "* Testing persistent changes for posix compatibility" >&2
touch "$T1" && ln -sf "$T1" "$T2" 2>/dev/null && \
chmod +x "$T1" 2>/dev/null && test -x "$T1" && \
chmod -x "$T1" 2>/dev/null && test ! -x "$T1" && \
rm "$T1" "$T2" 2>/dev/null
if [ $? -ne 0 ]; then
echo_green_star
echo "Activating posixovl for persistent changes" >&2
rm "$T1" "$T2" 2>/dev/null
mount.posixovl -F "$CHANGES" -- -o attr_timeout=300,entry_timeout=300,negative_timeout=300,kernel_cache,allow_other
else
echo_green_star
echo "Activating native persistent changes" >&2
fi
mount --bind "$CHANGES" "$2"
}
# Copy data to RAM if requested # Copy data to RAM if requested
# $1 = live data directory # $1 = live data directory
# $2 = changes directory
# #
copy_to_ram() copy_to_ram()
{ {
local DM RAM local DM RAM CHANGES
if grep -vq toram /proc/cmdline; then if grep -vq toram /proc/cmdline; then
echo "$1" echo "$1"
return return
fi fi
CHANGES="$(basename $2)"
DM="$(mounted_device "$1" | cut -d : -f 2-)" DM="$(mounted_device "$1" | cut -d : -f 2-)"
RAM="$DM.ram" RAM="$DM.ram"
echo "* Copying $LIVEKITNAME data to RAM..." >&2 echo "* Copying $LIVEKITNAME data to RAM..." >&2
mkdir -p "$RAM" mkdir -p "$RAM"
cp -a "$DM/$LIVEKITNAME" "$RAM" cp -a "$DM/$LIVEKITNAME" "$RAM"
echo "$RAM/$LIVEKITNAME" echo "$RAM/$LIVEKITNAME"
if grep -q perch /proc/cmdline; then
umount "$2"
umount "$DM/$LIVEKITNAME/$CHANGES"
umount "$DM/$LIVEKITNAME/$CHANGES" 2>/dev/null
mount --bind "$RAM/$LIVEKITNAME/$CHANGES" "$2"
fi
umount "$DM" umount "$DM"
} }