10.5. 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
# Virtuozzo VM Linux
--blkiotune 'weight=500' \
--channel 'char_type=unix,target_type=virtio,name=org.qemu.guest_agent.0' \
--channel 'char_type=unix,target_type=virtio,name=org.qemu.guest_agent.1' \
--cputune 'global_period=100000,global_quota=-1' \
--network 'type=network,source=Bridged,boot_order=3' \
--noautoconsole \
--os-type linux \
--os-variant centos7.0 \
--redirdev none
# virt-install --show-preset vz_vm_windows
# Virtuozzo VM Windows
--blkiotune 'weight=500' \
--channel 'char_type=unix,target_type=virtio,name=org.qemu.guest_agent.0' \
--channel 'char_type=unix,target_type=virtio,name=org.qemu.guest_agent.1' \
--cputune 'global_period=100000,global_quota=-1' \
--disk 'device=floppy,path=/usr/share/vz-guest-tools/floppy_win2019.vfd,startup_policy=optional,readonly=on' \
--network 'type=network,source=Bridged,boot_order=3' \
--noautoconsole \
--os-type windows \
--os-variant win2k19 \
--redirdev none

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.