Skip to content

Instantly share code, notes, and snippets.

@olivierpierre
Last active June 14, 2020 18:56
Show Gist options
  • Save olivierpierre/cb6061e901bbd68bf0e336014321c987 to your computer and use it in GitHub Desktop.
Save olivierpierre/cb6061e901bbd68bf0e336014321c987 to your computer and use it in GitHub Desktop.
FreeBSD guest with CHERI toolchain and emulator inside, for a Linux host

Host requirements

  • wget
  • qemu/kvm

Get the FreeBSD 11.3 VM disk image:

wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/11.3-RELEASE/amd64/Latest/FreeBSD-11.3-RELEASE-amd64.qcow2.xz
unxz FreeBSD-11.3-RELEASE-amd64.qcow2.xz

Boot the VM for the first time (feel free to adapt CPUs/RAM options):

qemu-system-x86_64 -smp 4 -m 4G \
    -drive format=qcow2,file=FreeBSD-11.3-RELEASE-amd64.qcow2,l2-cache-size=10M \
    --accel kvm -nographic -nic user

On the menu type 3 to get the loader prompt and type this:

set console=comconsole
boot

Login with root, there is no password feel free to set one with passwd. To avoid setting the console in the bootloader each time you boot, make this change permanent:

echo "console=comconsole" >> /boot/loader.conf

Next we need to expand (1) the disk size, (2) the rootfs partition size then (3) the rootfs filesystem size as we need a lot of space for the CHERI toolchain. One way to do it is to boot on a copy of the disk and resize the original one. Close the VM (use the halt command then ctrl+a followed by x to exit Qemu) and type this on the host:

cp FreeBSD-11.3-RELEASE-amd64.qcow2 tmp.qcow2
qemu-img resize FreeBSD-11.3-RELEASE-amd64.qcow2 +40G

Then boot on the second disk:

qemu-system-x86_64 -smp 4 -m 4G \
    -drive format=qcow2,file=tmp.qcow2,l2-cache-size=10M \
    -drive format=qcow2,file=FreeBSD-11.3-RELEASE-amd64.qcow2,l2-cache-size=10M \
    --accel kvm -nographic -nic user

In the VM resize the partition then the filesystem:

gpart recover ada1
gpart resize -i 3 -s 40G ada1
growfs /dev/ada1p3

Halt the VM, then on the host cleanup and reboot on the resized disk:

rm tmp.qcow2
qemu-system-x86_64 -smp 4 -m 4G \
    -drive format=qcow2,file=FreeBSD-11.3-RELEASE-amd64.qcow2,l2-cache-size=10M \
    --accel kvm -nographic -nic user

In the VM install cheribuild's dependencies:

pkg install git python3 libtoolize libtool autotools texinfo pkgconf glib \
    gsed gmake cmake pixman ninja samba410

Then clone the cheribuild repo and build everything:

git clone https://github.com/CTSRD-CHERI/cheribuild.git
cd cheribuild
./cheribuild.py run -d -f

SSH access

Simply change the network option in the invocation of Qemu:

-nic user,hostfwd=tcp::5555-:22

TODO: describe how to install ssh and enable root ssh in the guest.

Then ssh with this commmand:

ssh root@localhost -p 5555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment