
Kali Linux VM images build script
Kali Linux Virtual Machine (VM) image builder, via debos (with fakemachine and KVM).
These are the same build-scripts that the Kali team uses to generate the official Kali Linux VM images, found on kali.org/get-kali/.
For more information, please see: kali.org/docs/virtualization/.
Build your Kali, today!
We recommend building on a Linux-based host, which matches the desired architecture.
There are various ways to get ready to use kali-vm build-script. You can either:
build.sh - Build straight from your machinebuild-in-container.sh - Build from within a container (such as Docker or Podman) For this script to work, it will require KVM. However, super user access isn't required. We will skip over enabling KVM in BIOS/UEFI.
The reason why KVM is required is the build actually happens from within a virtual machine (VM), that is created on-the-fly by the build tool debos. Debos uses fakemachine under the hood, which in turn relies on QEMU+KVM.
First install git, and make sure that the repository is cloned locally:
$ sudo apt-get install --no-install-recommends \
git ca-certificates
$ git clone https://gitlab.com/kalilinux/build-scripts/kali-vm.git
$ cd ./kali-vm/
Due to the requirements of QEMU/KVM, you must be part of the kvm group.
You can check by doing:
$ # Not a part of the group
$ grep kvm /etc/group
kvm:x:104:
$
$ # In the group
$ grep kvm /etc/group
kvm:x:104:kali
$
If your username does not appear in the line returned (e.g. kali), it means that you are not in the group, and you must add yourself to the kvm group.
You can do that by doing:
$ sudo adduser $USER kvm
Then log out and log back in for the change to take effect. ...or
$ newgrp kvm
To build directly on your host, with build.sh, install the build dependencies:
$ sudo apt-get install --no-install-recommends \
debos \
linux-image-amd64 \
parted \
dosfstools e2fsprogs \
zerofree \
7zip bmap-tools qemu-utils xz-utils \
xkb-data
Now you can use ./build.sh, which will build a Kali VM image straight on your machine.
We will skip over setting up any container software.
If you prefer to build from within a container, you will need to install and configure either docker or podman on your machine.
docker requires the user to be added to the Docker group, or using the root account (e.g. $ sudo ./build-in-container.sh).podman has been tested with both as rootful (e.g. $ sudo ./build-in-container.sh) and rootless (e.g. $ ./build-in-container.sh). Rootless additionally needs crun (e.g. $ sudo apt install crun), as runc cannot reach /dev/kvm from a user namespace.build-in-container.sh is a wrapper on top of build.sh. It detects which OCI-compliant container engine to use, takes care of creating the container image if missing, and then it starts the container to perform the build from within.
You have three ways to provide the container image:
$ # Option #1 - Automated build (recommended)
$ ./build-in-container.sh
$ ./build-in-container.sh --force # If you need to rebuild the image from scratch
$
$
$
$ # Option #2 - Manual build
$ docker build -t kali-build/kali-vm .
$ # ...OR...
$ podman build -t kali-build/kali-vm .
$
$
$
$ # Option #3 - Use the pre-generated
$ docker pull registry.gitlab.com/kalilinux/build-scripts/kali-vm:latest
$ docker tag registry.gitlab.com/kalilinux/build-scripts/kali-vm:latest kali-build/kali-vm
$ # ...OR...
$ podman pull registry.gitlab.com/kalilinux/build-scripts/kali-vm:latest
$ podman tag registry.gitlab.com/kalilinux/build-scripts/kali-vm:latest kali-build/kali-vm
$
$ # ...then point the build at it:
$ ./build-in-container.sh # Locally built (automated or manual)
$ IMAGE=registry.gitlab.com/kalilinux/build-scripts/kali-vm:latest ./build-in-container.sh # Pre-generated
If you have both docker and podman installed, build-in-container.sh will default to using podman. To change this, prefix CONTAINER=docker before ./build-in-container.sh:
$ CONTAINER=docker ./build-in-container.sh [...]
Now you can use ./build-in-container.sh (rather than ./build.sh), to build an image.
$ ./build.sh --help
Usage: build.sh [OPTIONS] [-- <debos options>]
Build a Kali Linux VM image.
Build options:
-a, --arch ARCH Build an image for this architecture (default: amd64)
Supported: amd64
-b, --branch BRANCH Kali branch used to build the image (default: kali-rolling)
Supported: kali-rolling kali-dev kali-last-snapshot
-f, --format FORMAT Format to export the image to (default: ...depends on --variant)
Supported: hyperv ova ovf qemu raw vagrant virtualbox vmware
-k, --keep Keep intermediary build artifacts
-m, --mirror URL Mirror used to build the image (default: http://http.kali.org/kali)
-o, --output DIR Output directory (default: /home/kali/kali-vm/output)
-r, --rootfs ROOTFS Rootfs to use to build the image (default: none)
-v, --variant VARIANT Variant of image to build, see below for details (default: generic)
Supported: generic hyperv qemu rootfs virtualbox vmware
-x, --version VERSION What to name the image release as (default: rolling)
-z, --zip Compress image and metadata files after the build
-h, --help Show this help and exit