Overview

I had to build a kernel and an image for trying CorJail. But the building was not completed in my environment (WSL2 on Windows 11). I think I will be comfortable if I have a linux VM for a building linux kernel, file system image, and etc.

Step

  1. Select Ubuntu version and download its image on here
  2. Install cloud-init, cloud-utils and qemu-system
    1. You can install them by sudo apt install -y cloud-init cloud-utils qemu-system on Debian/Ubuntu.
  3. Generate a RSA key using ssh-keygen -t rsa
  4. Set up config file and create seed.img
    1. To create config files, see config files section
    2. Create seed.img via cloud-localds seed.img user-data.yaml metadata.yaml
  5. Set shared foldder and run qemu
  6. In guest OS, add shared /shared 9p trans=virtio,version=9p2000.L,access=any 0 0 to /etc/fstab
    1. After addition type sudo systemctl daemon-reload && sudo systemctl restart local-fs.target && sudo mount -a.

Then if you need more space for a qemu drive, use qemu-img resize.

Config flies


instance-id: <instance-name>
local-hostname: <host-name>

#cloud-config
user: <user-id>
password: <password>
chpasswd: {expire: False}
ssh_pwauth: True
ssh_authorized_keys: <rsa-pub> <username@domain>

Run QEMU


#!/bin/bash

SCRIPT_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")

qemu-system-x86_64  \
  -enable-kvm \
  -m 16G \
  -smp 8 \
  -nographic \
  -device virtio-net-pci,netdev=net0 \
  -netdev user,id=net0,hostfwd=tcp::2222-:22 \
  -drive if=virtio,format=qcow2,file="$SCRIPT_DIR/<your-cloud-image-path>" \
  -drive if=virtio,format=raw,file="$SCRIPT_DIR/<your-seed-image-path>" \
  -virtfs local,path="$SCRIPT_DIR/<your-shared-directory-path>",mount_tag=shared,security_model=none \

Reference