Qemu下如何启动FreeBSD镜像

How to boot FreeBSD image under Qemu

我有一个包含 /boot/loader* 和 /boot/kernel 等的 FreeBSD 映像。它在 EC2 实例下启动良好,但我想用 Qemu 启动它。我尝试了各种方法,但都没有用。见下文。

qemu-system-x86_64 -kernel kernel -nographic -append 'console=ttyS0' disk.img
qemu-system-x86_64 -kernel loader -nographic -append disk.img

FreeBSD wiki 有一些如何在 Qemu 中 运行FreeBSD 的方法

https://wiki.freebsd.org/QemuRecipes

这会在 Ubuntu 20.04 amd64 主机,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

用户名是root,密码为空:

该图像的下载页面是:https://www.freebsd.org/where.html

很遗憾,正在尝试添加:

-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 提到了如何通过修改图像来解决这个问题,这很烦人,但很有效。在 GUI 启动时,我做了:

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

然后下一个 nographic 引导在我的终端上完全运行。

您可以使用 Ctrl-A X 退出 QEMU -nographic,如下所示:https://superuser.com/questions/1087859/how-to-quit-the-qemu-monitor-when-not-using-a-gui/1211516#1211516

下一个问题是磁盘已满,我必须学会增加它的大小。通过交互式 df -Th 检查,图像似乎包含单个原始 UFS 分区。我试过了:

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

但这可能还不够,因为分区本身没有调整大小以适应磁盘。可能这可以通过 gpart 实现,如下所示:https://www.freebsd.org/doc/handbook/disks-growing.html 但我现在没有耐心。