You can move a virtual machine (VM) created with OVZ virtualization to an LXD cluster. To move the VM:

  1. Save the information about permissions to VM files.
  2. Create an LXD container for the VM and clear it.
  3. Move the directory of the source VM to the created LXD container.
  4. 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.

  1. Update software packages to the latest version:

    yum update
    BASH
  2. Install the acl package on the running VM:

    yum install acl
    BASH
  3. Install the cloud-init package:

    yum install cloud-init
    CODE
  4.  Save the information about permissions to VM files and directories:

    cd / && getfacl -R / > acl.save
    BASH
  5. Stop the VM:

    Note

    If you use VMmanager 5 OVZ, stop the VM in the control panel: ManagementVirtual machines → select the VM → Stop button.

    vzctl stop 109
    BASH

    109 — id of the OVZ container with the VM

  6. Save the VM directory to the archive:

    If you use simfs

    cd /vz/private/109/;tar -czf /109.tgz .
    BASH

    If you use ploop

    mount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
    BASH
  7. Copy the created archive to LXD cluster node.
  8. 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.

  9. Determine where the VM container is located:

    zfs list
    BASH
  10. Mount the container with the created VM:

    zfs mount tank/containers/vm-624
    BASH

    tank — ZFS pool name

    vm-624 — VM name

  11. Clear the container:

    rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
    BASH
  12. 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
    BASH
  13. 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
    BASH
  14. 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*
    CODE
  15. Edit /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"
    CODE
  16. 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
    CODE

    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
    CODE
  17. Unmount the container:

    zfs umount tank/containers/vm-624
    BASH
  18. Delete the content of the directory /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/.

  19. Start the VM in VMmanager interface.

  20. Restore the permissions to VM files:

    lxc exec vm-624 bash
    BASH
    cd / && setfacl --restore=acl.save
    BASH
  21. Reboot the VM to apply the settings:

    reboot
    BASH
  1. Update software packages to the latest version:

    apt update && apt upgrade
    BASH
  2. Install the acl package on the running VM:

    apt install acl
    BASH
  3. 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 
    CODE
  4. Install the cloud-init package:

    dpkg -i cloud-*
    
    BASH
    apt --fix-broken install -y
    BASH
    dpkg -i cloud-*
    BASH
  5.  Save the information about permissions to VM files and directories:

    cd / && getfacl -R / > acl.save
    BASH
  6. Stop the VM:

    Note

    If you use VMmanager 5 OVZ, stop the VM in the control panel: ManagementVirtual machines → select the VM → Stop button.

    vzctl stop 109
    BASH

    109 — id of the OVZ container with the VM

  7. Save the VM directory to the archive:

    If you use simfs

    cd /vz/private/109/;tar -czf /109.tgz .
    BASH

    If you use ploop

    mount -t ploop /vz/private/109/root.hdd/DiskDescriptor.xml /media/;cd /media;tar -czf /109.tgz .
    BASH
  8. Copy the created archive to LXD cluster node.
  9. 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.

  10. Determine where the VM container is located:

    zfs list
    BASH
  11. Mount the container with the created VM:

    zfs mount tank/containers/vm-624
    BASH

    tank — ZFS pool name

    vm-624 — VM name

  12. Clear the container:

    rm -rf /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/*
    BASH
  13. 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
    BASH
  14. 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
    BASH
  15. Edit the network interface configuration file:

    vi /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/rootfs/etc/network/interfaces
    CODE

    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/*
    CODE
  16. 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
    CODE

    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
    CODE
  17. Unmount the container:

    zfs umount tank/containers/vm-624
    BASH
  18. Delete the content of the directory /var/snap/lxd/common/lxd/storage-pools/zfs_pool/containers/vm-624/.

  19. Start the VM in VMmanager interface.

  20. Restore the permissions to VM files:

    lxc exec vm-624 bash
    BASH
    cd / && setfacl --restore=acl.save
    BASH
  21. Reboot the VM to apply the settings:

    reboot
    BASH