首页 > 代码库 > FreeBSD_11-系统管理——{Part_10 - bhyve}

FreeBSD_11-系统管理——{Part_10 - bhyve}

创建 vm:

#!/usr/bin/env zsh

tap_IF=tap0
bridge_IF=bridge0
physical_IF=re0

iso_Path=/bhyve/ISO/CentOS.iso
vol_Path=/dev/zvol/zdata/linux_0
uefi_Path=/usr/local/share/uefi-firmware/BHYVE_UEFI.fd

vm_Name=gentoo
cpu_Num=2
mem_Size=2048M
vol_Size=24G

kldload vmm 
kldload if_tap
sysctl net.link.tap.up_on_open=1

ifconfig $tap_IF create
ifconfig $bridge_IF create
ifconfig $bridge_IF addm $physical_IF addm $tap_IF
ifconfig $bridge_IF up

zfs create -V $vol_Size -o volmode=dev zroot/$vm_Name

# cd /usr/ports/sysutils/bhyve-firmware
# make install clean
bhyve -AHP     -s 0:0,hostbridge     -s 1:0,lpc     -s 2:0,virtio-net,$tap_IF     -s 3:0,virtio-blk,$vol_Path     -s 4:0,ahci-cd,$iso_Path     -c $cpu_Num     -m $mem_Size     -l bootrom,$uefi_Path     $vm_Name

管理 vm:

  • ls -al /dev/vmm
  • bhyvectl --destroy --vm=guest_Name

配置文件:

  • /etc/sysctl.conf
    • net.link.tap.up_on_open=1
  • /boot/loader.conf
    • vmm_load="YES"
    • if_bridge_load="YES"
    • if_tap_load="YES"
  • /etc/rc.conf
    • cloned_interfaces="bridge_Name tap_Name"
    • ifconfig_bridge0="addm if_Name addm tap_Name"

FreeBSD_11-系统管理——{Part_10 - bhyve}