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.
-
Update software packages to the latest version:
yum update
-
Install the acl package on the running VM:
yum install acl
-
Install the cloud-init package:
yum install cloud-init
-
Save the information about permissions to VM files and directories:
cd / && getfacl -R / > acl.save
-
Stop the VM:
NoteIf you use VMmanager 5 OVZ, stop the VM in the control panel: Management → Virtual machines → select the VM → Stop button.vzctl stop 109
Comments to the command -
Save the VM directory to the archive:
If you use simfscd /vz/private/109/;tar -czf /109.tgz .
If you use ploopmount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
- Copy the created archive to LXD cluster node.
-
In the VMmanager interface, create a VM in the LXD cluster and stop it.
NoteCreate a VM with the same OS and the same parameters as the original VM. -
Determine where the VM container is located:
zfs list
-
Mount the container with the created VM:
zfs mount tank/containers/vm-624
Comments to the command -
Clear the container:
rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
-
Unzip the archive from the original VM:
tar -xf 109.tgz -C /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs
-
Change 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
-
Remove old network configuration files:
rm /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/sysconfig/network-scripts/ifcfg-venet*
-
Edit /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/sysconfig/network file:
Example of fileNETWORKING="yes" GATEWAYDEV="venet0" NETWORKING_IPV6="yes" IPV6_DEFAULTDEV="venet0" HOSTNAME="example.com"
-
Create 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
File 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
-
Unmount the container:
zfs umount tank/containers/vm-624
- Delete 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
cd / && setfacl --restore=acl.save
-
Reboot the VM to apply the settings:
reboot
-
Update software packages to the latest version:
apt update && apt upgrade
-
Install the acl package on the running VM:
apt install acl
-
Download 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
-
Install the cloud-init package:
dpkg -i cloud-*
apt --fix-broken install -y
dpkg -i cloud-*
-
Save the information about permissions to VM files and directories:
cd / && getfacl -R / > acl.save
-
Stop the VM:
NoteIf you use VMmanager 5 OVZ, stop the VM in the control panel: Management → Virtual machines → select the VM → Stop button.vzctl stop 109
Comments to the command -
Save the VM directory to the archive:
If you use simfscd /vz/private/109/;tar -czf /109.tgz .
If you use ploopmount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
- Copy the created archive to LXD cluster node.
-
In the VMmanager interface, create a VM in the LXD cluster and stop it.
NoteCreate a VM with the same OS and the same parameters as the original VM. -
Determine where the VM container is located:
zfs list
-
Mount the container with the created VM:
zfs mount tank/containers/vm-624
Comments to the command -
Clear the container:
rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
-
Unzip the archive from the original VM:
tar -xf 109.tgz -C /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs
-
Change 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
-
Edit the network interface configuration file:
vi /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/network/interfaces
File 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/*
-
Edit 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
File 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
-
Unmount the container:
zfs umount tank/containers/vm-624
- Delete 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
cd / && setfacl --restore=acl.save
-
Reboot the VM to apply the settings:
reboot