.. _Performing Virtual Machine-specific Operations:

Performing Virtual Machine-specific Operations
----------------------------------------------

This section focuses on operations specific to virtual machines.

.. _Pausing Virtual Machines:

Pausing Virtual Machines
~~~~~~~~~~~~~~~~~~~~~~~~

Pausing a running virtual machine releases the resources, such as RAM and CPU, currently used by this virtual machine. The released resources can then be used by the hardware node or other running virtual machines and containers.

To pause a virtual machine, you can use the ``prlctl pause`` command. For example, the following command pauses the virtual machine ``MyVM``:

::

    # prlctl pause MyVM
    Pause the VM...
    The VM has been successfully paused.

You can check that the virtual machine has been successfully paused by using the ``prlctl list -a`` command:

::

    # prlctl list -a
    STATUS  IP_ADDR         NAME
    running 10.10.10.101    MyCT
    paused  10.10.10.201    MyVM

The command output shows that the virtual machine ``MyVM`` is paused at the moment. To continue running this virtual machine, execute this command:

::

    # prlctl start MyVM
    Starting the VM...
    The VM has been successfully started.

.. _Managing Virtual Machine Devices:

Managing Virtual Machine Devices
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Virtuozzo allows you to manage the following virtual machine devices:

-  hard disk drives

-  CD/DVD-ROM drives

-  floppy disk drives

-  network adapters

-  serial ports

-  USB controllers

The main operations you can perform on these devices are:

-  adding a new device to the virtual machine

-  configuring the device properties

-  removing a device from the virtual machine

.. _Adding New Devices:

Adding New Devices
^^^^^^^^^^^^^^^^^^

This section provides information on adding new devices to your virtual machines. You can add new virtual devices to your virtual machine using the ``prlctl set`` command. The options responsible for adding particular devices are listed in the following table:

+--------------------+--------------------------------------------------------+
| Option             | Description                                            |
+====================+========================================================+
| ``hdd``            | Adds a new hard disk drive to the virtual machine. You |
|                    | can either connect an existing image to the virtual    |
|                    | machine or create a new one.                           |
|                    |                                                        |
|                    | .. note:: SCSI and VirtIO hard disks can be added to   |
|                    |     both running and stopped VMs, IDE disks can only   |
|                    |     be added to stopped VMs.                           |
+--------------------+--------------------------------------------------------+
| ``cdrom``          | Adds a new CD/DVD-ROM drive to the virtual machine.    |
+--------------------+--------------------------------------------------------+
| ``net``            | Adds a new network adapter to the virtual machine.     |
+--------------------+--------------------------------------------------------+
| ``fdd``            | Adds a new floppy disk drive to the virtual machine.   |
+--------------------+--------------------------------------------------------+
| ``serial``         | Adds a new serial port to the virtual machine.         |
+--------------------+--------------------------------------------------------+
| ``usb``            | Adds a new USB controller to the virtual machine.      |
+--------------------+--------------------------------------------------------+

For example, you can execute the following command to add a new virtual disk to the virtual machine ``MyVM``:

::

    # prlctl set MyVM --device-add hdd
    Creating hdd1 () scsi:1 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded' 65536Mb subtype=virtio-scsi
    Created hdd1 () scsi:1 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded' subtype=virtio-scsi
    The VM has been successfully configured.

This command creates a new virtual disk with the following default parameters:

-  name: ``hdd1``

-  disk type: SCSI

-  disk subtype: VirtIO SCSI

-  image file name and location: ``/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk1.hdd``

-  disk format: expanded

-  disk capacity: 65536 MB

You can redefine some of these parameters by specifying specific options during the command execution. For example, to create an IDE virtual disk that will have the capacity of 84 GB, you can run this command:

::

    # prlctl set MyVM --device-add hdd --size 84000 --iface ide
    Creating hdd2 () ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk2.hdd' type='expanded' 84000Mb
    Created hdd2 () ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk2.hdd' type='expanded'
    The VM has been successfully configured.

The virtual disk has been added to your virtual machine. However, before starting to use it, you must initialize the disk. Refer to the next subsection for information on how you can do it.

When managing devices, keep in mind the following:

-  You can connect up to 4 IDE devices, and 8 SCSI devices (virtual disks or CD/DVD-ROM drives) to a virtual machine.

-  A virtual machine can have up to 16 virtual network adapters.

-  A virtual machine can have up to 4 serial ports.

-  A virtual machine can have only 1 USB controller.

