How to automate and deploy Linux VMs on Windows, Mac, and Linux?

First published: Wednesday, August 28, 2024 | Last updated: Wednesday, August 28, 2024

Automate deployment of a variety of Linux VMs on Windows, Mac, and Linux operating systems using VirtualBox, VMware, and Vagrant.


In this blog post, you were presented with a straightforward method for automating the creation, deployment, and administration of various Linux-based virtual machines on Windows, Mac, and Linux operating systems. This was achieved through the utilization of type-2 hosted hypervisor software such as VirtualBox and VMware, as well as automation tools like Vagrant, enabling the seamless and automated deployment of Linux VMs.

Make sure to carefully review the entire blog post for step-by-step instructions on how to perform automated deployment of Linux virtual machines on Windows, Mac, and Linux operating systems.

Install and configure VirtualBox on Windows, Mac, and Linux

The following resources will guide you through the process of installing and configuring VirtualBox on Windows, Mac, or Linux operating systems.

  1. How to install and configure VirtualBox on Windows, Mac, and Linux?

Install and configure Git on Windows, Mac, and Linux

Please refer to the following articles for step-by-step instructions on how to download, install, and configure Git on Windows, Mac, or Linux operating systems.

  1. How to install and configure Git on Windows, Mac, and Linux?

Install Vagrant on Windows, Mac, and Linux

Below are the links to the articles that provide detailed step-by-step instructions for downloading and installing Vagrant on Windows, Mac, or Linux operating systems.

  1. How to install Vagrant on Windows, Mac, and Linux?

Setup our Linux starter-kit from GitHub

At SloopStash, we are proud to offer our own open source Linux starter-kit repository on GitHub. This repository is designed to provide robust support for a wide range of Linux-based operating systems including CentOS Linux, Ubuntu Linux, Amazon Linux, Alma Linux, Rocky Linux, and other similar equivalents. Additionally, we are committed to creating, uploading, and maintaining our VM images for these operating systems in the Vagrant Cloud. Our comprehensive Linux starter-kit has been meticulously curated to encompass all the essential components needed for building and running any Linux-based virtual machine.

Windows

Below are the steps you can use to setup our Linux starter-kit while using the Windows operating system.

  1. Open the Git Bash terminal in administrator mode.
  2. Execute the below commands in the Git Bash terminal to setup our Linux starter-kit.
# Download Linux starter-kit from GitHub to local filesystem path.
$ git clone https://github.com/sloopstash/kickstart-linux.git /opt/kickstart-linux

Mac

Here are the instructions for setting up our Linux starter-kit on a Mac operating system.

  1. Open the terminal.
  2. Execute the below commands in the terminal to setup our Linux starter-kit.
# Download Linux starter-kit from GitHub to local filesystem path.
$ sudo git clone https://github.com/sloopstash/kickstart-linux.git /opt/kickstart-linux

# Change ownership of Linux starter-kit directory.
$ sudo chown -R $USER /opt/kickstart-linux

Linux

You can use the following commands to setup our Linux starter-kit in any Linux-based operating system.

  1. Open the terminal.
  2. Execute the below commands in the terminal to setup our Linux starter-kit.
# Download Linux starter-kit from GitHub to local filesystem path.
$ sudo git clone https://github.com/sloopstash/kickstart-linux.git /opt/kickstart-linux

# Change ownership of Linux starter-kit directory.
$ sudo chown -R $USER:$USER /opt/kickstart-linux

Configure environment variables on Windows, Mac, and Linux

Before initiating the automated deployment of a Linux VM, it is essential to carefully configure the following environment variables in your Windows, Mac, or Linux terminals. These variables play a critical role in specifying the operating system (CentOS Linux, Ubuntu Linux, Amazon Linux, Alma Linux, or Rocky Linux), processor architecture (AMD64 or ARM64), edition (server or desktop), and hypervisor (VirtualBox or VMware) that will be used for the Linux VM deployment.

Supported environment variables

# Allowed values for $OS_NAME variable.
* centos-linux-7
* ubuntu-linux-18-04
* ubuntu-linux-22-04
* amazon-linux-2
* alma-linux-8
* alma-linux-9
* rocky-linux-8
* rocky-linux-9

# Allowed values for $OS_ARCHITECTURE variable.
* amd64
* arm64

# Allowed values for $OS_EDITION variable.
* server
* desktop

# Allowed values for $HYPERVISOR variable.
* virtualbox
* vmware

Set environment variables

In this section, we set environment variables for the build, deployment, and automation of the Ubuntu Linux 22.04 AMD64 server operating system using VirtualBox hypervisor. Similarly, the environment variables can be modified to automate the VM deployment for different Linux variants and versions as mentioned above.

# Store environment variables.
$ export OS_NAME=ubuntu-linux-22-04
$ export OS_ARCHITECTURE=amd64
$ export OS_EDITION=server
$ export HYPERVISOR=virtualbox

Deploy and manage Linux VMs with Vagrant automation

Vagrant provides the ability to easily create, start, stop, and remove virtual machines using straightforward commands. All the necessary configurations for the automated deployment of Linux VMs are included in our Linux starter-kit. This means that by executing the appropriate Vagrant commands, you can efficiently build, deploy, and automate Linux VMs.

If you encounter any issues while deploying Linux VMs, please raise an issue in our Linux starter-kit on GitHub.

Windows

You can use the below commands to create, deploy, and automate Linux VMs on the Windows operating system using Vagrant.

  1. Open the Git Bash terminal in administrator mode.
  2. Execute the below commands in the Git Bash terminal to build, deploy, and automate Linux VMs.
# Switch to Linux starter-kit directory.
$ cd /opt/kickstart-linux

# Boot Linux VM using Vagrant.
$ VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant up

# SSH to Linux VM using Vagrant.
$ VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant ssh

# Exit from Linux VM.
$ exit

# Halt Linux VM using Vagrant.
$ VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant halt

# Provision Linux VM using Vagrant.
$ VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant provision

# Destroy Linux VM using Vagrant.
$ VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant destroy

Mac and Linux

You can use the following commands to build, deploy, and automate Linux VMs on a Mac or Linux operating system using Vagrant.

  1. Open the terminal.
  2. Execute the below commands in the terminal to build, deploy, and automate Linux VMs.
# Switch to Linux starter-kit directory.
$ cd /opt/kickstart-linux

# Boot Linux VM using Vagrant.
$ sudo VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant up

# SSH to Linux VM using Vagrant.
$ sudo VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant ssh

# Exit from Linux VM.
$ exit

# Halt Linux VM using Vagrant.
$ sudo VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant halt

# Provision Linux VM using Vagrant.
$ sudo VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant provision

# Destroy Linux VM using Vagrant.
$ sudo VAGRANT_CWD=./vagrant/$OS_NAME/$HYPERVISOR/$OS_ARCHITECTURE/$OS_EDITION vagrant destroy