Customizing Windows VMs using cloudbase-init – KVM

If you had the chance to go through Chapter 9, Customizing a Virtual Machine with cloud-init, we discussed a tool called cloud-init. What we used it for was guest operating system customization, specifically for Linux machines. cloud-init is heavily used in Linux-based environments, specifically in Linux-based clouds, to perform initialization and configuration of cloud VMs.

The idea behind cloudbase-init is the same, but it’s aimed at Windows guest operating systems. Its base services start up when we boot a Windows guest operating system instance, as well as read through the configuration information and configure/initialize it. We are going to show a couple of examples of cloudbase-init operations a bit later in this chapter.

What can cloudbase-init do? The list of features is quite long, as cloudbase-init has a modular approach at its core, so it offers many plugins and interpreters, which can be used to further its reach:

  • It can execute custom commands and scripts, most commonly coded in PowerShell, although regular CMD scripts are also supported.
  • It can work with PowerShell remoting and the Windows Remote Management (WinRM) service.
  • It can manage and configure disks, for example, to do a volume expansion.
  • It can do basic administration, including the following:

    a) Creating users and passwords

    b) Setting up a hostname

    c) Configuring static networking

    d) Configuring MTU size

    e) Assigning a license

    f) Working with public keys

    g) Synchronizing clocks

We mentioned earlier that our Windows Server 2019 VM is going to be used for cloudbase-init customization, so that’s our next subject. Let’s prepare our VM for cloudbase-init. We are going to achieve that by downloading the cloudbase-init installer and installing it. We can find the cloudbase-init installer by pointing our internet browser at https://cloudbase-init.readthedocs.io/en/latest/intro.html#download. The installation is simple enough, and it can work both in a regular, GUI fashion and silently. If you’re used to using Windows Server Core or prefer silent installation, you can use the MSI installer for silent installation by using the following command:

msiexec /i CloudbaseInitSetup.msi /qn /l*v log.txt

Make sure that you check the cloudbase-init documentation for further configuration options as the installer supports additional runtime options. It’s located at https://cloudbase-init.readthedocs.io/en/latest/.

Let’s stick with the GUI installer as it’s simpler to use, especially for a first-time user. First, the installer is going to ask about the license agreement and installation location – just the usual stuff. Then, we’re going to get the following options screen:

Figure 10.2 – Basic configuration screen

Figure 10.2 – Basic configuration screen

What it’s asking us to do is to give permission to create the cloudbase-init configuration files (both cloudbase-init-unattend.conf and cloudbase-init.conf) with this specific future user in mind. This user will be a member of the local Administrators group and will be used for logging in when we start using the new image. This will be reflected in both of our configuration files, so if we select Admin here, that’s the user that’s going to get created. It’s also asking us whether we want the cloudbase-init service to be run as a LocalSystem service, which we selected to make the whole process easier. The reason is really simple – this is the highest level of permission that we can give to our cloudbase-init services so that they can execute its operations. Translation: the cloudbase-init service will then be run as a LocalSystem service account, which has unlimited access to all local system resources.

The last configuration screen is going to ask us about running sysprep. Usually, we don’t check the Run sysprep to create a generalized image box here, as we first need to create a cloudbase-init customization file and run sysprep after that. So, leave the following window open:

Figure 10.3 – The cloudbase-init installation wizard finishing up

Figure 10.3 – The cloudbase-init installation wizard finishing up

Now that the cloudbase-init services are installed and configured, let’s create a customization file that’s going to configure this VM by using cloudbase-init. Again, make sure that this configuration screen is left open (with the completed setup wizard) so that we can easily start the whole process when we finish creating our cloudbase-init configuration.

It will gives you output similar to below:

It will gives you output similar to below:

It will gives you output similar to below:

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

two × five =