All Projects → goffinet → packer-kvm

goffinet / packer-kvm

Licence: MIT License
Create VM templates with Packer for usage with Libvirt/KVM virtualization : CentOS 7, CentOS 8, CentOS 8 Stream, Alma Linux, Rocky Linux, Bionic (Ubuntu 1804), Focal (Ubuntu 2004), Debian 11 (stable), Kali Linux, Fedora 33 and Fedora 34.

Programming Languages

shell
77523 projects
HCL
1544 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to packer-kvm

wsl-distrod
Distrod is a meta-distro for WSL 2 which installs Ubuntu, Arch, Debian, Gentoo, etc. with systemd in a minute for you. Distrod also has built-in auto-start feature on Windows startup and port forwarding ability.
Stars: ✭ 1,637 (+1553.54%)
Mutual labels:  debian, fedora, centos, rockylinux, almalinux
Openvpn Install
OpenVPN road warrior installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS and Fedora
Stars: ✭ 14,199 (+14242.42%)
Mutual labels:  debian, fedora, centos, rockylinux, almalinux
ansible-role-docker-ce
Ansible role to install Docker CE on AlmaLinux/Rocky/CentOS/Fedora/RHEL(Redhat)/Ubuntu/Debian/Mint/Raspbian
Stars: ✭ 73 (-26.26%)
Mutual labels:  debian, fedora, centos, rockylinux, almalinux
Packer Build
Packer Automated VM Image and Vagrant Box Builds
Stars: ✭ 199 (+101.01%)
Mutual labels:  packer, debian, kvm, qemu
Robox
The tools needed to robotically create/configure/provision a large number of operating systems, for a variety of hypervisors, using packer.
Stars: ✭ 303 (+206.06%)
Mutual labels:  packer, debian, fedora, centos
distrobox
Use any linux distribution inside your terminal. Enable both backward and forward compatibility with software and freedom to use whatever distribution you’re more comfortable with. Mirror available at: https://gitlab.com/89luca89/distrobox
Stars: ✭ 4,371 (+4315.15%)
Mutual labels:  fedora, centos, rockylinux, almalinux
Kvm Install Vm
Bash script to build local virtual machines using KVM/libvirt and cloud-init.
Stars: ✭ 248 (+150.51%)
Mutual labels:  debian, fedora, centos, kvm
insaneworks-packer-template
CentOS 7-8 8Stream / AlmaLinux 8 / FreeBSD 12 - 13 x64 + VirtualBox / VMWare for Packer Template + FreeBSD 13 / AlmaLinux 9 + Parallels
Stars: ✭ 38 (-61.62%)
Mutual labels:  packer, centos, packer-template, almalinux
Qemu Images
A collection of disk images and virtual machines that can be used by the QEMU emulator
Stars: ✭ 145 (+46.46%)
Mutual labels:  debian, kvm, qemu, kali-linux
kubash
Kubash - the K8$ shell for your kube clusters
Stars: ✭ 20 (-79.8%)
Mutual labels:  packer, kvm, qemu, qemu-kvm
installer-linux
💾 SinusBot Installer for Debian, Ubuntu and CentOS - Installs the SinusBot with a single command.
Stars: ✭ 28 (-71.72%)
Mutual labels:  debian, fedora, centos
Packer Boxes
Jeff Geerling's Packer build configurations for Vagrant boxes.
Stars: ✭ 495 (+400%)
Mutual labels:  packer, debian, centos
Packer Templates
Stars: ✭ 90 (-9.09%)
Mutual labels:  packer, debian, fedora
cloud-desktops
Cloud-based Virtual Desktops on Google Cloud Platform
Stars: ✭ 14 (-85.86%)
Mutual labels:  packer, debian, kali-linux
Terrible
An Ansible playbook that apply the principle of the Infrastructure as Code on a QEMU/KVM environment.
Stars: ✭ 161 (+62.63%)
Mutual labels:  debian, kvm, qemu
packer-centos
Create CentOS images for different hypervisors with Packer
Stars: ✭ 18 (-81.82%)
Mutual labels:  packer, centos, kvm
LinuxMirrors
Linux 一键更换国内软件源
Stars: ✭ 623 (+529.29%)
Mutual labels:  debian, fedora, centos
piu
Cross platform package manager wrapper
Stars: ✭ 33 (-66.67%)
Mutual labels:  debian, fedora, centos
Termux Os
All in One Termux Os..!! (New)
Stars: ✭ 150 (+51.52%)
Mutual labels:  debian, fedora, kali-linux
Invidious-Updater
Automatic install and update script for Invidious
Stars: ✭ 181 (+82.83%)
Mutual labels:  debian, fedora, centos

