Skip to content

[Virtualization] Install FreeBSD Guest on FreeBSD Bhyve Host

Install FreeBSD Guest on FreeBSD Bhyve Host

1. Detect if your local CPU supports Virtualization

For Intel CPU:
# dmesg | grep -i vt-x
For AMD CPU:
# dmesg | grep -i amd-v
If you are running your FreeBSD on local hardware, you are most likely grep some information about vt, but if you are running your FreeBSD on jail/bhyve/old hardware you maybe grep nothing.

2. Prepare vt/network environment and file resources

Download any latest FreeBSD installer image:

FreeBSD-12.2-RELEASE-amd64-disc1.iso

Use vmrun.sh :

# whoami
root
# mkdir ~/bin
# cp /usr/share/examples/bhyve/vmrun.sh ~/bin/                                 
# chmod +x ~/bin/vmrun.sh                                                      
# vmrun.sh -h

Create virtual disk:

# truncate -s 8G freebsd-hd.bhyve

Load vt kernel module (vmm):

# kldload vmm

Let vmm be loaded permanently:

# sysrc kld_list
kld_list: i915kms
# sysrc kld_list+="vmm"
kld_list: i915kms -> i915kms vmm
sysrc kld_list to see what's in the kld_list; sysrc kld_list+="vmm" to add vmm to the kld_list.

Configure bridge network for the bhyve guest os:

Load if_bridge:
# kldload if_tap
# kldload if_bridge
# sysrc kld_list+="if_tap if_bridge"
Create tap and bridge net interface:
# ifconfig tap create
tap0
# ifconfig bridge create
bridge0
# sysctl net.link.tap.up_on_open=1
net.link.tap.up_on_open: 0 -> 1
# ifconfig bridge0 addm tap0 addm wlan0    # Replace wlan0 with your real Internet card.
Keep them once if you reboot computer:
# sysrc cloned_interfaces="tap0 bridge0"
cloned_interfaces:  -> tap0 bridge0
# sysrc ifconfig_bridge0="addm tap0 addm wlan0"
ifconfig_bridge0:  -> addm tap0 addm wlan0
# echo "net.link.tap.up_on_open=1" >> /etc/sysctl.conf

3. Install FreeBSD Guest on Bhyve

Boot the installing process now:

vmrun.sh -c 2 -m 512M -d freebsd-hd.bhyve -i -I FreeBSD-12.2-RELEASE-amd64-disc1.iso FreeBSD-VM-01
Now follow the FreeBSD installer guide, it is very easy to understand and continue!
/  ______               ____   _____ _____  
  |  ____|             |  _ \ / ____|  __ \ 
  | |___ _ __ ___  ___ | |_) | (___ | |  | |
  |  ___| '__/ _ \/ _ \|  _ < \___ \| |  | |
  | |   | | |  __/  __/| |_) |____) | |__| |
  | |   | | |    |    ||     |      |      |
  |_|   |_|  \___|\___||____/|_____/|_____/ 
                                                 ```                        `
 �������������������������������������������    s` `.....---.......--.```   -/
 �                                         �    +o   .--`         /y:`      +.
 �  1. Boot Multi user [Enter]             �     yo`:.            :o      `+-
 �  2. Boot Single user                    �      y/               -/`   -o/
 �  3. Escape to loader prompt             �     .-                  ::/sy+:.
 �  4. Reboot                              �     /                     `--  /
 �  5. Cons: Serial                        �    `:                          :`
 �                                         �    `:                          :`
 �  Options:                               �     /                          /
 �  6. Kernel: default/kernel (1 of 1)     �     .-                        -.
 �  7. Boot Options                        �      --                      -.
 �                                         �       `:`                  `:`
 �                                         �Welcome to FreeBSD       `--.
 �������������������������������������������            .---.....----.

4. Explore your FreeBSD Guest

Boot FreeBSD Virtual Machine Normally:

# vmrun.sh -c 2 -m 512M -d freebsd-hd.bhyve FreeBSD-VM-01

Explore FreeBSD, install pkg, etc.

[Setup in Host] Set IP address to bridge0 as Router

Bridge0 is used as router for the guest, set its ip to 2.2.2.1/24
ifconfig bridge0 inet 2.2.2.1/24

[Setup in Guest] Set a static IP address for Guest

Because there is no DHCP server software installed, the guest must be set with a static ip. Set the guest ip address to 2.2.2.2, and tell it the router ip is 2.2.2.1.
sysrc ifconfig_vtnet0="2.2.2.2/24"
defaultrouter="2.2.2.1"

[Setup in Host] pf NAT forwarding

All net configurations for bhyve guest are done now, but the guest cannot communicate with Internet. We need one more thing: how to redirect the net data between guest and Internet? so we use pf nat.

a. Enable ip forwarding in host:

sysctl net.inet.ip.forwarding=1
b. Enable pf:
sysrc pf_enable="YES"
pf nat for bridge0:
echo "nat on wlan0 from {2.2.2.0/24} to any -> (wlan0)" > /etc/pf.conf
Start pf:
service pf start

The guest can communicate with Internet now!

 

 

 

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options

Submitted comments will be subject to moderation before being displayed.

@freebsdgames.xyz