
Kali Linux VMイメージビルドスクリプト
Kali Linux 仮想マシン (VM) イメージビルダー。debos (fakemachine および KVM を使用) 経由。
これらは Kali チーム が公式の Kali Linux VM イメージを生成するために使用しているものと同じ ビルドスクリプト であり、kali.org/get-kali/ で入手できます。
詳細については、以下を参照してください: kali.org/docs/virtualization/。
今すぐ あなたの Kali をビルドしましょう!
希望するアーキテクチャに一致する Linux ベースのホスト上でビルドすることを推奨します。
kali-vm ビルドスクリプトを使用する準備をする方法はいくつかあります。以下のいずれかを使用できます:
build.sh - マシンから直接ビルドbuild-in-container.sh - コンテナ内からビルド (Docker や Podman など) このスクリプトを動作させるには、KVM が必要です。ただし、スーパーユーザーアクセスは必要ありません。 BIOS/UEFI での KVM の有効化については省略します。
KVM が必要な理由は、ビルドが実際にはビルドツール debos によってオンザフライで作成される仮想マシン (VM) 内から行われるためです。 Debos は内部的に fakemachine を使用しており、これが QEMU+KVM に依存しています。
まず git をインストールし、リポジトリがローカルにクローンされていることを確認してください:```console
$ sudo apt-get install --no-install-recommends
git ca-certificates
$ git clone https://gitlab.com/kalilinux/build-scripts/kali-vm.git
$ cd ./kali-vm/
QEMU/KVMの要件により、`kvm`グループに所属している必要があります。
次のコマンドで確認できます:```console
$ # Not a part of the group
$ grep kvm /etc/group
kvm:x:104:
$
$ # In the group
$ grep kvm /etc/group
kvm:x:104:kali
$
返された行にあなたのユーザー名(例: kali)が表示されない場合、あなたはそのグループに属していないため、自分自身を kvm グループに追加する必要があります。
これは次のようにして行えます:```console
$ sudo adduser $USER kvm
その後、変更を有効にするために**ログアウトして再度ログイン**してください。 <!-- これはターミナルアプリを閉じて再度開くことではなく、Xfceからログアウトすることです! -->
...または```console
$ newgrp kvm
build.sh を使用してホスト上で直接ビルドするには、ビルド依存関係をインストールします:```console
$ sudo apt-get install --no-install-recommends
debos
linux-image-amd64
parted
dosfstools e2fsprogs
zerofree
7zip bmap-tools qemu-utils xz-utils
xkb-data
<!-- This should match what is in: [Dockerfile](https://gitlab.com/kalilinux/build-scripts/kali-vm/-/blob/main/Dockerfile) & [kali.org/docs/virtualization/](https://www.kali.org/docs/virtualization/)
Alt: $ sudo apt-get install 7zip debos dosfstools qemu-utils zerofree
xkb-data is optional, just helps to validate settings - doesn't take up that much space
-->
- - -
これで `./build.sh` を使用して、マシン上で直接 Kali VM イメージをビルドできます。
### コンテナ内からのビルド
_コンテナソフトウェアのセットアップについては省略します。_
コンテナ内からビルドしたい場合は、マシンに `docker` または `podman` のいずれかをインストールして設定する必要があります。
- `docker` は、ユーザーを Docker グループに追加するか、root アカウントを使用する必要があります(例: `$ sudo ./build-in-container.sh`)。
- `podman` は、rootful(例: `$ sudo ./build-in-container.sh`)と rootless(例: `$ ./build-in-container.sh`)の両方でテストされています。rootless の場合はさらに `crun` が必要です(例: `$ sudo apt install crun`)。これは `runc` がユーザー名前空間から `/dev/kvm` にアクセスできないためです。
- - -
`build-in-container.sh` は `build.sh` の上に構築されたラッパーです。使用する OCI 準拠のコンテナエンジンを検出し、[コンテナイメージ](https://gitlab.com/kalilinux/build-scripts/kali-vm/-/blob/main/Dockerfile) が存在しない場合は作成し、その後コンテナを起動して内部からビルドを実行します。
コンテナイメージを提供する方法は 3 つあります:```console
$ # 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
docker と podman の両方がインストールされている場合、build-in-container.sh はデフォルトで podman を使用します。これを変更するには、./build-in-container.sh の前に CONTAINER=docker を付けてください:```console
$ CONTAINER=docker ./build-in-container.sh [...]
- - -
これで、イメージをビルドするために (`./build.sh` ではなく) `./build-in-container.sh` を使用できます。
## ヘルプ```console
$ ./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
VM options:
-D, --desktop DESKTOP Desktop environment installed in the image (default: xfce)
Supported: xfce e17 gnome i3 kde lxde mate none
-H, --hostname HOSTNAME Set system host name (default: kali)
-K, --keyboard KEYBOARD Set keyboard layout (default: us)
See README.md for details
-L, --locale LOCALE Set locale (default: en_US.UTF-8)
-P, --packages PKGS Install extra packages (comma/space separated list)
-s, --size SIZE Size of the disk image in GB (default: 86)
-S, --swap SWAP Swap as a partition, a file, or none (default: file)
Supported: partition file none
-T, --toolset TOOLSET The selection of tools to include in the image (default: default)
Supported: default everything headless large none
-U, --userpass USERPASS Username and password, separated by a colon (default: kali:kali)
-Z, --timezone TIMEZONE Set timezone (default: America/New_York)
Use "same" as the value for -K/-L/-Z to inherit the host's current setting.
The different variants of images are:
generic Image with all virtualization support pre-installed, default format: raw
hyperv Image pre-configured for Hyper-V "Enhanced Session Mode", default format: hyperv
qemu Image with QEMU and SPICE guest agents pre-installed, default format: qemu
rootfs Not an image, a root filesystem (no bootloader/kernel), packed in a .tar.gz
virtualbox Image with VirtualBox guest utilities pre-installed, default format: virtualbox
vmware Image with Open VM Tools pre-installed, default format: vmware