-  A virtual machine can have only 1 floppy disk drive.

.. _Adding Hyper-V SCSI Devices to Windows Virtual Machines:

Adding Hyper-V SCSI Devices to Windows Virtual Machines
*******************************************************

Virtuozzo supports Hyper-V paravirtualized device emulation of SCSI hard disks and CD/DVD-ROM drives. The emulation allows to use these devices with native Windows drivers. It is supported and recommended for the following Windows operating systems:

- Windows 10 (x64),

- Windows Server 2016,

- Windows Server 2012 R2,

- Windows Server 2012,

- Windows Server 2008 R2 with Service Pack 2.

To add, for example, a SCSI CD/DVD-ROM and HDD emulated via Hyper-V to a VM, run the following commands:

::

    # prlctl set vm1 --device-add cdrom --image <path_to_image> --iface scsi --subtype hyperv
    # prlctl set vm1 --device-add hdd --iface scsi --subtype hyperv

.. _Initializing Newly Added Disks:

Initializing Newly Added Disks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After you added a new blank virtual hard disk to the virtual machine configuration, it will be invisible to the operating system installed inside the virtual machine until the moment you initialize it.

Initializing the New Virtual Hard Disk in Windows

To initialize a new virtual hard disk in a Windows guest OS, you will need the Disk Management utility available. For example, in Windows Server 2012 you can access this utility by clicking Start > Control Panel > System and Security > Administrative Tools > Computer Management > Storage > Disk Management.

When you open the Disk Management utility, it automatically detects that a new hard disk was added to the configuration and launches the Initialize Disk wizard:

1. In the Select disks section, select the newly added disk.

2. Choose the partition style for the selected disk: MBR (Master Boot Record) or GPD (GUID Partition Table).

3. Click OK.

The added disk will appear as a new disk in the Disk Management utility window, but its memory space will be unallocated. To allocate the disk memory, right-click this disk name in the Disk Management utility window and select New Volume. The New Volume Wizard window will appear. Follow the steps of the wizard and create a new volume in the newly added disk.

After that your disk will become visible in My Computer and you will be able to use it as a data disk inside your virtual machine.

Initializing the New Virtual Hard Disk in Linux

Initializing a new virtual hard disk in a Linux guest OS comprises two steps: (1) allocating the virtual hard disk space and (2) mounting this disk in the guest OS.

To allocate the space, you need to create a new partition on this virtual hard disk using the fdisk utility:

.. note:: To use the ``fdisk`` utility, you need the ``root`` privileges.

1.  Launch a terminal window.

2.  To list the IDE disk devices present in your virtual machine configuration, enter:

    ::

        fdisk /dev/hd*

    .. note:: If you added a SCSI disk to the virtual machine configuration, use the ``fdisk /dev/sd*`` command instead.

3.  By default, the second virtual hard disk appears as ``/dev/hdc`` in your Linux virtual machine. To work with this device, enter:

    ::

        fdisk /dev/hdc

    .. note:: If this is a SCSI disk, use the ``fdisk /dev/sdc`` command instead.

4.  To get detailed information about the disk, enter:

    ::

        p

5.  To create a new partition, enter:

    ::

        n

6.  To create the primary partition, enter:

    ::

        p

7.  Specify the partition number. By default, it is 1.

8.  Specify the first cylinder. If you want to create a single partition on this hard disk, use the default value.

9.  Specify the last cylinder. If you want to create a single partition on this hard disk, use the default value.

10. To create a partition with the specified settings, enter:

    ::

        w

When you allocated the space on the newly added virtual hard disk, you should format it by entering the following command in the terminal:

::

   # mkfs -t <FileSystem> /dev/hdc1

.. note:: ``<FileSystem>`` stands for the filesystem you want to use on this disk. It is recommended to use ``ext4``.

When the added virtual hard disk is formatted, you can mount it in the guest OS.

1. To create a mount point for the new virtual hard disk, enter:

   ::

      # mkdir /mnt/hdc1

   .. note:: You can specify a different mount point.

2. To mount the new virtual hard disk to the specified mount point, enter:

   ::

       mount /dev/hdc1 /mnt/hdc1

When you mounted the virtual hard disk, you can use its space in your virtual machine.

.. _Configuring Virtual Devices:

Configuring Virtual Devices
^^^^^^^^^^^^^^^^^^^^^^^^^^^

In Virtuozzo, you can use the ``--device-set`` option of the ``prlctl set`` command to configure the parameters of an existing virtual device. As a rule, the process of configuring the device properties includes two steps:

