vmstart (1586B)
1 #!/bin/sh 2 3 usage() 4 { 5 echo "usage: ${0##*/} [-uv] [-c cpu] [-C com] [-d disksiz] [-g grub_bootdrv]" 1>&2 6 echo " [-G grub_bootdir] [-i img] [-m mem] [-t tap] name" 1>&2 7 exit 1 8 } 9 10 err() 11 { 12 echo "${0##*/} ${@}" 1>&2 13 exit 1 14 } 15 16 cpu="2" 17 mem="2G" 18 disk="disk.img" 19 tap="tap0" 20 vnc="no" 21 uefifile="/usr/local/share/uefi-firmware/BHYVE_UEFI.fd" 22 23 # TODO man page? 24 # TODO merge vmstart and vmstop to `vm <start/stop> ...`? (find new name in this case) 25 # TODO virtio-blk 26 # TODO does grub work properly? 27 28 while getopts "c:C:d:g:G:i:m:t:uv" arg; do 29 case "${arg}" in 30 c) cpu="${OPTARG}" ;; 31 C) com="${OPTARG}" ;; 32 d) disksiz="${OPTARG}" ;; 33 g) grubdrv="${OPTARG}" ;; 34 G) grubdir="${OPTARG}" ;; 35 i) img="${OPTARG}" ;; 36 m) mem="${OPTARG}" ;; 37 t) tap="${OPTARG}" ;; 38 u) uefi="-l bootrom,${uefifile}" ;; 39 v) vnc="-s 29,fbuf,tcp=0.0.0.0:5900,wait" ;; 40 *) usage ;; 41 esac 42 done 43 shift $((OPTIND - 1)) 44 45 name="${1}" 46 test -z "${name}" && usage 47 48 test ! -f ${uefifile} && \ 49 err "${uefifile} not found. Install $(pkg search uefi-edk | awk '{print $1}')" 50 51 ifconfig "${tap}" up || exit 1 52 53 test -n "${disksiz}" && truncate -s "${disksiz}" ${disk} 54 55 if [ -n "${grubdrv}" ]; then 56 echo "(hd0) disk.img" > device.map 57 ${img:+(cd0) ${img}} >> device.map 58 grub-bhyve \ 59 -m device.map \ 60 -r ${grubdrv} \ 61 ${grubdir:+-d ${grubdir}} \ 62 -M ${mem} \ 63 ${name} 64 fi 65 66 bhyve \ 67 -wHAP \ 68 -c ${cpu} \ 69 -m ${mem} \ 70 -s 0,hostbridge \ 71 ${img:+-s 3,ahci-cd,${img}} \ 72 -s 4,ahci-hd,${disk} \ 73 -s 5,virtio-net,${tap} \ 74 ${vnc:+${vnc}} \ 75 -s 30,xhci,tablet \ 76 -s 31,lpc \ 77 ${com:+-l com1,${com}} \ 78 ${uefi:+${uefi}} \ 79 ${name}