I’ve been curious about FreeBSD and wanted to try it on QEMU. FreeBSD has instructions for running it. As I’m using an Apple Silicon machine, I paid attention to the HVF acceleration option. I first logged in via Telnet, but once SSH was set up, I ran it in the background with a small script (./run.sh &
):
#!/bin/sh
qemu-system-aarch64 -m 4096M -cpu host -M virt,accel=hvf \
-bios edk2-aarch64-code.fd -display none \
-drive if=virtio,file=FreeBSD-14.3-RELEASE-arm64-aarch64-ufs.qcow2,id=hd0 \
-device virtio-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22
This worked well, but as I installed more packages I eventually hit a weird error:
elf_load_section: truncated ELF file
The error appeared while a program was trying to read a text file. I initially thought the precompiled program installed via pkg
was broken, but after searching I noticed others had similar issues. The following was particularly enlightening:
[1] Try recompile or reinstall devel/qt4-rcc.
[2] You are brilliant! I thought that the error message “elf_load_section: truncated ELF file” was being issued by qt4-rcc, which was reporting a failure to compile a file, for some reason.
In fact, the message was being issued by the shell, which was reporting a failure to invoke the qt4-rcc command, because qt4-rcc itself was truncated, perhaps because I originally built it when my virtual computer was low on disk storage, before I purchased two more virtual filesystems from amazon.com for /usr/ports and /usr/local.
That made me realize I might be low on disk space. Running df -h
showed the root filesystem was 88% full. Oddly, about 500 MB was still free — not much. The vanilla image comes with 4 or 6 GB of storage, so it’s a good idea to resize it. I asked Claude for help, and its suggestions matched what I later found in the official docs. In summary, the steps were:
- Resize the image file:
qemu-img resize VM10G.raw 15GB
. - Fix disk partitions: log into the VM and run
gpart show
andgpart recover vtbd0
. - Resize the
freebsd-ufs
partition; the exact command depends ongpart show
, but for me it wasgpart resize -i 3 vtbd0
. - Grow the UFS filesystem.
Step 4 caused me a headache. Claude suggested growfs /dev/vtbd0p3
, but I got:
# growfs /dev/vtbd0p3
It's strongly recommended to make a backup before growing the file system.
OK to grow file system on /dev/vtbd0p4 from 5.0GB to 64GB? [yes/no] yes
growfs: /dev/vtbd0p4: Operation not permitted
Claude then hallucinated a bit and suggested booting into single-user mode and other steps. It even suggested logging in via an ISO because FreeBSD had “stricter validations around resizing” or something. I tried single-user login, but got suspicious at the ISO advice and looked elsewhere. I eventually found Bug 237392 - growfs: operation not permitted. The report reproduced my error and noted that running growfs /
worked. That fixed step 4.
Once I had enough disk space on the VM, I reinstalled all packages to make sure I wouldn’t hit the error elsewhere:
sudo pkg upgrade -f
I haven’t seen the truncated ELF issue since.