2022-05-30 05:38:06 -04:00
## Setup
2022-10-19 07:10:15 -04:00
- Install mkosi (from git):
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
```sh
cd /tmp/
git clone https://github.com/systemd/mkosi
cd mkosi
2023-04-25 12:22:40 -04:00
git checkout d8b32fbf3077b612db0024276e73cec3c2c87577
2022-10-19 07:10:15 -04:00
tools/generate-zipapp.sh
cp builddir/mkosi /usr/local/bin/
```
2022-05-30 05:38:06 -04:00
2023-04-25 12:22:40 -04:00
- Build systemd tooling (from git):
Ubuntu and Fedora ship outdated versions of systemd tools, so you need to build them from source:
```sh
# Ubuntu
echo "deb-src http://archive.ubuntu.com/ubuntu/ $(lsb_release -cs) main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get build-dep systemd
sudo apt-get install libfdisk-dev
# Fedora
sudo dnf builddep systemd
git clone https://github.com/systemd/systemd --depth=1
meson systemd/build systemd -Drepart=true -Defi=true -Dbootloader=true
BINARIES=(
bootctl
systemctl
systemd-analyze
systemd-dissect
systemd-nspawn
systemd-repart
ukify
)
ninja -C systemd/build ${BINARIES[@]}
SYSTEMD_BIN=$(realpath systemd/build)
echo installed systemd tools to "${SYSTEMD_BIN}"
```
2022-10-19 07:10:15 -04:00
- Install tools:
< details >
< summary > Ubuntu / Debian< / summary >
```sh
sudo apt-get update
sudo apt-get install --assume-yes --no-install-recommends \
2023-04-25 12:22:40 -04:00
bubblewrap \
coreutils \
curl \
2022-10-19 07:10:15 -04:00
dnf \
e2fsprogs \
efitools \
jq \
2023-04-25 12:22:40 -04:00
mtools \
ovmf \
python3-pefile \
python3-pyelftools \
python3-setuptools \
qemu-system-x86 \
qemu-utils \
rpm \
sbsigntool \
squashfs-tools \
systemd-container \
util-linux \
virt-manager
2022-10-19 07:10:15 -04:00
```
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
< / details >
< details >
< summary > Fedora< / summary >
```sh
sudo dnf install -y \
2023-04-25 12:22:40 -04:00
bubblewrap \
2022-10-19 07:10:15 -04:00
edk2-ovmf \
systemd-container \
qemu \
e2fsprogs \
squashfs-tools \
efitools \
sbsigntools \
coreutils \
curl \
jq \
util-linux \
virt-manager
2022-05-30 05:38:06 -04:00
```
2022-10-19 07:10:15 -04:00
< / details >
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
- Prepare secure boot PKI (see `secure-boot/genkeys.sh` )
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
## Build
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
When building your first image, prepare the secure boot PKI (see `secure-boot/genkeys.sh` ) for self-signed, locally built images.
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
After that, you can build the image with:
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
```sh
2023-04-25 12:22:40 -04:00
# export SYSTEMD_BIN=<path to systemd tools>
2022-10-19 07:10:15 -04:00
# OPTIONAL: to create a debug image, export the following line
2023-01-20 04:28:09 -05:00
# export DEBUG=true
2023-01-16 06:20:01 -05:00
# OPTIONAL: to enable the serial console, export the following line
# export AUTOLOGIN=true
2022-10-19 07:10:15 -04:00
# OPTIONAL: symlink custom path to secure boot PKI to ./pki
# ln -s /path/to/pki/folder ./pki
2023-04-25 12:22:40 -04:00
sudo make EXTRA_SEARCH_PATHS="${SYSTEMD_BIN}" -j $(nproc)
2022-10-19 07:10:15 -04:00
```
2022-05-30 05:38:06 -04:00
2023-06-15 10:50:35 -04:00
Raw images will be placed in `mkosi.output.<CSP>/fedora~38/image.raw` .
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
## Prepare Secure Boot
2022-08-09 03:05:05 -04:00
2022-10-19 07:10:15 -04:00
The generated images are partially signed by Microsoft ([shim loader](https://github.com/rhboot/shim)), and partially signed by Edgeless Systems (systemd-boot and unified kernel images consisting of the linux kernel, initramfs and kernel commandline).
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
For QEMU and Azure, you can pre-generate the NVRAM variables for secure boot. This is not necessary for GCP, as you can specify secure boot parameters via the GCP API on image creation.
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
< details >
2022-11-16 09:45:10 -05:00
< summary > < a id = "qemu-secure-boot" > libvirt / QEMU / KVM< / a > < / summary >
2022-08-02 11:14:13 -04:00
2022-10-19 07:10:15 -04:00
```sh
2023-06-15 10:50:35 -04:00
secure-boot/generate_nvram_vars.sh mkosi.output.qemu/fedora~38/image.raw
2022-08-02 11:14:13 -04:00
```
2022-10-19 07:10:15 -04:00
< / details >
2022-08-09 03:05:05 -04:00
2022-10-19 07:10:15 -04:00
< details >
< summary > < a id = "azure-secure-boot" > Azure< / a > < / summary >
2022-08-09 03:05:05 -04:00
2022-10-19 07:10:15 -04:00
These steps only have to performed once for a fresh set of secure boot certificates.
VMGS blobs for testing and release images already exist.
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
First, create a disk without embedded MOK EFI variables.
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
```sh
# set these variables
export AZURE_SECURITY_TYPE=ConfidentialVM # or TrustedLaunch
export AZURE_RESOURCE_GROUP_NAME= # e.g. "constellation-images"
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
export AZURE_REGION=northeurope
2022-11-04 11:48:52 -04:00
export AZURE_REPLICATION_REGIONS=
2022-10-19 07:10:15 -04:00
export AZURE_DISK_NAME=constellation-$(date +%s)
export AZURE_SNAPSHOT_NAME=${AZURE_DISK_NAME}
2023-06-15 10:50:35 -04:00
export AZURE_RAW_IMAGE_PATH=${PWD}/mkosi.output.azure/fedora~38/image.raw
export AZURE_IMAGE_PATH=${PWD}/mkosi.output.azure/fedora~38/image.vhd
2022-10-19 07:10:15 -04:00
export AZURE_VMGS_FILENAME=${AZURE_SECURITY_TYPE}.vmgs
2023-06-15 10:50:35 -04:00
export AZURE_JSON_OUTPUT=${PWD}/mkosi.output.azure/fedora~38/image-upload.json
2022-10-19 07:10:15 -04:00
export BLOBS_DIR=${PWD}/blobs
upload/pack.sh azure "${AZURE_RAW_IMAGE_PATH}" "${AZURE_IMAGE_PATH}"
upload/upload_azure.sh --disk-name "${AZURE_DISK_NAME}-setup-secure-boot" ""
secure-boot/azure/launch.sh -n "${AZURE_DISK_NAME}-setup-secure-boot" -d --secure-boot true --disk-name "${AZURE_DISK_NAME}-setup-secure-boot"
```
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
Ignore the running launch script and connect to the serial console once available.
The console shows the message "Verification failed: (0x1A) Security Violation". You can import the MOK certificate via the UEFI shell:
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
Press OK, then ENTER, then "Enroll key from disk".
Select the following key: `/EFI/loader/keys/auto/db.cer` .
Press Continue, then choose "Yes" to the question "Enroll the key(s)?".
Choose reboot.
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
Extract the VMGS from the running VM (this includes the MOK EFI variables) and delete the VM:
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
```sh
secure-boot/azure/extract_vmgs.sh --name "${AZURE_DISK_NAME}-setup-secure-boot"
secure-boot/azure/delete.sh --name "${AZURE_DISK_NAME}-setup-secure-boot"
```
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
< / details >
## Upload to CSP
2023-04-21 04:47:07 -04:00
Warning! Never set `--version` to a value that is already used for a release image.
2022-10-17 11:39:49 -04:00
< details >
< summary > AWS< / summary >
- Install `aws` cli (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html ))
- Login to AWS (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html ))
- Choose secure boot PKI public keys (one of `pki_dev` , `pki_test` , `pki_prod` )
2023-07-18 09:08:34 -04:00
- `pki_dev` can be used for local image builds
- `pki_test` is used by the CI for non-release images
- `pki_prod` is used for release images
2022-10-17 11:39:49 -04:00
```sh
2023-04-21 04:47:07 -04:00
# Warning! Never set `--version` to a value that is already used for a release image.
# Instead, use a `ref` that corresponds to your branch name.
2023-06-15 10:50:35 -04:00
bazel run //image/upload -- aws --verbose --raw-image mkosi.output.aws/fedora~38/image.raw --variant "" --version ref/foo/stream/nightly/v2.7.0-pre-asdf
2022-10-17 11:39:49 -04:00
```
< / details >
2022-10-19 07:10:15 -04:00
< details >
< summary > GCP< / summary >
- Install `gcloud` and `gsutil` (see [here ](https://cloud.google.com/sdk/docs/install ))
- Login to GCP (see [here ](https://cloud.google.com/sdk/docs/authorizing ))
- Choose secure boot PKI public keys (one of `pki_dev` , `pki_test` , `pki_prod` )
2023-07-18 09:08:34 -04:00
- `pki_dev` can be used for local image builds
- `pki_test` is used by the CI for non-release images
- `pki_prod` is used for release images
2022-10-19 07:10:15 -04:00
```sh
2023-06-15 10:50:35 -04:00
export GCP_RAW_IMAGE_PATH=${PWD}/mkosi.output.gcp/fedora~38/image.raw
export GCP_IMAGE_PATH=${PWD}/mkosi.output.gcp/fedora~38/image.tar.gz
2022-10-19 07:10:15 -04:00
upload/pack.sh gcp ${GCP_RAW_IMAGE_PATH} ${GCP_IMAGE_PATH}
2023-04-21 04:47:07 -04:00
# Warning! Never set `--version` to a value that is already used for a release image.
# Instead, use a `ref` that corresponds to your branch name.
bazel run //image/upload -- gcp --verbose --raw-image "${GCP_IMAGE_PATH}" --variant "sev-es" --version ref/foo/stream/nightly/v2.7.0-pre-asdf
2022-10-19 07:10:15 -04:00
```
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
< / details >
< details >
< summary > Azure< / summary >
2022-11-09 04:11:23 -05:00
Note:
> For testing purposes, it is a lot simpler to disable Secure Boot for the uploaded image!
> Disabling Secure Boot allows you to skip the VMGS creation steps above.
2022-10-19 07:10:15 -04:00
- Install `az` and `azcopy` (see [here ](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli ))
- Login to Azure (see [here ](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli ))
2022-11-09 04:11:23 -05:00
- Optional (if Secure Boot should be enabled) [Prepare virtual machine guest state (VMGS) with customized NVRAM or use existing VMGS blob ](#azure-secure-boot )
2022-10-19 07:10:15 -04:00
```sh
2023-06-15 10:50:35 -04:00
export AZURE_RAW_IMAGE_PATH=${PWD}/mkosi.output.azure/fedora~38/image.raw
export AZURE_IMAGE_PATH=${PWD}/mkosi.output.azure/fedora~38/image.vhd
2022-10-19 07:10:15 -04:00
upload/pack.sh azure "${AZURE_RAW_IMAGE_PATH}" "${AZURE_IMAGE_PATH}"
2023-04-21 04:47:07 -04:00
# Warning! Never set `--version` to a value that is already used for a release image.
# Instead, use a `ref` that corresponds to your branch name.
bazel run //image/upload -- azure --verbose --raw-image "${AZURE_IMAGE_PATH}" --variant "cvm" --version ref/foo/stream/nightly/v2.7.0-pre-asdf
2022-10-19 07:10:15 -04:00
```
2022-05-30 05:38:06 -04:00
2022-10-19 07:10:15 -04:00
< / details >
2022-11-16 09:45:10 -05:00
2023-02-27 12:19:52 -05:00
< details >
< summary > OpenStack< / summary >
Note:
> OpenStack is not one a global cloud provider, but rather a software that can be installed on-premises.
> This means we do not upload the image to a cloud provider, but to our CDN.
- Install `aws` cli (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html ))
- Login to AWS (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html ))
```sh
2023-04-21 04:47:07 -04:00
# Warning! Never set `--version` to a value that is already used for a release image.
# Instead, use a `ref` that corresponds to your branch name.
2023-06-15 10:50:35 -04:00
bazel run //image/upload -- openstack --verbose --raw-image mkosi.output.openstack/fedora~38/image.raw --variant "sev" --version ref/foo/stream/nightly/v2.7.0-pre-asdf
2023-02-27 12:19:52 -05:00
```
< / details >
2022-11-16 09:45:10 -05:00
< details >
< summary > QEMU< / summary >
- Install `aws` cli (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html ))
- Login to AWS (see [here ](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html ))
```sh
2023-04-21 04:47:07 -04:00
# Warning! Never set `--version` to a value that is already used for a release image.
# Instead, use a `ref` that corresponds to your branch name.
2023-06-15 10:50:35 -04:00
bazel run //image/upload -- qemu --verbose --raw-image mkosi.output.qemu/fedora~38/image.raw --variant "default" --version ref/foo/stream/nightly/v2.7.0-pre-asdf
2022-11-16 09:45:10 -05:00
```
< / details >