Moving an OVZ container to LXD cluster
You can move a virtual machine (VM) created with OVZ virtualization to an LXD cluster. To move the VM:
- Save the information about permissions to VM files.
- Create an LXD container for the VM and clear it.
- Move the directory of the source VM to the created LXD container.
- Restore the permissions to VM files.
Note
You can apply this method only for moving VM to an LXD cluster with the "Switching" network configuration type.
Update software packages to the latest version:
yum update
BASHInstall the acl package on the running VM:
yum install acl
BASHInstall the cloud-init package:
yum install cloud-init
CODESave the information about permissions to VM files and directories:
cd / && getfacl -R / > acl.save
BASHStop the VM:
Note
If you use VMmanager 5 OVZ, stop the VM in the control panel: Management → Virtual machines → select the VM → Stop button.
vzctl stop 109
BASHComments to the command109 — id of the OVZ container with the VM
Save the VM directory to the archive:
If you use simfs
cd /vz/private/109/;tar -czf /109.tgz .
BASHIf you use ploop
mount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
BASH- Copy the created archive to LXD cluster node.
In the VMmanager interface, create a VM in the LXD cluster and stop it.
Note
Create a VM with the same OS and the same parameters as the original VM.
Determine where the VM container is located:
zfs list
BASHMount the container with the created VM:
zfs mount tank/containers/vm-624
BASHComments to the commandtank — ZFS pool name
vm-624 — VM name
Clear the container:
rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
BASHUnzip the archive from the original VM:
tar -xf 109.tgz -C /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs
BASHChange the owner of the file system to the root user of LXD container:
chown 1000000:1000000 /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/ -R
BASHRemove old network configuration files:
rm /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/sysconfig/network-scripts/ifcfg-venet*
CODEEdit /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/sysconfig/network file:
Example of file
NETWORKING="yes" GATEWAYDEV="venet0" NETWORKING_IPV6="yes" IPV6_DEFAULTDEV="venet0" HOSTNAME="example.com"
CODECreate a new configuration file for the network interface:
touch /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/sysconfig/network-scripts/ifcfg-ens1
CODEFile contents
# Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=none DEFROUTE=yes DEVICE=ens1 DNS1=8.8.8.8 DNS2=1.1.1.1 DNS3=77.88.8.8 GATEWAY=10.13.0.1 IPADDR=10.13.0.156 IPADDR1=10.13.0.157 NETMASK=255.255.255.0 NETMASK1=255.255.255.255 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no
CODEUnmount the container:
zfs umount tank/containers/vm-624
BASHDelete the content of the directory /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/.
Start the VM in VMmanager interface.
Restore the permissions to VM files:
lxc exec vm-624 bash
BASHcd / && setfacl --restore=acl.save
BASHReboot the VM to apply the settings:
reboot
BASH
Update software packages to the latest version:
apt update && apt upgrade
BASHInstall the acl package on the running VM:
apt install acl
BASHDownload the cloud-init packages:
curl -O https://download.ispsystem.com/external/cloud-init/stretch/cloud-guest-util_0.29-1_all.deb -O https://download.ispsystem.com/external/cloud-init/stretch/cloud-image-utils_0.29-1_all.deb -O https://download.ispsystem.com/external/cloud-init/stretch/cloud-init_20.2-2~deb10u1_all.deb -O https://download.ispsystem.com/external/cloud-init/stretch/cloud-utils-euca_0.29-1_all.deb -O https://download.ispsystem.com/external/cloud-init/stretch/cloud-utils_0.29-1_all.deb
CODEInstall the cloud-init package:
dpkg -i cloud-*
BASHapt --fix-broken install -y
BASHdpkg -i cloud-*
BASHSave the information about permissions to VM files and directories:
cd / && getfacl -R / > acl.save
BASHStop the VM:
Note
If you use VMmanager 5 OVZ, stop the VM in the control panel: Management → Virtual machines → select the VM → Stop button.
vzctl stop 109
BASHComments to the command109 — id of the OVZ container with the VM
Save the VM directory to the archive:
If you use simfs
cd /vz/private/109/;tar -czf /109.tgz .
BASHIf you use ploop
mount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
BASH- Copy the created archive to LXD cluster node.
In the VMmanager interface, create a VM in the LXD cluster and stop it.
Note
Create a VM with the same OS and the same parameters as the original VM.
Determine where the VM container is located:
zfs list
BASHMount the container with the created VM:
zfs mount tank/containers/vm-624
BASHComments to the commandtank — ZFS pool name
vm-624 — VM name
Clear the container:
rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
BASHUnzip the archive from the original VM:
tar -xf 109.tgz -C /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs
BASHChange the owner of the file system to the root user of LXD container:
chown 1000000:1000000 /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/ -R
BASHEdit the network interface configuration file:
vi /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/network/interfaces
CODEFile contents
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback source /etc/network/interfaces.d/*
CODEEdit the Cloud-init configuration file for network settings:
vi /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-882-deb9v1/rootfs/etc/network/interfaces.d/50-cloud-init
CODEFile contents
# This file is generated from information provided by the datasource. Changes # to it will not persist across an instance reboot. To disable cloud-init's # network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} auto lo iface lo inet loopback auto ens1 iface ens1 inet static address 10.13.0.162/24 dns-nameservers 77.88.8.8 8.8.8.8 1.1.1.1 gateway 10.13.0.1
CODEUnmount the container:
zfs umount tank/containers/vm-624
BASHDelete the content of the directory /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/.
Start the VM in VMmanager interface.
Restore the permissions to VM files:
lxc exec vm-624 bash
BASHcd / && setfacl --restore=acl.save
BASHReboot the VM to apply the settings:
reboot
BASH