configure_virtualization.ksh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/ksh
  2. release=$(uname -r)
  3. release_brief=$(echo $release | tr -d ".")
  4. print "INFO: Checking CPU capabilities..."
  5. dmesg | egrep '(VMX/EPT|SVM/RVI)'
  6. print "INFO: Enable and start vmd..."
  7. doas rcctl enable vmd
  8. doas rcctl start vmd
  9. print "INFO: Enable and start vmd... DONE"
  10. print "INFO: Creating VMs directory in ~/vms..."
  11. mkdir -p ~/vms
  12. print "INFO: Creating VMs directory in ~/vms... DONE"
  13. if [ ! -d ~/isos/openbsd/$release ]; then
  14. print "INFO: Downloading latest RELEASE iso image..."
  15. mkdir -p ~/isos/openbsd/$release
  16. cd ~/isos/openbsd/$release
  17. curl -OL "https://cdn.openbsd.org/pub/OpenBSD/$release/amd64/SHA256"
  18. curl -OL "https://cdn.openbsd.org/pub/OpenBSD/$release/amd64/SHA256.sig"
  19. curl -OL "https://cdn.openbsd.org/pub/OpenBSD/$release/amd64/miniroot$release_brief.img"
  20. curl -OL "https://cdn.openbsd.org/pub/OpenBSD/$release/amd64/cd$release_brief.iso"
  21. print "INFO: Downloading latest RELEASE iso image... DONE"
  22. fi
  23. if [ ! -f /etc/hostname.vether0 ]; then
  24. print "INFO: Configuring network bridge..."
  25. echo 'inet 10.0.0.1 255.255.255.0' | doas tee -a /etc/hostname.vether0
  26. doas sh /etc/netstart vether0
  27. fi
  28. if [ ! -f /etc/hostname.bridge0 ]; then
  29. echo 'add vether0' | doas tee -a /etc/hostname.bridge0
  30. doas sh /etc/netstart bridge0
  31. print "INFO: Configuring network bridge... DONE"
  32. fi
  33. print ""
  34. print "To create a new VM:"
  35. print " $ vmctl create -s 10G ~/vms/openbsd_$release_brief.qcow2"
  36. print " $ doas vmctl start -m 1G -L -i 1 -r ~/isos/openbsd/$release/cd$release_brief.iso -d ~/vms/openbsd_$release_brief.qcow2 openbsd_$release_brief"
  37. print " $ vmctl show"
  38. print " $ doas vmctl console openbsd_$release_brief"
  39. print " $ doas vmctl stop openbsd_$release_brief"
  40. print ""