Skip to content

Make customized Alpine Linux disk image for virtual machines

License

Notifications You must be signed in to change notification settings

omnivagant/alpine-make-vm-image

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Make Alpine Linux VM Image

Build Status

This project provides a script for making customized Alpine Linux disk images for virtual machines. It’s quite simple (300 LoC of shell), fast (~32 seconds on GitHub Actions) and requires minimum dependencies (QEMU and filesystem tools).

Tip
Don’t need VM, just want to chroot into Alpine Linux (e.g. on CI)? Try alpine-chroot-install!

Requirements

  • Linux system with common userland (Busybox or GNU coreutils)

  • POSIX-sh compatible shell (e.g. Busybox ash, dash, Bash, ZSH)

  • qemu-img and qemu-nbd (automatically installed by the script if running on Alpine)

  • e2fsprogs (for ext4), btrfs-progs (for Btrfs), or xfsprogs (for XFS) (automatically installed by the script if running on Alpine)

Usage

Read documentation in alpine-make-vm-image. See .github/workflows/ci.yml for GitHub Actions example.

You can copy alpine-make-vm-image into your repository or download it on demand, e.g.:

wget https://raw.githubusercontent.com/alpinelinux/alpine-make-vm-image/v0.7.0/alpine-make-vm-image \
    && echo '9803170e07b05b97eb6712e6a9097ad656954d0f  alpine-make-vm-image' | sha1sum -c \
    || exit 1

Pitfalls

Creating Image for VMware (ESXi)

VMware and disk images (virtual disks) is one big mess. You can find that VMware uses the VMDK format, but the problem is that this is not a single format. Actually it has many subformats with very different structure and various (in)compatibility with VMware hypervisors.

When I’ve created a disk image using qemu-img create -f vmdk or converted Qcow2 to VMDK using qemu-img convert -O vmdk, vSphere client loaded this image without any problem, but the data was corrupted. Eventually I found in some old documentation that ESXi does not support “sparse” disks…

So after many trials I found out that the least bad and functional solution is to create Qcow2 image and then convert it to VMDK using:

qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=monolithicFlat alpine.qcow2 alpine.vmdk

Unfortunately, this creates a “thick” image, i.e. its size equals the “provisioned space”, not actually used space as in Qcow2. However, you can compress it with gzip to avoid transferring multiple gigabytes of zeros over network.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.

About

Make customized Alpine Linux disk image for virtual machines

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 92.5%
  • Makefile 7.5%