Mua hàng tại Link Shopee hoặc Hotline 0345-148-136.

Linux VM on FreeBSD bhyve

I’ve been using FreeBSD on my server for a while and it work very well.

Today I want to install memos on this server but I couldn’t build its ui in FreeBSD jail. pnpm is not support FreeBSD yet.

So if I want to run memos on this FreeBSD machine then I need to build web ui somewhere else. I used to build program from source in FreeBSD jail, now I need to build them in Linux jail or Linux VM.

I thought that I need to make some Linux VMs on my FreeBSD server, it called bhyve. There are several bhyve managers since I don’t want to do it manual:

  • CBSD – a management layer written for the FreeBSD jail(8) subsystem, bhyve , QEMU / NVMM. and Xen
  • vm-bhyve – Shell based, minimal dependency bhyve manager
  • bmd – Bhyve Management Daemon

CBSD is overkill for my need because I already had other jail manager software. bmd is quite young, so I go with vm-bhyve.

Install vm-bhyve and make Linux VM on it was simple:

# pkg install sysutils/grub2-bhyve sysutils/bhyve-firmware
# pkg install vm-bhyve
# zfs create mypool/vm
# sysrc vm_enable="YES"
# sysrc vm_dir="zfs:pool/vm"
# vm init
# cp /usr/local/share/examples/vm-bhyve/* /mypool/vm/.templates/
# vm switch create -a 192.168.8.1/24 public
# echo "nat on re0 from {192.168.8.0/24} to any -> (re0)" >> /etc/pf.conf
# service pf restart
# vm iso https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso
# vm create -t debian mydebian
# vm install -f mydebian debian-12.5.0-amd64-netinst.iso

And install Debian just like I was using a real machine.

Note that:

  • My network interface is “re0” and I already have pf running
  • I also need to set static IP for Linux VM because I didn’t want to run a DHCP
  • For for information about NAT you can read here.

I think bhyve is good for your system because it is lightweight. I feel like I was running an jail, of course when the vm was idle.

You may want to check its wiki, it is not very good but helpful.

I wanted to make my VM auto start when FreeBSD boot so I added these lines to /etc/rc.conf

vm_list="mydebian"
vm_delay="5"

It may not work because of cu console, you need to change it to tmux

# pkg install tmux
# vm set console=tmux


Comments

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *