install_kvm.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. <dns enable="no"/>
  16. </network>
  17. EOL
  18. virsh net-define /tmp/host-bridge.xml
  19. virsh net-autostart host-bridge
  20. virsh net-start host-bridge
  21. rm /tmp/host-bridge.xml
  22. # Create isolated network (without DHCP)
  23. cat >/tmp/isolated-bridge.xml <<EOL
  24. <network>
  25. <name>isolated-bridge</name>
  26. <forward mode="bridge"/>
  27. <bridge name="br1"/>
  28. <dns enable="no"/>
  29. </network>
  30. EOL
  31. virsh net-define /tmp/isolated-bridge.xml
  32. virsh net-autostart isolated-bridge
  33. virsh net-start isolated-bridge
  34. rm /tmp/isolated-bridge.xml
  35. # List networks
  36. virsh net-list
  37. # Allow admin to use libvirt
  38. sudo usermod -a -G libvirt admin