1. Finding out the name of the device you want to configure.

2. Running the ``prlctl set`` command to configure the necessary device properties.

Finding Out Device Names

To configure a virtual device, you need to specify its name when running the ``prlctl set`` command. If you do not know the device name, you can use the ``prlctl list`` command to learn it. For example, to obtain the list of virtual devices in the virtual machine ``MyVM``, run this command:

::

    # prlctl list --info MyVM
    ...
    Hardware:
      cpu cpus=2 VT-x accl=high mode=32 ioprio=4 iolimit='0'
      memory 1024Mb
      video 32Mb 3d acceleration=off vertical sync=yes
      hdd0 (+) scsi:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk.hdd' type='expanded' subtype=virtio-scsi
      hdd1 (+) scsi:1 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded' subtype=virtio-scsi
      cdrom0 (+) scsi:1 image='' subtype=virtio-scsi
      usb (+)
      net0 (+) dev='vme426f6594' network='Bridged' mac=001C426F6594 card=virtio
    ...

All virtual devices currently available to the virtual machine are listed under ``Hardware``. In our case the virtual machine ``MyVM`` has the following devices: 2 CPUs, main memory, video memory, a floppy disk drive, 2 hard disk drives, a CD/DVD-ROM drive, a USB controller, and a network card.

Configuring Virtual Devices

Once you know the virtual device name, you can configure its properties. For example, you can execute the following command to configure the current type of the virtual disk ``hdd1`` in the virtual machine ``MyVM`` from SCSI to IDE:

::

    # prlctl set MyVM --device-set hdd1 --iface ide
    Configured hdd1 (+) ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded'
    The VM has been successfully configured.

To check that the virtual disk type has been successfully changed, use the ``prlctl list --info`` command:

::

    # prlctl list --info MyVM
    ...
    hdd1 (+) ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded'
    ...

Connecting and Disconnecting Virtual Devices

In Virtuozzo, you can connect or disconnect certain devices when a virtual machine is running. These devices include:

-  CD/DVD-ROM drives

-  floppy disk drives

-  network adapters

-  printer ports

-  serial ports

Usually, all virtual devices are automatically connected to a virtual machine when you create them. To disconnect a device from the virtual machine, you can use the ``prlctl set`` command. For example, the following command disconnects the CD/DVD-ROM drive ``cdrom0`` from the virtual machine ``MyVM``:

::

    # prlctl set MyVM --device-disconnect cdrom0
    Disconnect device: cdrom0
    The VM has been successfully configured.

To connect the CD/DVD-ROM drive back, you can run the following command:

::

    # prlctl set MyVM --device-connect cdrom0
    Connect device: cdrom0
    The VM has been successfully configured.

.. _Deleting Devices:

Deleting Devices
^^^^^^^^^^^^^^^^

You can delete a virtual device that you do not need any more in your virtual machine using the ``--device-del`` option of the ``prlctl set`` command. The options responsible for removing particular devices are listed in the following table:

+--------------------+--------------------------------------------------------+
| Option             | Description                                            |
+====================+========================================================+
| ``hdd``            | Deletes the specified hard disk drive from the virtual |
|                    | machine.                                               |
|                    |                                                        |
|                    | .. note:: IDE and SCSI disks can be removed from       |
|                    |     stopped virtual machines only.                     |
+--------------------+--------------------------------------------------------+
| ``cdrom``          | Deletes the specified CD/DVD-ROM drive from the        |
|                    | virtual machine.                                       |
+--------------------+--------------------------------------------------------+
| ``net``            | Deletes the specified network adapter from the virtual |
|                    | machine.                                               |
+--------------------+--------------------------------------------------------+
| ``fdd``            | Deletes the floppy disk drive from the virtual         |
|                    | machine.                                               |
+--------------------+--------------------------------------------------------+
| ``serial``         | Deletes the specified serial port from the virtual     |
|                    | machine.                                               |
+--------------------+--------------------------------------------------------+
| ``usb``            | Deletes the USB controller from the virtual machine.   |
+--------------------+--------------------------------------------------------+

As a rule deleting a virtual device involves performing two operations:

1. Finding out the name of the device to be deleted.

2. Deleting the device from the virtual machine.

Finding Out the Device Name

To remove a virtual device, you need to specify its name when running the ``prlctl set`` command. If you do not know the device name, you can use the ``prlctl list`` command to learn it. For example, to obtain the list of virtual devices in the ``MyVM`` virtual machine, run this command:

::

    # prlctl list --info MyVM
    ...
    Hardware:
      cpu cpus=2 VT-x accl=high mode=32 ioprio=4 iolimit='0'
      memory 1024Mb
      video 32Mb 3d acceleration=off vertical sync=yes
      hdd0 (+) scsi:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk.hdd' type='expanded' subtype=virtio-scsi
      hdd1 (+) ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' type='expanded'
      cdrom0 (+) scsi:1 image='' subtype=virtio-scsi
      usb (+)
      net0 (+) dev='vme426f6594' network='Bridged' mac=001C426F6594 card=virtio
    ...

All virtual devices currently available to the virtual machine are listed under ``Hardware``. In our case the virtual machine ``MyVM`` has the following devices: 2 CPUs, main memory, video memory, a floppy disk drive, 2 hard disk drives, a CD/DVD-ROM drive, a USB controller, and a network card.

Deleting a Virtual Device

Once you know the virtual device name, you can remove it from your virtual machine. For example, you can execute the following command to remove the virtual disk ``hdd1`` from the virtual machine ``MyVM``:

::

    # prlctl set MyVM --device-del hdd1
    Remove the hdd1 device.
    The VM has been successfully configured.

If you do not want to permanently delete a virtual device, you can temporarily disconnect it from the virtual machine using the ``--disable`` option.

.. _Making Screenshots:

Making Screenshots
~~~~~~~~~~~~~~~~~~

When a virtual machine stops responding to requests, you can check its state by capturing an image (or screenshot) of its screen with the ``prlctl capture`` command. A screenshot is saved in PNG format. 

.. note:: You can take screenshots of running virtual machines only. 

To take a screenshot of the ``MyVM`` virtual machine screen and save it to the ``/usr/screenshots/image1.png`` file:

1. Make sure that the virtual machine is running:

::

    # prlctl list
    UUID                                    STATUS    IP_ADDR        T   NAME
    {b2de86d9-6539-4ccc-9120-928b33ed31b9}  running   10.10.100.1    VM  MyVM

2. Take the virtual machine screenshot:

::

    # prlctl capture MyVM --file /usr/screenshots/image1.png

If the ``--file`` option is not specified, a screenshot is dumped to the command output.

3.  Check that the ``image1.png`` file has been successfully created:

::

    # ls /usr/screenshots/
    image1.png

.. _Assigning USB Devices to Virtual Machines:

Assigning USB Devices to Virtual Machines
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In Virtuozzo, you can assign a USB device to a virtual machine so that the device is automatically connected to the virtual machine when you connect the USB device to the hardware node or start the virtual machine. To assign a USB device to a virtual machine, you need to specify two parameters:

1. ID of the USB device. To get this information, use the ``prlsrvctl info`` command, for example:

   ::

       # prlsrvctl info
       ...
       Hardware info:
                hdd                                            '/dev/sda'
       hdd-part NTFS                                           '/dev/sda2'
       hdd-part Linux                                          '/dev/sda3'
       hdd-part Linux                                          '/dev/sda5'
       hdd-part Linux swap                                     '/dev/sda6'
        cdrom Optiarc DVD RW AD-7260S                     '/dev/scd0'
         net enp0s5                                        'enp0s5'
         usb Broadcom - USB Device 3503                  '2-1.4.3|0a5c|3503|full|KM|Empty'
         sb Broadcom - USB Device 3502                   '2-1.4.2|0a5c|3502|full|KM|Empty'
         usb LITEON Technology - USB Multimedia Keyboard '1-1.6|046d|c312|low|KM|Empty'
         serial /dev/ttyS0                                     '/dev/ttyS0'
        serial /dev/ttyS1                                      '/dev/ttyS1'

   All USB devices available on the hardware node are listed in the Hardware info section and start with ``usb``.

2. ID of the virtual machine. To get this information, use the ``prlctl list --info`` command, for example:

   ::

       # prlctl list --info
       ID: {d8d516c9-dba3-dc4b-9941-d6fad3767035}
       Name: Windows 7
       ...

   The first line in the command output indicates the virtual machine ID; in our case, it is ``{d8d516c9-dba3-dc4b-9941-d6fad3767035}``.

Once you know the USB device and virtual machine IDs, you can use the ``prlsrvctl usb set`` command to assign the USB device to the virtual machine. For example:

