AlmaLinux OS is a Linux operating systemd forked from RHEL by the team behind CloudLinux. It is meant to be a free Linux OS developed in close co-operation with the community, and for the community. With Red Hat diverting the attention of CentOS development towards its vision around RHEL, AlmaLinux OS is an ideal option for your computing needs.
In this tutorial we’re going to generate Vagrant Boxes of AlmaLinux 8 OS for Libvirt/QEMU, Virtualbox and VMware using Packer and Ansible. During Vagrant box generation a virtual machine is created on the chosen provider hypervisor.
Installing Packer
Packer is an open source and free to use tool for creating golden images for multiple platforms from a single source configuration. Packer is installed on a Linux system from an archive binary file:
Debian / Ubuntu:
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install packer
CentOS / Rocky / Alma / RHEL:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install packer
Fedora:
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
sudo dnf -y install packer
Amazon Linux:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install packer
macOS:
brew tap hashicorp/tap
brew install hashicorp/tap/packer
Check if packer command can be executed from your shell:
$ packer version
Packer v1.9.4
Installing Ansible on Linux
These are the commands that you’ll use to install Ansible on Ubuntu/Debian, CentOS and Fedora Linux systems:
# Ubuntu / Debian
sudo apt update
sudo apt -y install ansible
# CentOS
sudo yum -y install epel-release
sudo yum -y install ansible
# Fedora
sudo dnf -y install ansible
# Arch Linux / Manjaro
sudo pacman -S ansible
Installing Virtualization Hypervisor of choice
Below are the hypervisors supported by Packer configuration that will be used.
- VirtualBox (for VirtualBox images only)
- VMWare Workstation (for VMWare images only)
- QEMU (for Libvirt images only)
Refer to the official hypervisor’s documentation for complete how-to installation guides.
We’ll cover the installation of QEMU / Libvirt for reference purposes.
# Ubuntu
sudo apt update
sudo apt -y install qemu-kvm libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin libguestfs-tools libguestfs-tools virt-top
# Debian
sudo apt update
sudo apt -y install qemu-kvm libvirt-daemon libvirt-daemon-system virtinst libosinfo-bin bridge-utils libguestfs-tools virt-top
# CentOS
sudo dnf -y install qemu-kvm libvirt virt-install virt-manager
sudo systemctl enable --now libvirtd
# Fedora
sudo dnf -y install qemu-kvm libvirt virt-install virt-manager
sudo systemctl enable --now libvirtd
# Arch Linux / Manjaro
sudo pacman -S git
Generate AlmaLinux OS KVM|VirtualBox|VMware Images using Packer
Install git if not available in your current system:
# Ubuntu / Debian
sudo apt update
sudo apt -y install git
# CentOS
sudo yum -y install git
# Fedora
sudo dnf -y install git
# Arch Linux / Manjaro
sudo pacman -S git
Clone the project code which will be used for generating VM images.
git clone https://github.com/AlmaLinux/cloud-images.git
Switching your working directory to cloud-images:
cd cloud-images
Build a Libvirt box:
export PACKER_LOG=1
packer build -only=qemu.almalinux-8 almalinux-8.pkr.hcl
Build a VMWare box:
export PACKER_LOG=1
packer build -only=vmware-iso.almalinux-8 almalinux-8.pkr.hcl
Build a VirtualBox box:
export PACKER_LOG=1
packer build -only=virtualbox-iso.almalinux-8 almalinux-8.pkr.hcl
Sample execution output:
...
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: [INFO] Packer version: 1.6.6 [go1.15.5 darwin amd64]
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Checking 'PACKER_CONFIG' for a config file path
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: 'PACKER_CONFIG' not set; checking the default config file path
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Attempting to open config file: /Users/jkmutai/.packerconfig
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: [WARN] Config file doesn't exist: /Users/jkmutai/.packerconfig
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Setting cache directory: /tmp/cloud-images/packer_cache
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: args: []string{"packer-post-processor-vagrant"}
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Plugin address: unix /var/folders/ls/jhygxm1s78n_0077ndsf4d3c0000gn/T/packer-plugin120996319
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Waiting for connection...
2021/04/06 20:01:57 Received unix RPC address for /usr/local/bin/packer: addr is /var/folders/ls/jhygxm1s78n_0077ndsf4d3c0000gn/T/packer-plugin120996319
2021/04/06 20:01:57 packer-post-processor-vagrant plugin: Serving a plugin connection...
2021/04/06 20:01:57 Build debug mode: false
2021/04/06 20:01:57 Force build: false
2021/04/06 20:01:57 On error:
2021/04/06 20:01:57 Waiting on builds to complete...
2021/04/06 20:01:57 Starting build run: vmware-iso.almalinux-8
2021/04/06 20:01:57 Running builder:
2021/04/06 20:01:57 [INFO] (telemetry) Starting builder
vmware-iso.almalinux-8: output will be in this color.
2021/04/06 20:01:57 packer-builder-vmware-iso plugin: Detected VMware version: 12
2021/04/06 20:01:57 packer-builder-vmware-iso plugin: Testing against vmware driver *common.Fusion6Driver, Success: true
==> vmware-iso.almalinux-8: Retrieving ISO
==> vmware-iso.almalinux-8: Trying https://repo.almalinux.org/almalinux/8.3/isos/x86_64/AlmaLinux-8.3-x86_64-boot.iso
2021/04/06 20:01:57 packer-builder-vmware-iso plugin: Acquiring lock for: https://repo.almalinux.org/almalinux/8.3/isos/x86_64/AlmaLinux-8.3-x86_64-boot.iso?checksum=sha256%3A08fd99fab31277ea3710bfc1ccb8a7229522af5d3987d5b062739cb0dc3b5e3e (/tmp/cloud-images/packer_cache/9978acaf19faec2ea881d59808ff5240ac8591cd.iso.lock)
==> vmware-iso.almalinux-8: Trying https://repo.almalinux.org/almalinux/8.3/isos/x86_64/AlmaLinux-8.3-x86_64-boot.iso?checksum=sha256%3A08fd99fab31277ea3710bfc1ccb8a7229522af5d3987d5b062739cb0dc3b5e3e
vmware-iso.almalinux-8: AlmaLinux-8.3-x86_64-boot.iso 505.69 MiB / 638.00 MiB [=============================================>-----------] 79.26% 00m39s
....
VMware console view:

