10.6. Creating Virtual Environments with virt-install

While you typically create virtual machines and containers using prlctl, you can also do the same with virt-install. You will need to install it from the Virtuozzo official repository with yum install virt-install.

You can manage VMs created with virt-install using prlctl. You will need, however, to manually delete the hard disk images after you delete such VMs with prlctl delete.

To shorten the commands and make sure that the required parameters are always supplied, the common options for creating virtual environments are placed in presets. You can list the default presets and their contents as follows:

# virt-install --list-presets
vz_vm_windows - Virtuozzo VM Windows
vz_vm_linux - Virtuozzo VM Linux
vz_ct_windows - Virtuozzo CT Windows
# virt-install --show-preset vz_vm_linux
# virt-install --show-preset vz_vm_windows

You can also create your own presets and place them in /etc/virt-manager/presets. If a preset starts with a commented-out line, it is used to describe the preset in the output of virt-install --list-presets. Otherwise “No description” is shown.

Note

The vz_ct_windows preset is meant for the Windows Containers Demo. For more details, see the Windows Containers Demo Walkthrough.

The following sample command creates a blank VM based on the vz_vm_linux preset optimized for running CentOS 7:

# virt-install \
--import \
--name mylinuxvm \
--ram 2048 \
--vcpus 'sockets=1,cores=2' \
--disk 'path=/vz/mylinuxvm/harddisk.hdd,bus=scsi,startup_policy=optional,boot_order=1,size=64' \
--disk 'device=cdrom,path=myosdistrib.iso,bus=scsi,boot_order=2' \
--preset vz_vm_linux \
--graphics=vnc,password=mypasswd,listen=0.0.0.0,port=6533

The resulting VM has the following properties:

  • 2048 MB RAM

  • 1 CPU socket and 2 CPU cores

  • 64 GB hard disk in the file /vz/mylinuxvm/harddisk.hdd, which is created along with the VM (the directory must exist)

  • A CD-ROM drive where an existing file myosdistrib.iso, e.g., a Linux distribution image, is mounted to boot and install from

  • VNC enabled on port 6533 at host’s IP address

The next sample command creates a blank VM based on the vz_vm_windows preset optimized for running Microsoft Windows Server 2019:

# virt-install \
--import \
--name mywindowsvm \
--ram 2048 \
--vcpus 'sockets=1,cores=2' \
--disk 'path=/vz/mywindowsvm/harddisk.hdd,bus=scsi,startup_policy=optional,boot_order=1,size=64' \
--disk 'device=cdrom,path=myosdistrib.iso,bus=scsi,boot_order=2' \
--preset vz_vm_windows \
--graphics=vnc,password=mypasswd,listen=0.0.0.0,port=6534

The resulting VM has the following properties:

  • 2048 MB RAM

  • 1 CPU socket and 2 CPU cores

  • 64 GB hard disk in the file /vz/mywindowsvm/harddisk.hdd, which is created along with the VM (the directory must exist)

  • A CD-ROM drive where an existing file myosdistrib.iso, e.g., a Microsoft Windows distribution image, is mounted to boot and install from

  • VNC enabled on port 6534 at host’s IP address

Finally, the sample commands to create a Linux container based on the CentOS 7 template are:

# vzpkg create image centos-7-x86_64 mylinuxct.hdd
# virt-install \
--connect vzct:///system \
--name mylinuxct \
--memory 2048 \
--disk 'path=/vz/mylinuxct/mylinuxct.hdd,boot_order=1'

The first command creates a hard disk image for the container. It is made from the same template that is used when creating containers using prlctl. The second command creates the container with the specified hard disk.

You can resize the disk with virsh blockresize <CT_name> <device_name> <size><units>. The container can be running or stopped. For example:

# virsh --connect vzct:///system blockresize mylinuxct vda 16G
# prlctl list -i mylinuxct | grep hdd
hdd0 (+) scsi:0 image='/root/mylinuxct.hdd' type='expanded' 16384Mb <...>