.. _Managing Virtual Disks:

Managing Virtual Disks
----------------------

In Virtuozzo, you can manage virtual disks as follows:

-  resize,

-  compact (reduce their size on the physical hard drive),

-  change interface.

All these operations are described in the following subsections in detail.

.. _Resizing Virtual Disks:

Resizing Virtual Disks
~~~~~~~~~~~~~~~~~~~~~~

.. warning:: Only use ``prl_disk_tool`` on disks of stopped virtual machines.

You can resize virtual hard disks of your virtual machines or containers with the ``prl_disk_tool resize --size`` command. For example:

.. only:: latex

   ::

       # prl_disk_tool resize --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
       harddisk.hdd --size 30G

.. only:: html

   ::

       # prl_disk_tool resize --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk.hdd --size 30G

When resizing virtual disks, keep in mind the following:

- The virtual machine that uses the virtual disk to be resized must not have any snapshots.

- The virtual disk size shown inside the virtual machine or container may differ from the size the virtual disk occupies on server's physical disk.

- In case disk size is increased, the added disk space is added as unallocated. You can use standard tools of the guest OS to allocate the added space.

- You cannot reduce XFS filesystems (the default choice for CentOS 7 and Red Hat Enterprise Linux 7).

.. _Checking the Minimum Disk Capacity:

Checking the Minimum Disk Capacity
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If, before reducing disk capacity, you want to know the minimum size to which it can be reduced, use the ``prl_disk_tool resize --info`` command. For example, if the disk ``hdd0`` of the virtual machine ``MyVM`` is emulated by the image ``/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk.hdd``, run the following command:

.. only:: latex

   ::

       # prl_disk_tool resize --info --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065- \
       8fef6178bc5b/harddisk.hdd
       Disk information:
       ...
       Minimum: 2338M
       ...

.. only:: html

   ::

       # prl_disk_tool resize --info --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk.hdd
       Disk information:
       ...
       Minimum: 2338M
       ...

.. _Compacting Disks:

Compacting Disks
~~~~~~~~~~~~~~~~

.. warning:: Only use ``prl_disk_tool`` on disks of stopped virtual machines.

In Virtuozzo, you can reduce the space your virtual machines and containers occupy on the physical server's disk drive by compacting their virtual disks. Doing so frees up server disk space for hosting more virtual machines and containers.

To compact a virtual disk, you can use the ``prl_disk_tool compact`` command. For example, to compact the disk ``/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk.hdd``, run this command:

.. only:: latex

   ::

       # prl_disk_tool compact --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
       harddisk.hdd/

.. only:: html

   ::

       # prl_disk_tool compact --hdd /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/harddisk.hdd/

To check the space that was freed by compacting the virtual disk, you can use standard Linux utilities (for example, ``df``).

.. _Managing Virtual Machine Disk Interfaces:

Managing Virtual Machine Disk Interfaces
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, any virtual machine is created with a SCSI (Small Computer System Interface) virtual hard disk. If necessary, you can change the interface type of a disk from SCSI to IDE (Integrated Drive Electronics) or VirtIO. For example, to change the interface type of the default disk (``hdd0``) in the virtual machine ``MyVM`` from SCSI to IDE, you can run the following command:

::

    # prlctl set MyVM --device-set hdd0 --iface ide
    The VM has been successfully configured

To check that the interface type has been successfully changed, use this command:

::

    # prlctl list -i MyVM | grep hdd0
    Boot order: hdd0 cdrom0 net0
    hdd0 (+) ide:0 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk.hdd'

The command output shows that now the interface type of the ``hdd0`` disk is IDE.

You can create additional disks for the virtual machine ``MyVM``. For example, to add a new disk of the IDE type to the virtual machine, execute the following command:

::

    # prlctl set MyVM --device-add hdd --iface ide
    Creating hdd1 (+) ide:1 image='/vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/ \
    harddisk1.hdd' 65536Mb
    Create the expanding image file, 65536Mb...
    The VM has been successfully configured.

You can also create a VirtIO disk. To do this, specify ``--iface virtio`` instead of ``--iface ide`` in the command above. If you omit the ``--iface`` option, a SCSI disk is created by default.

The maximum number of devices (both virtual hard disks and CD/DVD-ROM drives) you can add to a virtual machine is given below:

-  4 IDE devices

-  8 SCSI devices

At any time, you can remove the ``hdd1`` disk from the virtual machine ``MyVM``:

::

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

.. note::

    1. Virtual IDE and SCSI disks can be added to or removed from stopped virtual machines only.

    2. You need to initialize a newly added disk before you can start using it. To initialize the disk, use standard means provided by your guest operating system.

