2.15. Performing Virtual Machine-specific Operations

This section focuses on operations specific to virtual machines.

2.15.1. 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.

2.15.2. 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

2.15.2.1. 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:

  • To a virtual machine, you can connect up to:
    • 4 IDE devices (virtual disks or CD/DVD-ROM drives),
    • 15 SCSI devices (virtual disks or CD/DVD-ROM drives),
    • 15 VirtIO virtual disks.
  • 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.

2.15.2.1.1. 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

2.15.2.2. 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.

2.15.2.2.1. 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.

2.15.2.2.2. 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.

2.15.2.3. 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.

2.15.2.3.1. 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.

2.15.2.3.2. Configuring Virtual Device Properties

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'
...

2.15.2.3.3. 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.

2.15.2.4. 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

Hard disks can be removed only from stopped virtual machines.

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.

2.15.2.4.1. 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 details, see Finding Out Device Names).

2.15.2.4.2. 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.

2.15.3. 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
    

2.15.4. 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.

2.15.5. 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