Hosts/BSD: Difference between revisions
(→NetBSD) |
(Mention capstone as optional dependency) |
||
(40 intermediate revisions by 6 users not shown) | |||
Line 15: | Line 15: | ||
Run the image with: | Run the image with: | ||
qemu-system-x86_64 -m 2048 -hda FreeBSD-11.0-RELEASE-amd64.qcow2 -enable-kvm -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 -device e1000,netdev=mynet0 | qemu-system-x86_64 -m 2048 \ | ||
-hda FreeBSD-11.0-RELEASE-amd64.qcow2 -enable-kvm \ | |||
-netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ | |||
-device e1000,netdev=mynet0 | |||
(TODO: check virtio works and recommend that instead.) | (TODO: check virtio works and recommend that instead.) | ||
Line 40: | Line 43: | ||
Install enough packages to do builds: | Install enough packages to do builds: | ||
pkg update | pkg update | ||
pkg install git | pkg install git gcc gmake python pkgconf pixman bison glib | ||
It is also recommended to install these packages for additional features and testing: | |||
pkg install bash capstone4 gsed curl nettle png usbredir devel/sdl20 | |||
=== Building === | === Building === | ||
Line 70: | Line 68: | ||
Get installer, create disk: | Get installer, create disk: | ||
qemu-img create -f qcow2 disk.qcow2 | qemu-img create -f qcow2 disk.qcow2 32G | ||
wget https://www.mirrorservice.org/pub/OpenBSD/6. | wget https://www.mirrorservice.org/pub/OpenBSD/6.5/amd64/cd65.iso | ||
Run installer: | Run installer: | ||
qemu-system-x86_64 -m 2048 - | qemu-system-x86_64 -m 2048 \ | ||
-cdrom cd65.iso \ | |||
-drive if=virtio,file=disk.qcow2,format=qcow2 \ | |||
-enable-kvm \ | |||
-netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ | |||
-device virtio-net,netdev=mynet0 \ | |||
-smp 2 | |||
Follow the straightforward install prompts (accepting defaults generally OK). | Follow the straightforward install prompts (accepting defaults generally OK). | ||
You'll want to enable sshd and allow logins with prohibit-password. | You'll want to enable sshd and allow logins with prohibit-password. | ||
NB: it's important to run the installer with more than one CPU, or it will not install the SMP kernel. To fix this and add the SMP kernel after the initial install enter 'boot hd0a:bsd.rd' at the bootloader prompt to re-run the installer and add the 'bsd.mp' layer. | |||
Reboot when it asks, and when it's rebooted kill the QEMU VM. | Reboot when it asks, and when it's rebooted kill the QEMU VM. | ||
Line 84: | Line 90: | ||
Now run the VM on the installed image: | Now run the VM on the installed image: | ||
qemu-system-x86_64 -m 2048 -drive if=virtio,file=disk.qcow2,format=qcow2 -enable-kvm -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 -device | qemu-system-x86_64 -m 2048 \ | ||
-drive if=virtio,file=disk.qcow2,format=qcow2 \ | |||
-enable-kvm \ | |||
-netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ | |||
-device virtio-net,netdev=mynet0 | |||
Copy your ssh public key into root's .ssh/authorized_keys | Copy your ssh public key into root's .ssh/authorized_keys | ||
ssh-copy-id root@localhost | |||
You should now be able to get in to the VM with | You should now be able to get in to the VM with | ||
ssh | ssh root@localhost | ||
Make sure that the filesystem you're building and running QEMU from has the "wxallowed" option set in /etc/fstab, like: | |||
d3651b0622794af6.k /home ffs rw,wxallowed,nodev,nosuid 1 2 | |||
then either reboot or use "mount -uo wxallowed /wherever" to set it for this session. | |||
(This is necessary because QEMU assumes it can map memory RWX for TCG and 'make check' will fail if it can't.) | |||
=== Required packages === | === Required packages === | ||
Line 97: | Line 114: | ||
pkg_add git | pkg_add git | ||
pkg_add gmake | pkg_add gmake | ||
pkg_add glib2 | pkg_add glib2 | ||
pkg_add | pkg_add ninja | ||
pkg_add | |||
Optional dependencies if you want to run the test framework | |||
pkg_add bash | |||
pkg_add gsed | |||
Other recommended packages: | |||
pkg_add capstone | |||
pkg_add sdl2 | |||
=== Building === | |||
You can configure and build QEMU as you would on Linux: | |||
mkdir build | mkdir build | ||
cd build | cd build | ||
../configure | ../configure | ||
gmake | gmake | ||
== NetBSD == | == NetBSD == | ||
Create a disk image, and grab the install cd image: | Create a disk image, and grab the install cd image: | ||
Line 128: | Line 144: | ||
wget http://cdn.netbsd.org/pub/NetBSD/NetBSD-7.1/images/NetBSD-7.1-amd64.iso | wget http://cdn.netbsd.org/pub/NetBSD/NetBSD-7.1/images/NetBSD-7.1-amd64.iso | ||
Run the installer | Run the installer: | ||
qemu-system-x86_64 -m 2048 -enable-kvm \ | qemu-system-x86_64 -m 2048 -enable-kvm \ | ||
Line 136: | Line 152: | ||
-cdrom NetBSD-7.1-amd64.iso | -cdrom NetBSD-7.1-amd64.iso | ||
The defaults will generally do. When it gets to the big menu of things to configure at the end of the install: configure networking (select defaults); enable NTP and ntpdate; enable ssh; set a root password. | |||
Reboot into the installed system. Edit /etc/ssh/sshd_config to set 'PermitRootLogin: without-password', and set up ssh authorized keys. | |||
Now you can run the installed image: | |||
qemu-system-x86_64 -m 2048 \ | |||
-drive if=virtio,file=disk.qcow2,format=qcow2 \ | |||
-enable-kvm \ | |||
-netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ | |||
-device e1000,netdev=mynet0 | |||
You should now be able to get in to the VM with | |||
ssh -p 7722 root@localhost | |||
=== Required packages === | |||
Run this to make pkg_add actually work: | |||
export PKG_PATH="http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/<PORT>/<RELEASE-NUMBER>/All" | |||
Then install dependencies: | |||
pkg_add git gmake python37 glib2 bison pkgconf pixman | |||
Recommended optional dependencies: | |||
pkg_add capstone SDL2 bash | |||
=== Building === | |||
You can configure and build QEMU as you would on Linux: | |||
mkdir build | |||
cd build | |||
../configure --python=python2.7 | |||
gmake | |||
gmake check | |||
Note that you need to use 'gmake', not plain 'make'. | |||
== DragonFly BSD == | |||
=== Resources for the installation === | |||
There are two options here. One is to use the USB image to boot from it directly, as a raw image, the other one is to use the ISO and install dfly on | |||
the qemu host. | |||
Fetch either daily snapshot or the release ISO/image files, links below. At the moment of this writing latest stable version is 4.8.1. | |||
'''USB image''' | |||
Stable release: [http://avalon.dragonflybsd.org/iso-images/dfly-x86_64-4.8.1_REL.img.bz2 IMG.bz2] | |||
Daily snapshot: [http://avalon.dragonflybsd.org/snapshots/x86_64/DragonFly-x86_64-LATEST-IMG.img.bz2 IMG.bz2] | |||
'''ISO image''' | |||
Stable release: [http://avalon.dragonflybsd.org/iso-images/dfly-x86_64-4.8.1_REL.iso.bz2 ISO.bz2] | |||
Daily snapshot: [http://avalon.dragonflybsd.org/snapshots/x86_64/DragonFly-x86_64-LATEST-ISO.iso.bz2 ISO.bz2] | |||
=== VM Setup === | |||
'''Option 1. Using the USB IMG file''' | |||
No need to create a disk image as the USB image itself will act as the raw image disk file for qemu: | |||
qemu-system-x86_64 -m 2048 \ | |||
-drive if=virtio,file=DragonFly-x86_64-LATEST-IMG.img,format=raw \ | |||
-netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ | |||
-device e1000,netdev=mynet0 | |||
Note: You will likely find this error while booting. There is a way to make this permanent which is explained below. | |||
Manual root filesystem specification: | |||
<fstype>:<device> Specify root (e.g. ufs:da0s1a) | |||
? List valid disk boot devices | |||
panic Just panic | |||
abort Abort manual input | |||
mountroot> ? | |||
Possibly valid devices for root FS: | |||
"vn0" "vn1" "vn2" "vn3" "md0" "md0s0" "acd0" "vbd0" "vbd0s1" "vbd0s2" | |||
"vbd0s2a" "cd0" "sg0" | |||
mountroot> ufs:vbd0s2a | |||
Mounting root from ufs:vbd0s2a | |||
DMA space used: 1192k, remaining available: 127912k | |||
Mounting devfs | |||
[...] | |||
To set a device for booting permanently on the USB image: | |||
login: root | |||
Last login: Tue Sep 12 17:44:26 2017 on ttyv0 | |||
Copyright (c) 2003-2017 The DragonFly Project. | |||
Copyright (c) 1992-2003 The FreeBSD Project. | |||
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 | |||
The Regents of the University of California. All rights reserved. | |||
DragonFly v4.9.0.653.g8e456-DEVELOPMENT (X86_64_GENERIC) #0: Tue Sep 12 10:48:26 UTC 2017 | |||
Welcome to DragonFly! | |||
# echo 'vfs.root.mountfrom=ufs:vbd0s2a' >> /boot/loader.conf | |||
# reboot | |||
'''Option 2. Installing from the ISO image''' | |||
Depending on whether you're going to use UFS or HAMMER you are encouraged to use a specific HDD size since HAMMER works better with +50GB disks. | |||
Of course this is not mandatory and you can use whatever size you prefer as long as it's bigger than 10GB. | |||
Create a virtual disk: | |||
qemu-img create -f qcow2 disk.qcow2 15G | |||
Run qemu and boot from CD | |||
qemu-system-x86_64 -m 2048 -boot d \ | |||
-cdrom DragonFly-x86_64-LATEST-ISO.iso \ | |||
-drive if=virtio,file=disk.qcow2,format=qcow2 \ | |||
-netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ | |||
-device e1000,netdev=mynet0 | |||
For installation instructions you can follow this guide, section "Long Walkthrough of DragonFly BSD Installation and Configuration", | |||
although it might not be completely accurate it is a good one: https://www.dragonflybsd.org/varialus/ | |||
=== Configuration === | |||
Enable networking and ssh by adding these lines to /etc/rc.conf: | |||
sshd_enable="YES" | |||
ifconfig_em0="DHCP" | |||
Copy your ssh public key into the VM's /root/.ssh/authorized_keys | |||
You should now be able to ssh into the VM from outside with | |||
ssh -p 7722 root@localhost | |||
=== Required packages === | |||
Install enough packages to do builds: | |||
pkg install git python pkgconf glib | |||
gcc and binutils are in the base distribution so no need to install them. pixmap is now of of the submodules, so no need to install it either. | |||
=== Building === | |||
Instructions from https://www.qemu.org/download/#source: | |||
git clone git://git.qemu.org/qemu.git | |||
cd qemu | |||
git submodule init | |||
git submodule update --recursive | |||
./configure --prefix=/opt/local | |||
gmake | |||
gmake check | |||
'''NOTE: '''You need to use 'gmake', not plain 'make'. | |||
'''NOTE-2: '''Do not use default /usr/local as it is the place where the package system installs the software. |
Latest revision as of 12:41, 23 May 2022
QEMU on BSD hosts
This documentation is not written by a BSD expert - corrections welcome!
QEMU can be built on BSD hosts. At the moment most QEMU developers are Linux users, though, so BSD is not very well supported.
This page includes documentation of how to get the various BSD flavours running in a VM inside QEMU, so that Linux-based developers can do build tests on them. If you're running natively on BSD you can ignore the "VM setup" instructions.
FreeBSD
VM setup
Download and uncompress the official FreeBSD qcow2 image from
https://download.freebsd.org/ftp/releases/VM-IMAGES/11.0-RELEASE/amd64/Latest/
Run the image with:
qemu-system-x86_64 -m 2048 \ -hda FreeBSD-11.0-RELEASE-amd64.qcow2 -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ -device e1000,netdev=mynet0
(TODO: check virtio works and recommend that instead.)
Enable networking and ssh by adding these lines to /etc/rc.conf:
sshd_enable="YES" ifconfig_em0="DHCP"
Edit /etc/ssh/sshd_config to add
PermitRootLogin prohibit-password
and then reboot the VM or run
service netif restart service sshd start
Copy your ssh public key into the VM's /root/.ssh/authorized_keys
You should now be able to ssh into the VM from outside with
ssh -p 7722 root@localhost
Required packages
Install enough packages to do builds:
pkg update pkg install git gcc gmake python pkgconf pixman bison glib
It is also recommended to install these packages for additional features and testing:
pkg install bash capstone4 gsed curl nettle png usbredir devel/sdl20
Building
You can configure and build QEMU as you would on Linux:
mkdir build cd build ../configure gmake gmake check
Note that you need to use 'gmake', not plain 'make'.
(NB as of 2017-03-20 you'll also need --disable-user to work around a QEMU bug.)
OpenBSD
VM setup
Get installer, create disk:
qemu-img create -f qcow2 disk.qcow2 32G wget https://www.mirrorservice.org/pub/OpenBSD/6.5/amd64/cd65.iso
Run installer:
qemu-system-x86_64 -m 2048 \ -cdrom cd65.iso \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ -device virtio-net,netdev=mynet0 \ -smp 2
Follow the straightforward install prompts (accepting defaults generally OK). You'll want to enable sshd and allow logins with prohibit-password.
NB: it's important to run the installer with more than one CPU, or it will not install the SMP kernel. To fix this and add the SMP kernel after the initial install enter 'boot hd0a:bsd.rd' at the bootloader prompt to re-run the installer and add the 'bsd.mp' layer.
Reboot when it asks, and when it's rebooted kill the QEMU VM.
Now run the VM on the installed image:
qemu-system-x86_64 -m 2048 \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ -device virtio-net,netdev=mynet0
Copy your ssh public key into root's .ssh/authorized_keys
ssh-copy-id root@localhost
You should now be able to get in to the VM with
ssh root@localhost
Make sure that the filesystem you're building and running QEMU from has the "wxallowed" option set in /etc/fstab, like:
d3651b0622794af6.k /home ffs rw,wxallowed,nodev,nosuid 1 2
then either reboot or use "mount -uo wxallowed /wherever" to set it for this session. (This is necessary because QEMU assumes it can map memory RWX for TCG and 'make check' will fail if it can't.)
Required packages
Install enough packages to build QEMU
pkg_add git pkg_add gmake pkg_add glib2 pkg_add ninja
Optional dependencies if you want to run the test framework
pkg_add bash pkg_add gsed
Other recommended packages:
pkg_add capstone pkg_add sdl2
Building
You can configure and build QEMU as you would on Linux:
mkdir build cd build ../configure gmake
NetBSD
Create a disk image, and grab the install cd image:
qemu-img create -f qcow2 disk.qcow2 15G wget http://cdn.netbsd.org/pub/NetBSD/NetBSD-7.1/images/NetBSD-7.1-amd64.iso
Run the installer:
qemu-system-x86_64 -m 2048 -enable-kvm \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ -device e1000,netdev=mynet0 \ -cdrom NetBSD-7.1-amd64.iso
The defaults will generally do. When it gets to the big menu of things to configure at the end of the install: configure networking (select defaults); enable NTP and ntpdate; enable ssh; set a root password.
Reboot into the installed system. Edit /etc/ssh/sshd_config to set 'PermitRootLogin: without-password', and set up ssh authorized keys.
Now you can run the installed image:
qemu-system-x86_64 -m 2048 \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ -device e1000,netdev=mynet0
You should now be able to get in to the VM with
ssh -p 7722 root@localhost
Required packages
Run this to make pkg_add actually work:
export PKG_PATH="http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/<PORT>/<RELEASE-NUMBER>/All"
Then install dependencies:
pkg_add git gmake python37 glib2 bison pkgconf pixman
Recommended optional dependencies:
pkg_add capstone SDL2 bash
Building
You can configure and build QEMU as you would on Linux:
mkdir build cd build ../configure --python=python2.7 gmake gmake check
Note that you need to use 'gmake', not plain 'make'.
DragonFly BSD
Resources for the installation
There are two options here. One is to use the USB image to boot from it directly, as a raw image, the other one is to use the ISO and install dfly on the qemu host.
Fetch either daily snapshot or the release ISO/image files, links below. At the moment of this writing latest stable version is 4.8.1.
USB image
Stable release: IMG.bz2
Daily snapshot: IMG.bz2
ISO image
Stable release: ISO.bz2
Daily snapshot: ISO.bz2
VM Setup
Option 1. Using the USB IMG file
No need to create a disk image as the USB image itself will act as the raw image disk file for qemu:
qemu-system-x86_64 -m 2048 \ -drive if=virtio,file=DragonFly-x86_64-LATEST-IMG.img,format=raw \ -netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ -device e1000,netdev=mynet0
Note: You will likely find this error while booting. There is a way to make this permanent which is explained below.
Manual root filesystem specification: <fstype>:<device> Specify root (e.g. ufs:da0s1a) ? List valid disk boot devices panic Just panic abort Abort manual input mountroot> ? Possibly valid devices for root FS: "vn0" "vn1" "vn2" "vn3" "md0" "md0s0" "acd0" "vbd0" "vbd0s1" "vbd0s2" "vbd0s2a" "cd0" "sg0"
mountroot> ufs:vbd0s2a Mounting root from ufs:vbd0s2a DMA space used: 1192k, remaining available: 127912k Mounting devfs [...]
To set a device for booting permanently on the USB image:
login: root Last login: Tue Sep 12 17:44:26 2017 on ttyv0 Copyright (c) 2003-2017 The DragonFly Project. Copyright (c) 1992-2003 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. DragonFly v4.9.0.653.g8e456-DEVELOPMENT (X86_64_GENERIC) #0: Tue Sep 12 10:48:26 UTC 2017 Welcome to DragonFly! # echo 'vfs.root.mountfrom=ufs:vbd0s2a' >> /boot/loader.conf # reboot
Option 2. Installing from the ISO image
Depending on whether you're going to use UFS or HAMMER you are encouraged to use a specific HDD size since HAMMER works better with +50GB disks. Of course this is not mandatory and you can use whatever size you prefer as long as it's bigger than 10GB.
Create a virtual disk:
qemu-img create -f qcow2 disk.qcow2 15G
Run qemu and boot from CD
qemu-system-x86_64 -m 2048 -boot d \ -cdrom DragonFly-x86_64-LATEST-ISO.iso \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ -device e1000,netdev=mynet0
For installation instructions you can follow this guide, section "Long Walkthrough of DragonFly BSD Installation and Configuration", although it might not be completely accurate it is a good one: https://www.dragonflybsd.org/varialus/
Configuration
Enable networking and ssh by adding these lines to /etc/rc.conf:
sshd_enable="YES" ifconfig_em0="DHCP"
Copy your ssh public key into the VM's /root/.ssh/authorized_keys
You should now be able to ssh into the VM from outside with
ssh -p 7722 root@localhost
Required packages
Install enough packages to do builds:
pkg install git python pkgconf glib
gcc and binutils are in the base distribution so no need to install them. pixmap is now of of the submodules, so no need to install it either.
Building
Instructions from https://www.qemu.org/download/#source:
git clone git://git.qemu.org/qemu.git cd qemu git submodule init git submodule update --recursive ./configure --prefix=/opt/local gmake gmake check
NOTE: You need to use 'gmake', not plain 'make'.
NOTE-2: Do not use default /usr/local as it is the place where the package system installs the software.