::

    # prlsrvctl usb set '1-1.6|046d|c312|low|KM|Empty' {d8d516c9-dba3-dc4b-9941-\
    d6fad3767035}
    The server has been successfully configured.

This command assigns the USB device ``LITEON Technology - USB Multimedia Keyboard with ID '1-1.6|046d|c312|low|KM|Empty'`` to the virtual machine with ID ``{d8d516c9-dba3-dc4b-9941-d6fad3767035}``. When running the command, remember to specify the single quotes and curly brackets with the USB device and virtual machine IDs, respectively.

To check that the USB device has been successfully assigned to the virtual machine, use the ``prlsrvctl usb list`` command:

::

    # prlsrvctl usb list
    Broadcom - USB Device 3503                  '2-1.4.3|0a5c|3503|full|KM|Empty'
    Broadcom - USB Device 3502                  '2-1.4.2|0a5c|3502|full|KM|Empty'
    LITEON Technology - USB Multimedia Keyboard '1-1.6|046d|c312|low|KM|Empty' \
          {d8d516c9-dba3-dc4b-9941-d6fad3767035}

The command output shows that the USB device with ID ``'1-1.6|046d|c312|low|KM|Empty'`` is now associated with the virtual machine with ID ``{d8d516c9-dba3-dc4b-9941-d6fad3767035}``. This means that the device is automatically connected to the virtual machine every time you start this virtual machine and connect the device to the hardware node.

To remove the assignment of the USB device with ID ``'1-1.6|046d|c312|low|KM|Empty'``, use the ``prlsrvctl usb del`` command:

::

    # prlsrvctl usb del '1-1.6|046d|c312|low|KM|Empty'
    The server has been successfully configured.

When assigning USB devices to virtual machines, keep in mind the following:

-  You cannot migrate a running virtual machine having one or more USB devices assigned.

-  After migrating a stopped virtual machine, all its assignments are lost.

-  All USB assignments are preserved if you restoring a virtual machine to its original location and are lost otherwise.

-  The USB device assignment to a virtual machine is created for the user currently logged in to the system.

.. _Configuring IP Address Ranges for Host-Only Networks:

Configuring IP Address Ranges for Host-Only Networks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All virtual machines connected to networks of the host-only type receive their IP addresses from the DHCP server. This DHCP server is set up during the Virtuozzo installation and includes by default IP addresses from 10.37.130.1 to 10.37.130.254. You can redefine the default IP address range for host-only networks and make virtual machines get their IP addresses from different IP address ranges. For example, you can run the following command to set the start and end IP addresses for the ``Host-Only`` network (this network is automatically created during the Virtuozzo installation) to 10.10.11.1 and 10.10.11.254, respectively:

::

    # prlsrvctl net set Host-Only --ip-scope-start 10.10.11.1 --ip-scope-end 10.10.11.254

You can also specify a custom IP address range directly when creating a new network of the host-only type. Assuming that you want to create a network with the ``Host-Only2`` name and define for this network the IP addresses range from 10.10.10.1 to 10.10.10.254, you can execute the following command:

::

    # prlsrvctl net add Host-Only2 -t host-only --ip-scope-start 10.10.10.1 --ip-scope-\
    end 10.10.10.254

When working with IP address ranges, pay attention to the following:

-  The start and end IP addresses of an IP address range must belong to the same subnetwork.

-  IP address ranges can be defined for each network of the host-only type separately. For example, you can set the IP address range from 10.10.11.1 to 10.10.11.254 for the ``Host-Only`` network and from 10.10.10.1 to 10.10.10.254 for the ``Host-Only2`` network.

.. _Configuring Virtual Machine Crash Mode:

Configuring Virtual Machine Crash Mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In Virtuozzo 7, you can configure a virtual machine behavior after the guest OS crash: restart or pause. By default, when a virtual machine fails, a crash dump is created and sent in the problem report to the Virtuozzo technical support team, and the virtual machine is restarted with the same configuration.

To address the problem yourself, you can switch the virtual machine crash mode to ``pause`` using the ``prlctl set`` command. For example:

::

    # prlctl set MyVM --on-crash pause

The virtual machine resources will be preserved to allow analysis and its crash dump will be sent in the problem report.

As crash dumps can take up significant disk space and lead to the whole server malfunction, the crash mode is automatically switched to ``pause``, if a virtual machine fails more than three times within twenty-four hours since the last crash. 

If you want to skip creating the crash dump and sending the problem report, add ``:no-report`` to the command. For example:

::

    # prlctl set MyVM --on-crash restart:no-report
