.. _Performing Initial Configuration of Virtual Machines and Containers:

Performing Initial Configuration of Virtual Machines and Containers
-------------------------------------------------------------------

Before you start using a newly created virtual machine or container, you will need to configure it. This section describes the main configuration steps.

.. _Using cloud-init for Virtual Machine Guest Initialization:

Using cloud-init for Virtual Machine Guest Initialization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Virtuozzo supports VM guest initialization via cloud-init, so you can perform some of the initial configuration tasks described further in this section on stopped virtual machines. The supported tasks are: mounting the guest tools image, setting user names and passwords, and configuring network settings.

The changes resulting from performing the above tasks are not applied to the VM immediately but rather saved as instructions to be carried out when the guest OS with cloud-init is loading. So when you run a corresponding command (e.g., ``prlctl set --userpasswd``), the following happens: the bundled image with cloud-init instructions is copied to the VM home path, a CD-ROM device is added to the VM, and the image is mounted to said CD-ROM. However, the changes (e.g., to the user name and password) will only be applied after you install and start loading the guest OS.

As mentioned above, you will need cloud-init installed in a guest OS for the feature to work. For Linux guests, the easiest way to get cloud-init is to install a "cloud-enabled" distribution that already comes with it. You can also install cloud-init manually (e.g., by running ``yum install cloud-init`` on CentOS 7). For Windows guests, you can create your own distributions with cloud-init or install it manually. The Windows version is available at https://cloudbase.it/cloudbase-init/.

.. _Installing Virtuozzo Guest Tools:

Installing Virtuozzo Guest Tools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Virtuozzo guest tools enable you to configure running virtual machines from the physical host. These operations include:

-  Running commands in VMs with the ``prlctl exec`` command.

-  Setting passwords for users in VMs with the ``prlctl set --userpasswd`` command. If the user does not exist, it will be created.

-  Obtaining and changing VM network settings.

In addition, installing Virtuozzo guest tools schedules weekly automatic "trimming" of filesystems in Linux guests by means of the ``fstrim`` service. It reclaims unused storage space by discarding data blocks unused by VM's filesystem. If you disable the service, it will not be re-enabled by future updates of Virtuozzo guest tools. In Windows guests, Storage Optimizer does the same periodic job by default.

.. note:: If a node is in a Virtuozzo Storage cluster that provides data redundancy by replication, automatic compacting (trimming) of the filesystem(s) that store data replicas is disabled. In case data redundancy is provided by erasure coding, trimming is enabled.

To install Virtuozzo guest tools in a Linux or Windows virtual machine ``MyVM``, do the following:

1. Run the ``prlctl installtools`` command on the host. For example:

   ::

       # prlctl installtools MyVM

   The guest tools image shipped with Virtuozzo will be mounted to the virtual machine's optical drive.

2. Log in to the virtual machine and do the following:

   -  Inside a Linux VM, create a mount point for the optical drive with the guest tools image and run the installer:

      ::

          # mount /dev/cdrom /mnt/cdrom
          # bash /mnt/cdrom/install

   -  Inside a Windows VM, if autorun is enabled, the installer will run automatically. Otherwise, navigate to the optical drive and launch the installer manually.

    .. note:: Virtuozzo guest tools rely on QEMU guest agent which is installed alongside the tools. The agent daemon/service (``qemu-ga``) must be running for the tools to work.

.. _Configuring Network Settings:

Configuring Network Settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To make virtual machines and containers accessible from the network, you need to assign valid IP addresses to them and configure DNS servers. The session below illustrates setting these parameters for the virtual machine ``MyVM`` and the container ``MyCT``:

-  Assigning IPv4 and IPv6 addresses:

   ::

       # prlctl set MyVM --device-set net0 --ipadd 10.0.186.100/24
       # prlctl set MyVM --device-set net0 --ipadd 1fe80::20c:29ff:fe01:fb07
       # prlctl set MyCT --ipadd 10.0.186.101/24
       # prlctl set MyCT --ipadd fe80::20c:29ff:fe01:fb08

   ``net0`` in the commands above denotes the network card in the virtual machine to assign the IP address to. You can view all network cards of a virtual machine using the ``prlctl list <VM_name> -i`` command.

-  Setting DNS server addresses:

   ::

       # prlctl set MyVM --nameserver 192.168.1.165
       # prlctl set MyCT --nameserver 192.168.1.165

.. note::

       1. You can configure the network settings only for virtual machines that have Virtuozzo guest tools installed.

       2. To assign network masks to containers operating in the ``venet0`` network mode, you must set the ``USE_VENET_MASK`` parameter in the ``/etc/vz/vz.conf`` configuration file to ``yes``.

.. _Setting Passwords for Virtual Machines and Containers:

Setting Passwords for Virtual Machines and Containers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In Virtuozzo, you can use the ``--userpasswd`` option of the ``prlctl set`` command to create new accounts in your virtual machines and containers directly from the hardware node. The created account can then be used to log in to the virtual machine or container. The easiest way of doing it is to run this command:

::

    # prlctl set MyCT --userpasswd user1:2wsx123qwe

This command creates the ``user1`` account in the container ``MyCT`` and sets the ``2wsx123qwe`` password for it. Now you can log in to the container as ``user1`` and administer it in the same way you would administer a standalone server: install additional software, add users, set up services, and so on.

The ``prlctl set`` command can also be used to change passwords for existing accounts in your virtual machines and containers. For example, to change the password for ``user1`` in the container ``MyCT`` to ``0pi65jh9``, run this command:

::

    # prlctl set MyCT --userpasswd user1:0pi65jh9

When setting passwords for virtual machines and containers, keep in mind the following:

-  You can manage user accounts only inside virtual machines that have Virtuozzo guest tools installed.

-  You should use passwords that meet the minimum length and complexity requirements of the respective operating system. For example, for Windows Server 2008, a password must be more than six characters in length and contain characters from three of the following categories: uppercase characters, lowercase characters, digits, and non-alphabetic characters.

-  You should not create accounts with empty passwords for virtual machines and containers running Linux operating systems.

.. _Setting Startup Parameters:

Setting Startup Parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``prlctl set`` command allows you to define the ``autostart`` startup parameter for virtual machines and containers. Setting this parameter to ``on`` makes your virtual machine or container automatically boot at the physical server startup. For example, to enable the container ``MyCT`` and the virtual machine ``MyVM`` to automatically start on your server boot, you can execute the following commands:

-  For the container ``MyCT``:

   ::

       # prlctl set MyCT --autostart on

-  For the virtual machine ``MyVM``:

   ::

       # prlctl set MyVM --autostart on

Notice that the ``autostart`` parameter will have effect only on the next server startup.

