Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- lxc-clone.orig 2013-10-02 19:23:25.402039992 +0300
- +++ lxc-clone 2013-10-02 19:28:54.320818235 +0300
- @@ -191,6 +191,7 @@
- sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
- if [ -b $oldroot ]; then
- + tmproot=`mktemp -d`
- type vgscan || { echo "$(basename $0): lvm is not installed" >&2; false; }
- lvdisplay $oldroot > /dev/null 2>&1 || { echo "$(basename $0): non-lvm blockdev cloning is not supported" >&2; false; }
- lvm=TRUE
- @@ -202,41 +203,28 @@
- if [ $lxc_size = "_unset" ]; then
- lxc_size=`lvdisplay $oldroot | grep Size | awk '{ print $3 $4 }'`
- fi
- - newlv="${lxc_lv_prefix}${lxc_new}_snapshot"
- - lvcreate -s -L $lxc_size -n $newlv $oldroot
- - type xfs_admin > /dev/null 2>&1 && {
- - # change filesystem UUID if it is an xfs filesystem
- - xfs_admin -u /dev/$lxc_vg/$newlv && xfs_admin -U generate /dev/$lxc_vg/$newlv
- - }
- if [ $container_running = "True" ]; then
- lxc-unfreeze -n $lxc_orig
- frozen=0
- fi
- if [ $snapshot = "no" ]; then
- - #mount snapshot
- - mkdir -p ${rootfs}_snapshot
- - mount /dev/$lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot ${rootfs}_snapshot || { echo "$(basename $0): failed to mount new rootfs_snapshot" >&2; false; }
- - #create a new lv
- - lvcreate -L $lxc_size $lxc_vg -n ${lxc_lv_prefix}$lxc_new
- - echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
- - # and mount it so we can tweak it
- - mkdir -p $rootfs
- - mkfs -t $fstype /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new
- - mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "$(basename $0): failed to mount new rootfs" >&2; false; }
- - mounted=1
- - rsync -ax ${rootfs}_snapshot/ ${rootfs}/ || { echo "$(basename $0): copying data to new lv failed" >&2; false; }
- - umount ${rootfs}_snapshot
- - rmdir ${rootfs}_snapshot
- - lvremove -f $lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot
- + lvconvert -m 1 $oldroot --alloc anywhere
- + lvconvert --splitmirrors 1 --name $lxc_new $oldroot
- else
- + newlv="${lxc_lv_prefix}${lxc_new}_snapshot"
- + lvcreate -s -L $lxc_size -n $newlv $oldroot
- lvrename $lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot $lxc_vg/${lxc_lv_prefix}$lxc_new
- - echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
- - # and mount it so we can tweak it
- - mkdir -p $rootfs
- - mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "$(basename $0): failed to mount new rootfs" >&2; false; }
- - mounted=1
- fi
- + echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
- + type xfs_admin > /dev/null 2>&1 && {
- + # change filesystem UUID if it is an xfs filesystem
- + xfs_admin -u /dev/$lxc_vg/$newlv && xfs_admin -U generate /dev/$lxc_vg/$newlv
- + }
- + mkdir -p $tmproot
- + mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $tmproot || { echo "$(basename $0): failed to mount new rootfs" >&2; false; }
- + mounted=1
- + rootfs=$tmproot
- elif which btrfs >/dev/null 2>&1 && btrfs subvolume list $oldroot >/dev/null 2>&1; then
- # if oldroot is a btrfs subvolume, assume they want a snapshot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement