2.14.2.3. Configuring Virtual Devices

In OpenVZ, 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
  fdd0 () real='/dev/fd0' state=disconnected
  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 () ide:1 real='Default CD/DVD-ROM'
  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 OpenVZ, 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.