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

2.2.1. Using cloud-init for Virtual Machine Guest Initialization

Virtuozzo Hybrid Server 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: installing guest tools, 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/.

2.2.2. Installing Virtuozzo Guest Tools

Virtuozzo guest tools enable you to configure running virtual machines from the physical host. With tools you can:

  • Run commands in VMs with the prlctl exec command.

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

  • Obtain and change VM network settings.

In addition, installing Virtuozzo guest tools schedules weekly automatic “trimming” of file systems in Linux guests by means of the fstrim service. It reclaims unused storage space by discarding data blocks unused by VM’s file system. 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 file system(s) that store data replicas is disabled. In case data redundancy is provided by erasure coding, trimming is enabled.

It is recommended to have cloud-init installed in the guest OS (see the previous section). In this case, you only need to do the following:

  1. Mount the guest tools image shipped with Virtuozzo Hybrid Server to the virtual machine’s optical drive. For example:

    # prlctl installtools MyVM
    
  2. Start the virtual machine:

    # prlctl start MyVM
    

Cloud-init will install the guest tools automatically.

If a VM guest OS does not have cloud-init, you can install Virtuozzo guest tools either automatically or manually.

To install the guest tools automatically without cloud-init:

  1. Make sure these requirements are met:

    • The vz-guest-tools-updater package is installed on the node.

    • In the /etc/vz/tools-update.conf file, the InstallTools parameter is set to true (default).

    • The virtual machine has the --tools-autoupdate parameter set to on (default).

  2. Stop the virtual machine before installing the guest tools:

    # prlctl stop MyVM
    
  3. Start vz-guest-tools-updater for the VM:

    # vz-guest-tools-updater MyVM
    
  4. Start the virtual machine:

    # prlctl start MyVM
    

Once the VM is launched, the vz-guest-tools-updater tool will start installing Virtuozzo guest tools, which can take several minutes.

Important

By default, the updater tool obtains the new guest tools from the official repository. If the repository is not accessible, the updater tool forcibly mounts the guest tools image to VM’s optical disk drive even if it is already in use.

To install the guest tools manually without cloud-init:

  1. Mount the guest tools image shipped with Virtuozzo Hybrid Server to the virtual machine’s optical drive. For example:

    # prlctl installtools MyVM
    
  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, launch the installer in the AutoPlay window.

      ../_images/guest_tools_autorun.png

      Otherwise right-click the optical drive in Explorer and click Install Virtuozzo Tools.

      ../_images/guest_tools_manual.png

Note the following:

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

  • If you find out that Virtuozzo guest tools are incompatible with some software inside a virtual machine, you can uninstall them from that VM (for details, refer to Uninstalling Virtuozzo Guest Tools from Virtual Machines).

2.2.3. 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 the following:

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

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

2.2.4. Setting Passwords for Virtual Machines and Containers

In Virtuozzo Hybrid Server, 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.

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