Packer template for Alpine Linux on Hyper-V and Azure; GitHub – tomconte/packer-alpine-azure
Posted by jpluimers on 2020/10/05
Cool: a Packer template for Alpine Linux on Hyper-V and Azure: [WayBack] GitHub – tomconte/packer-alpine-azure
I like Alpine Linux because it is lightweight and the focus of being very secure, how popular it is in the Docker scene where it replaced Ubuntu and is now the standar package at [Archive.is/A2] library/alpine – Docker Hub and the motto [WayBack] Alpine Linux; Small. Simple. Secure. Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
Alpine is not yet out of of the box endorsed by Azure ([WayBack] Endorsed distributions of Linux | Microsoft Docs) so this is a very welcome tool.
From the readme:
Packer template for Alpine Linux on Hyper-V and Azure
This Packer template will generate a VHD suitable for use in Hyper-V or Azure.
How it works
- The Packer template downloads the Alpine 3.6 ISO from the official download site.
- It then uses
setup-alpineto perform an installation to disk.- The
answersfile is served using Packer’s built-in HTTP server.- It also installs the
hvtoolspackage and enables thehv_kvp_daemonservice so Hyper-V can detect the VM is running and retrieve its IP address. (Read more about Hyper-V Integration Services.)Software installed
The Packer provisioning step performs the following actions in order to prepare a proper Azure image:
- Installs Python and OpenSSL, plus
sudoandbash- Installs the
shadowpackage (foruseradd)- Installs the Azure Linux Agent
- Adds recommended boot parameters
- Sets the
sshclient interval to 180- Enables the Azure Agent to start at boot
The template also installs a custom
useraddscript (in/usr/local/sbin) that changes the behavior of adding password-less accounts (i.e. accounts that log in using SSH keys). By defaultuseraddlocks the password-less account, preventing it from logging in. The custom script forces an illegal password, so that the password cannot be used to log in, but leaves the account unlocked so it can be access via SSH.How to use the template
On Linux, using
qemuCheck out the
packer-qemubranch for a WIP version that builds the Alpine image usingqemu, allowing you to generate the image from a Linux machine.Detailed docs TBD, but the Windows instructions below should help.
On Windows, using Hyper-V
The commands need to be run from an elevated PowerShell prompt so that they can interact with Hyper-V.
First run the template. This will generate a VHDX file locally, in
output-hyperv-iso.packer build alpinehv.jsonTo use the image in Azure, you need to convert the image to VHD using
convert.ps1.The
deploy.cmdscript will upload the VHD to Azure and start a VM based on the image. Please amend the script variables as necessary.Once the VM is started, you can log on via
sshand make any additional changes. Then deprovision the VM to get it ready to be used as an image:waagent -deprovisionFinally,
makeimage.cmdwill deallocate the VM, capture it as an image, and start another VM based on that image.TODO
- Review/tweak boot command based on ladar’s comment
- Investigate
iptableserror messages
Used tooling:
- [WayBack] Manage Hyper-V Integration Services | Microsoft Docs
- [WayBack] Install to disk – Alpine Linux
- [WayBack] Packer by HashiCorp
- [WayBack] GitHub – Azure/WALinuxAgent: Microsoft Azure Linux Guest Agent
If you are Dutch, or you are fine with a Google translate, then read this background info:
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 1/6
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 2/6
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 3/6
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 4/6
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 5/6
- [WayBack] Alpine Linux: Een beetje vreemd, maar wel lekker – Webwereld – 6/6
- [WayBack] awall – Alpine Wall
- [WayBack] Alpine Wall – Alpine Linux
Endorsed version combinations grouped by heritance:
- CentOS / Red Hat Enterprise Linux / Oracle Linux
- Container Linux by CoreOS
- Debian / Ubuntu
- openSUSE / SUSE Linux Enterprise
A few others covered in [WayBack] Review: The best Linux distros for Docker and containers | InfoWorld:
and [WayBack] Linux Distributions Optimized for Hosting Docker · Sweetcode.io:
- Alpine Linux,
- Container Linux,
- RancherOS,
- Atomic Host,
- Boot2Docker,
- Ubuntu Core
--jeroen






Leave a comment