This could take a while as a number of packages are downloaded and installed.

Successful execution on VMware:
...
2021/04/06 20:37:30 packer-post-processor-vagrant plugin: Box add: '/var/folders/ls/jhygxm1s78n_0077ndsf4d3c0000gn/T/packer176302004/packer-almalinux-8.vmxf' to 'almalinux-8-x86_64.20210406.vmware.box'
vmware-iso.almalinux-8 (vagrant): Compressing: packer-almalinux-8.vmxf
2021/04/06 20:37:30 [INFO] (telemetry) ending vagrant
2021/04/06 20:37:30 Deleting original artifact for build 'vmware-iso.almalinux-8'
Build 'vmware-iso.almalinux-8' finished after 35 minutes 33 seconds.
==> Wait completed after 35 minutes 33 seconds
==> Wait completed after 35 minutes 33 seconds
==> Builds finished. The artifacts of successful builds are:
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact-count []string{"1"}
==> Builds finished. The artifacts of successful builds are:
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "builder-id", "mitchellh.post-processor.vagrant"}
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "id", "vmware"}
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "string", "'vmware' provider box: almalinux-8-x86_64.20210406.vmware.box"}
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "files-count", "1"}
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "file", "0", "almalinux-8-x86_64.20210406.vmware.box"}
2021/04/06 20:37:30 machine readable: vmware-iso.almalinux-8,artifact []string{"0", "end"}
2021/04/06 20:37:30 [INFO] (telemetry) Finalizing.
--> vmware-iso.almalinux-8: 'vmware' provider box: almalinux-8-x86_64.20210406.vmware.box
2021/04/06 20:37:31 waiting for all plugin processes to complete...
2021/04/06 20:37:31 /usr/local/bin/packer: plugin process exited
2021/04/06 20:37:31 /usr/local/bin/packer: plugin process exited
2021/04/06 20:37:31 /usr/local/bin/packer: plugin process exited
A vagrant box will be generated and stored in the current directory:
$ ls
LICENSE almalinux-8-x86_64.20210406.vmware.box ansible packer_cache
README.md almalinux-8.pkr.hcl http tpl
You can manually import the box
vagrant init my-box
vagrant up
Example:
$ vagrant box add almalinux-8 almalinux-8-x86_64.20210406.vmware.box --provider=vmware_desktop
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'almalinux-8' (v0) for provider: vmware_desktop
box: Unpacking necessary files from: file:///private/tmp/cloud-images/almalinux-8-x86_64.20210406.vmware.box
==> box: Successfully added box 'my-box' (v0) for 'vmware_desktop'!
$ vagrant init almalinux-8
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$ vagrant up --provider=vmware_desktop
References:
More guides from us: