I use Xen with LVM and want to clone my mailserver VM vm01.mail-disk with courier/postfix in Debian jessie to test if an upgrade is easily feasable.

How do I clone the VM and what do I have to change in the clone, so it doesn't interfear with the running mail server?

I am afraid, that the clone would immediately start fetching or sending mails from the existing queue.

I would first create a snapshot of the vm with the same of the original one:

lvcreate -L20480 -s -n 'vm01.mail-disk-snapshot' /dev/vg0/vm01.mail-disk

But I am not sure what is the best way to access that snapshot now and to test the dist-upgrade.

1 Answer 1



  • choose an IP for your new VM (in this example
  • choose an IP6 for your new VM (in this example 2a01:4f8:241:1d02:0:77:77:200)
  • choose a name (vm01.mail-test)

create a new xen guest

xen-create-image --hostname=vm01.mail-test --pygrub --size=180Gb --swap=8Gb --vcpus=1 --memory=8Gb --ip= --dist=jessie --nopasswd --nodhcp --gateway= --netmask= --broadcast=
# maybe this would be enough:
#lvcreate -L 180G -n vm01.mail-test-disk /dev/vg0
#lvcreate -L 1G -n vm01.mail-test-swap /dev/vg0
#mkfs.ext4 /dev/vg0/vm01.mail-test-disk
#mkswap /dev/vg0/vm01.mail-test-swap

mount the snapshot and the new LVM-volume:

mkdir -p /media/vm01.mail-disk-snapshot/
mkdir -p /media/vm01.mail-test-disk/
mount /dev/vg0/vm01.mail-disk-snapshot /media/vm01.mail-disk-snapshot/
mount /dev/vg0/vm01.mail-test-disk /media/vm01.mail-test-disk/

use rsync to copy all the data into the new LVM-volume

format the new VM and sync all files from the snapshot to the newly created VM but skip folders, that may not copied to the new server:

mkfs.ext4 /dev/vg0/vm01.mail-test-disk
e2fsck -f /dev/vg0/vm01.mail-test-disk
tune2fs -O ^metadata_csum /dev/vg0/vm01.mail-test-disk
# yes
tune2fs -O ^64bit /dev/vg0/vm01.mail-test-disk
resize2fs -s /dev/vg0/vm01.mail-test-disk
rsync -aAxX --del --info=progress2 /media/vm01.mail-disk-snapshot/ /media/vm01.mail-test-disk/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/boot/*,/var/tmp/*,/var/cache/*,/usr/tmp/*}
# this excludelist for rsync only excludes * inside each folders

adapt the new VM to the new IPs

find /media/vm01.mail-test-disk/etc/ -type f -exec sed -i -e "s/2a01:4f8:241:1d02:0:77:77:101/2a01:4f8:241:1d02:0:77:77:200/g" \
                                                          -e "s/" \
                                                          "{}" \;

chroot into the mounted new system:

mount /dev/vg0/vm01.mail-test-disk /media/vm01.mail-test-disk/
mount -t proc none /media/vm01.mail-test-disk/proc
mount --bind /dev /media/vm01.mail-test-disk/dev
mount -t sysfs sysfs /media/vm01.mail-test-disk/sys
chroot /media/vm01.mail-test-disk/ /bin/bash

1. empty the postqueue so no mails are sent from your new VM

postsuper -d ALL

2. adapt Hostname and exit

hostname mail-test
echo mail-test > /etc/hostname
echo " mail-test" >> /etc/hosts

start the new VM

umount -l /media/vm01.mail-test-disk
umount /media/vm01.mail-disk-snapshot 

xen create /etc/xen/vm01.mail-test.cfg
sleep 20
ssh "ip a s"

solved problems during development of this solution:

Here you see problems that occurred during the last days: Cannot boot new VM, when copied from one XEN-host to another


Now everything runs fine in the new Copied VM


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .