6

I have a FreeBSD image that contains /boot/loader* and /boot/kernel and more. It boots fine under an EC2 instance but I would like to boot it with Qemu. I have tried various methods, but they have not worked. See below.

qemu-system-x86_64 -kernel kernel -nographic -append 'console=ttyS0' disk.img
qemu-system-x86_64 -kernel loader -nographic -append disk.img
Steven P
  • 185
  • 2
  • 10

2 Answers2

6

This boots on Ubuntu 20.04 amd64 host, QEMU 4.2.1:

wget https://download.freebsd.org/ftp/releases/VM-IMAGES/12.1-RELEASE/amd64/Latest/FreeBSD-12.1-RELEASE-amd64.qcow2.xz
unxz FreeBSD-12.1-RELEASE-amd64.qcow2.xz
sudo apt install qemu-system-x86
qemu-system-x86_64 -drive file=FreeBSD-12.1-RELEASE-amd64.qcow2,format=qcow2 -enable-kvm

The username is root with empty password:

enter image description here

enter image description here

The download page for that image is: https://www.freebsd.org/where.html

Unfortunately, trying to add:

-serial mon:stdio -nographic

to get rid of the GUI only shows the bootloader images on the terminal, but not the rest of boot. https://lists.freebsd.org/pipermail/freebsd-hackers/2005-March/011051.html mentions how to fix that by modifying the image, which is annoying, but worked. On the GUI boot, I did:

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

and then the next nographic boot worked fully on my terminal.

You can quit QEMU -nographic with Ctrl-A X as shown at: https://superuser.com/questions/1087859/how-to-quit-the-qemu-monitor-when-not-using-a-gui/1211516#1211516

The next issue is that the disk is full, I have to learn to increase its size. From interactive df -Th inspection, the image appears to contain a single raw UFS partition. I tried:

qemu-img resize FreeBSD-12.1-RELEASE-amd64.qcow2 +1G

but that is not enough presumably because the partition itself was not resized to fit the disk. Likely this can be achieved with gpart as shown at: https://www.freebsd.org/doc/handbook/disks-growing.html but I don't have the patience right now.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • The last link (disk-growing) is obsoleted, [here](https://people.freebsd.org/~rodrigc/doc/handbook/disks-growing.html) is the new place. – Feng. Ma Aug 13 '21 at 15:06
  • For those who failed to grow the disk with command in the end: `growfs /dev/`. The reply [here](https://www.digitalocean.com/community/questions/freebsd-growfs-operation-not-permitted-aka-enlarge-your-partition) may help. TL;DR, run command `service growfs onestart` instead. Nevertheless, on my machine, part of the output says `gpart: arg0 'gpt/rootfs': Invalid argument`, but the partition was successfully resized though. – Feng. Ma Aug 13 '21 at 15:31
4

The FreeBSD wiki has some recipes how to run FreeBSD inside Qemu

https://wiki.freebsd.org/QemuRecipes

arved
  • 4,401
  • 4
  • 30
  • 53