Commit 145424c7 authored by root's avatar root

add mkoverlay

parent 8bb30efe
Pipeline #32 failed with stages
#!/bin/bash
if [ "$1" = "" ]; then
cat<<EOF
mkoverlay [_corezone] [targetzone] [copyopts]
Converts a flat dir zone to an overlay zone based on the specified core zone.
EOF
exit 0
fi
COREZONE=""
if [ "$2" != "" ]; then
COREZONE=$1
shift
fi
if [ "$COREZONE" != "" ]; then
zone start $COREZONE || true
inzones $COREZONE "apt -y update; apt -y upgrade"
zone stop $COREZONE || true
fi
zone start $1; sleep 1 || true
inzones $1 "apt -y update; apt -y upgrade"
zone stop $1; sleep 1 || true
cp -avu /zone/$1/. /zone/${1}.bak/
zfs umount Z/zone/$1
zfs list -t all
rm -rf /zone/$1
if [ "$COREZONE" = "" ]; then
lxc-destroy -l DEBUG -fs -n $1; sleep 1 || true
zfs destroy -R $(zfs list -t snapshot | grep @$1 | cut -d' ' -f1) || true
lxc-create -l DEBUG -n $1 -B zfs -t none; sleep 1 || true
zfs create -o mountpoint=/zone/$1/rootfs Z/zone/$1 || true
lxc-stop -l DEBUG -n $1 || true
else
lxc-destroy -l DEBUG -fs -n $1; sleep 1 || true
zfs destroy -R $(zfs list -t snapshot | grep @$1 | cut -d' ' -f1) || true
lxc-copy -l DEBUG -n $COREZONE -N $1 -p /zone/ -B zfs -s
if [ $? -ne 0 ]; then
mv /zone/${1}.bak /zone/$1
exit 1
fi
lxc-stop -l DEBUG -n $1 || true
fi
zfs mount Z/zone/$1
mkdir -p /opt/zone/$1
sed -i "s/= \/zone\//= zfs:\/zone\//" /zone/$1/config
sed -i "s/dir:\/zone\//zfs:\/zone\//" /zone/$1/config
sed -i "s/zone\/\@/zone\/\_/" /zone/$1/config
zone start $1
rsync -av --progress /zone/$1.bak/rootfs/. /zone/$1/rootfs/
cp -v /zone/$1.bak/* /zone/$1/
zone restart $1
echo ""
echo "Verify the functionality of the zone, then"
echo " rm -rf /zone/$1.bak"
echo "if you are satisfied."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment