install_kvm.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # Install KVM
  3. # bridge-utils are not required but useful for debugging
  4. apt-get install --no-install-recommends \
  5. qemu-system qemu-utils libvirt-clients libvirt-daemon-system ovmf bridge-utils
  6. # Remove virbr0 NAT interface created during the kvm installation
  7. virsh net-destroy default
  8. virsh net-undefine default
  9. # Create network from exisiting host bridge
  10. cat >/tmp/host-bridge.xml <<EOL
  11. <network>
  12. <name>host-bridge</name>
  13. <forward mode="bridge"/>
  14. <bridge name="br0"/>
  15. </network>
  16. EOL
  17. virsh net-define /tmp/host-bridge.xml
  18. virsh net-autostart host-bridge
  19. virsh net-start host-bridge
  20. rm /tmp/host-bridge.xml
  21. # Create isolated network (without DHCP)
  22. cat >/tmp/isolated-bridge.xml <<EOL
  23. <network>
  24. <name>isolated-bridge</name>
  25. <forward mode="bridge"/>
  26. <bridge name="br1"/>
  27. </network>
  28. EOL
  29. virsh net-define /tmp/isolated-bridge.xml
  30. virsh net-autostart isolated-bridge
  31. virsh net-start isolated-bridge
  32. rm /tmp/isolated-bridge.xml
  33. # List networks
  34. virsh net-list
  35. # Allow admin to use libvirt
  36. sudo usermod -a -G libvirt admin