packer-kvm

Create VM templates with Packer for usage with Libvirt/KVM virtualization : CentOS 7, CentOS 8 (Stream), Alma Linux, Rocky Linux, Bionic (Ubuntu 1804), Focal (Ubuntu 2004), Debian 11 (stable), Kali Linux, Fedora 33 and Fedora 34.

Only for education and learning purposes. Do not use it in production.

Packer Concepts

Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. (Introduction to Packer, What is Packer?). It uses different plugins as builders, provisioners or post-processors.

Builders are responsible for creating machines and generating images from them for various platforms. For example, there are separate builders for EC2, VMware, VirtualBox, Qemu, etc. Packer comes with many builders by default, and can also be extended to add new builders. (Builders)

Packer can enable an http server to serve kickstart, preseed or cloud-init configuration files at boot.

Provisioners use builtin and third-party software to install and configure the machine image after booting. (Provisioners)

Post-processors run after the image is built by the builder and provisioned by the provisioner(s). (Post-Processors)

Proof of Concept to generate Linux qemu images

This is a Packer "Proof of Concept" with :

  • qemu/kvm as image builder (qcow2)
  • "shell" and "ansible-local" as provisionners
  • "shell-local" as post-processor to generate a gns3a appliance file, checksum and upload to a server

Optionnal :

  • run this inside a docker container
  • build your own container

Enjoy those images with :

  • Libvirt native tools
  • Terraform as IaC tool with a third party Libvirtd Provider plugin

The built images are intended to be published on a S3 bucket.

Pre-requisites

The run this project with success, you need a virtualization server and some softwares installed :

  • Libvirt/KVM, Packer and aws s3 cli
  • Docker (to run the build inside a container)

Use ./setup.sh for a quick setup of Libvirt/KVM, Packer and aws s3 cli but please read before the following manual instructions.

For Docker usage, install it and put your aws S3 credits in your ~/.profile.

Anyway, you can remove the post-processor in your image JSON template to avoid S3 upload attemps.

AWS S3

Configure your S3 credits :

echo "export AWS_ACCESS_KEY=<your AWS_ACCESS_KEY>" >> ~/.profile
echo "export AWS_SECRET_KEY=<your AWS_SECRET_KEY>" >> ~/.profile
source ~/.profile

Libvirt and Packer

Install Livirt/KVM on your server :

if [ -f /etc/debian_version ]; then
apt-get update && apt-get -y upgrade
apt-get -y install qemu-kvm libvirt-dev virtinst virt-viewer libguestfs-tools virt-manager uuid-runtime curl linux-source libosinfo-bin
virsh net-start default
virsh net-autostart default
elif [ -f /etc/redhat-release ]; then
yum -y install epel-release
yum -y upgrade
yum -y group install "Virtualization Host"
yum -y install virt-manager libvirt virt-install qemu-kvm xauth dejavu-lgc-sans-fonts virt-top libguestfs-tools virt-viewer virt-manager curl
ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-system-x86_64
fi

Install the Packer binary :

