;;
创建 vm:
#!/usr/bin/env zsh bridgeIF=bridge0 laggIF=lagg0 tapIF=tap0 phyIF_0=re0 phyIF_1=em0 isoPath=../ISOs/ubuntu.iso volPath=/dev/zvol/zdata/ubuntu vmName=ubuntu cpuNum=4 memSize=4096M volSize=200G kldload vmm kldload if_tap kldload if_lagg kldload if_bridge sysctl net.link.tap.uponopen=1 addr=192.168.0.254/24 router=192.168.0.1 for x in $phyIF_0 $phyIF_1 do ifconfig $x inet delete ifconfig $x inet6 delete done for x in $laggIF $tapIF $bridgeIF do ifconfig $x destroy done ifconfig lagg0 create # Avaliable Mode: lacp/roundrobin/failover/broadcast ifconfig lagg0 laggproto failover laggport $phyIF_0 laggport $phyIF_1 # Make sense for roundrobin only #ifconfig lagg0 rr_limit 1000 ifconfig $tapIF create ifconfig $bridgeIF create ifconfig $bridgeIF addm $laggIF addm $tapIF ifconfig $bridgeIF inet $addr route flush route add default $router for x in $phyIF_0 $phyIF_1 $laggIF $tapIF $bridgeIF do ifconfig $x up done for x in $laggIF $tapIF $bridgeIF do ifconfig $x promisc done # Install only #zfs create -V $volSize -o volmode=dev zdata/$vmName bhyvectl --destroy --vm=$vmName echo "(hd0) $volPath" > device.map # Install only #echo "(cd0) $isoPath" >> device.map # Install only #grub-bhyve -m ./device.map -r cd0 -M $memSize $vmName grub-bhyve -m ./device.map -r hd0,msdos1 -M $memSize $vmName #grub> linux (hd0,msdos1)/vmlinuz-XXX root=/dev/sdXN #grub> initrd (hd0,msdos1)/initramfs-XXX #grub> boot bhyve -AHP \ -s 0:0,hostbridge \ -s 1:0,lpc \ -s 2:0,virtio-net,$tapIF \ -s 3:0,virtio-blk,$volPath \ -s 4:0,ahci-cd,$isoPath \ -c $cpuNum \ -m $memSize \ -l com1,stdio \ $vmName 2>/dev/null &
管理 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"