Skip to content
README.adoc 2.89 KiB
Newer Older
Jakub Jirutka's avatar
Jakub Jirutka committed
= Make Alpine Linux VM Image
Jakub Jirutka's avatar
Jakub Jirutka committed
:script-name: alpine-make-vm-image
Jakub Jirutka's avatar
Jakub Jirutka committed
:script-sha1: de147fe81402cc21250169a6c7137692c07a8022
:gh-name: alpinelinux/{script-name}
Jakub Jirutka's avatar
Jakub Jirutka committed
:version: 0.9.0
Jakub Jirutka's avatar
Jakub Jirutka committed

ifdef::env-github[]
image:https://github.com/{gh-name}/workflows/CI/badge.svg["Build Status", link="https://github.com/{gh-name}/actions"]
Jakub Jirutka's avatar
Jakub Jirutka committed
endif::env-github[]

Jakub Jirutka's avatar
Jakub Jirutka committed
This project provides a script for making customized https://alpinelinux.org/[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).
Jakub Jirutka's avatar
Jakub Jirutka committed

TIP: Don’t need VM, just wanna chroot into Alpine Linux?
     Try https://github.com/alpinelinux/alpine-chroot-install[alpine-chroot-install]!
     Or do you want to create a custom rootfs?
     Then https://github.com/alpinelinux/alpine-make-rootfs[alpine-make-rootfs] is for you!
Jakub Jirutka's avatar
Jakub Jirutka committed

== Requirements

* Linux system with common userland (Busybox or GNU coreutils)
Jakub Jirutka's avatar
Jakub Jirutka committed
* 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)
Jakub Jirutka's avatar
Jakub Jirutka committed


== Usage

Read documentation in link:{script-name}[{script-name}].
See link:.github/workflows/ci.yml[] for GitHub Actions example.
Jakub Jirutka's avatar
Jakub Jirutka committed

You can copy link:{script-name}[{script-name}] into your repository or download it on demand, e.g.:

[source, sh, subs="+attributes"]
wget https://raw.githubusercontent.com/{gh-name}/v{version}/{script-name} \
    && echo '{script-sha1}  {script-name}' | sha1sum -c \
    || exit 1


== Pitfalls

=== Creating Image for VMware (ESXi)

VMware and disk images (virtual disks) is one big mess.
Jakub Jirutka's avatar
Jakub Jirutka committed
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.

Jakub Jirutka's avatar
Jakub Jirutka committed
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:

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

Jakub Jirutka's avatar
Jakub Jirutka committed
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.


Jakub Jirutka's avatar
Jakub Jirutka committed
== License

This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
For the full text of the license, see the link:LICENSE[LICENSE] file.