yum -y install wget unzip || apt update && apt -y install wget unzip
latest=$(curl -L -s https://releases.hashicorp.com/packer | grep 'packer_' | sed 's/^.*<.*\">packer_\(.*\)<\/a>/\1/' | head -1)
wget https://releases.hashicorp.com/packer/${latest}/packer_${latest}_linux_amd64.zip
unzip packer*.zip
chmod +x packer
mv packer /usr/local/bin/

Docker

Get Docker and docker-compose :

curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
if [ -f /etc/debian_version ]; then
apt-get update && apt-get -y install python3-pip
elif [ -f /etc/redhat-release ]; then
yum -y install python3-pip
fi
pip3 install docker-compose

Build with Packer

Each JSON file is a template for a distribution :

For example :

packer build centos7.json

Build with Docker qemu based image

goffinet/packer-qemu is a Docker image for building qemu images with packer and is available on Docker Hub.

docker run --rm \
  -e PACKER_LOG=1 \
  -e PACKER_LOG_PATH="packer-docker.log" \
  -it \
  --privileged \
  --cap-add=ALL -v /lib/modules:/lib/modules \
  -v `pwd`:/opt/ \
  -e AWS_ACCESS_KEY=$AWS_ACCESS_KEY \
  -e AWS_SECRET_KEY=$AWS_SECRET_KEY \
  -w /opt/ goffinet/packer-qemu build centos7.json

The script build.sh do it with the template filename as first argument.

./build.sh centos7.json

To build the image localy with the Dockerfile :

docker build -t packer-qemu .

Packing monitoring

Packer use VNC to launch a temporary VM, you can check this window with a VNC client like vinagre.

You can have more details from Packet with the env var configured : PACKER_LOG=1.

Cloud images for qemu/KVM/Libvirt built with Packer

I build images for qemu/KVM with this project and I publish them for use in those other IaC projects: Virt-scripts and Terraform with Libvirt/KVM provider.

You can easily download them to /var/lib/libvirt/images with this script :

curl -s -o /usr/local/bin/download-images.sh https://raw.githubusercontent.com/goffinet/virt-scripts/master/download-images.sh
chmod +x /usr/local/bin/download-images.sh
download-images.sh

How to exploit those built images

How to exploit those built images?

  • In the old way with Libvirt and some bash scripts
  • In a beter way with a tool like Terraform

This is always beter to know how Libvirt is working. Can you read fundamentals about KVM virtualization in french.

Enjoy with Libvirt

https://github.com/goffinet/virt-scripts

  1. Clone virt-scripts repo and prepare the machine
sudo apt update && apt -y install git
git clone https://github.com/goffinet/virt-scripts
cd virt-scripts
sudo ./autoprep.sh
  1. Build or download images

Put builded images in /var/lib/libvirt/images or download them :

sudo ./download-images.sh
Please provide the image name :
centos7 bionic debian11
  1. Launch two new machines
sudo ./define-guest-image.sh c1 centos7
sudo ./define-guest-image.sh u1 bionic
  1. Enjoy
sudo virsh console u1
ssh $(dig @192.168.122.1 +short u1)

Enjoy with Terraform (with libvirt)

https://github.com/goffinet/terraform-libvirt

Install Terraform 0.13 with a third party Libvirt provider plugin :

echo "security_driver = \"none\"" >> /etc/libvirt/qemu.conf
systemctl restart libvirtd
sudo yum -y install wget unzip || sudo apt update && sudo apt -y install wget unzip
wget https://releases.hashicorp.com/terraform/0.13.2/terraform_0.13.2_linux_amd64.zip
unzip terraform_0.13.2_linux_amd64.zip
chmod +x terraform
mv terraform /usr/local/bin/
wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.2/terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz
tar xvf terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz
mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64
cp -r terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64/

Compose your libvirt infrastructure :

git clone https://github.com/goffinet/terraform-libvirt
cd terraform-libvirt/ubuntu_cloudinit
terraform plan
cd ../count
terraform plan

Customization

To customize post-processing

The scripts/push-image.sh generate somme meta-data and push the generated image to a pre-defined S3 Bucket.

To customize this process, you can change the content as it :

#!/bin/bash

name=$IMAGE_NAME
version=$IMAGE_VERSION
image="${name}${version}"
echo "artifacts/qemu/${image} post-processing ..."

Anyway, you can remove the post-processor in your image JSON template to avoid this script call.

Customize SSH keys

To generate the ssh keys for provisionning and put it in the sshkeys/ folder :

ssh-keygen -q -t rsa -N '' -C 'packer-kvm-default-key' -f sshkeys/id_rsa

To get the default ssh private key :

curl https://raw.githubusercontent.com/goffinet/packer-kvm/master/sshkeys/id_rsa

To get the default ssh public key :

curl https://raw.githubusercontent.com/goffinet/packer-kvm/master/sshkeys/id_rsa.pub

ToDo

  • unique model : for efficience, a unique template should be sufficient with a data source with these elements.
  • random secret for provisonning (https://www.packer.io/docs/templates/engine#template-variables)
  • Remove swap post-processing
  • docker-compose for automation
  • add versions of post-processing and images meta-datas

Wath are the variants in those templates?

  • the iso_urls and the iso_checksum template parameters
  • the ssh_username, ssh_password and ssh_private_key_file template parameters as well as sshkey in kickstart files.
  • the boot_command as template parameter
  • the configuration file type : kickstart, preseed or cloud-init

Initials credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].