How to Automate VM Building on Windows Machine — Part 1

Sathiyaraj Sridhar
4 min readJun 26, 2020

--

This article helps you to install and build VM on Windows machine using VirtualBox, Vagrant and Git Bash.

VirtualBox Setup

VirtualBox is a hypervisor that helps you to build Virtual Machine on your host machine.

  • Once you completed, you can see the VirtualBox on your Desktop. You can also find it in the Windows starter list.

Suppose! If you are using Hyper-V hypervisor, first, you need to disable it.

# Here are the steps to disable Hyper-V.# Using GUI
Control Panel:
Programs:
Programs and Feature:
Turn Windows Features on or off:
Hyper-V: false
# Using CLI - Windows Power Shell
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

In case, your host machine does not support VM creation then you need to disable Secure Boot on BIOS setup. BIOS setup menu varies by computer. So check and disable Secure Boot according to your computer model.

Suppose you are prompted to install the Microsoft Visual C++ 2019 Redistributable Package. Please visit the official Microsoft documentation and download the package corresponding to your system type. Afterward, restart the installation process. If you are unsure how to determine your system type, please run the systeminfo command in the Command Prompt.

Vagrant Setup

Vagrant is a tool developed by HashiCorp company that helps you to automate VM creation, deletion, provisioning etc.

  • Vagrant won’t provide you User Interface, So you can’t see an icon in the dashboard, and also in the Windows starter list.
  • But you can verify Vagrant in the Command Prompt(CMD) or the Git Bash. Just type the following command to verify Vagrant.
# Command Prompt
C:\Users\Bob> vagrant --version
Vagrant 2.4.1
# Git Bash
$ vagrant --version
Vagrant 2.4.1

Git Bash Setup

Git Bash is a tool that provides you to run Linux commands on Windows machine. I have tried WSL, Unfortunately, It won’t work for Vagrant, So I prefered Git Bash.

  • Once you completed, you can see the Git Bash on the Windows starter list.
  • Just open Git Bash and verify some Linux commands.
$ pwd
/c/Users/Bob
$ vagrant --version
Vagrant 2.4.1
$ git --version
git version 2.44.0.windows.1
  • Once everything works fine, you need to configure your Git username and email address. So, Just run the following commands.
$ git config --global user.name "your-username"
$ git config --global user.email "your-email@gmail.com"

Anybody who comes from Linux background and you want to use VirtualBox and Vagrant on Windows machine, Git Bash is a tool that gives you native terminal experience.

Build VM using Vagrant

Building Virtual Machine(VM) is simple with Vagrant. Here, I am going to create a Fedora 39 Cloud Base VM, but you could choose your preferred Vagrant boxes here.

Run the following commands on the Git Bash.

# Create and switch to the project directory.
$ mkdir project-dir
$ cd project-dir
# Initialize Fedora 39 Cloud Base VM creation.
$ vagrant init fedora/39-cloud-base --box-version 39.20231031.1
# For run the VM
$ vagrant up
# For SSH into the VM
$ vagrant ssh
# For stop the VM
$ vagrant halt
# For delete the VM
$ vagrant destroy

Now, you realized the effective and easiest way of building VM on Windows machine with the power of Vagrant and Git Bash.

To configure VM settings such as increasing CPU count and memory size, setting the hostname, and assigning a private static IP address, please continue reading Part 2 of the article.

I hope it helps you. Thank you.

--

--