Create Simple Build VM Using Ubuntu Cloud
Table of Contents
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⌗
- Select Ubuntu version and download its image on here
- Install
cloud-init,cloud-utilsandqemu-system- You can install them by
sudo apt install -y cloud-init cloud-utils qemu-systemon Debian/Ubuntu.
- You can install them by
- Generate a RSA key using
ssh-keygen -t rsa - Set up config file and create seed.img
- To create config files, see config files section
- Create seed.img via
cloud-localds seed.img user-data.yaml metadata.yaml
- Set shared foldder and run qemu
- In guest OS, add
shared /shared 9p trans=virtio,version=9p2000.L,access=any 0 0to/etc/fstab- After addition type
sudo systemctl daemon-reload && sudo systemctl restart local-fs.target && sudo mount -a.
- After addition type
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 \