henrydenhengst

KVM install on Ubuntu 16.04 or Debian 8 host

Sep 16th, 2016
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Installation: KVM
  4. # WebGUI: Kimchi for KVM
  5. # Tested on Ubuntu 16.04 and Debian 8
  6. # Inspiration: https://raymii.org/s/articles/virt-install_introduction_and_copy_paste_distro_install_commands.html
  7. # version 1.00
  8. # written by Henry den Hengst
  9. #
  10. if [[ $EUID -ne 0 ]]; then
  11.    echo "This script must be run as root"
  12.    exit 1
  13. fi
  14. #
  15. # update server
  16. apt-get update && apt-get upgrade -y
  17. #
  18. # for Debian 8
  19. # apt install qemu-kvm libvirt-bin virtinst uuid bridge-utils libosinfo-bin ntp -y
  20. # for ubuntu 16.04:
  21. # apt install qemu-kvm libvirt-bin virtinst uuid bridge-utils libosinfo-bin ntp -y
  22. #
  23. if [[ -r /etc/os-release ]]; then
  24.     . /etc/os-release
  25.     if [[ $ID = ubuntu ]]; then
  26.         apt install qemu-kvm libvirt-bin virtinst uuid bridge-utils libosinfo-bin ntp yum git python-setuptools -y
  27.         # apt install kimchi -y
  28.         # I followed this link and was able to fix the issue: https://github.com/kimchi-project/kimchi/issues/821
  29.         # Basically you need to edit /lib/systemd/system/kimchi.service and change
  30.         #   Requires=libvirtd.service
  31.         #   After=libvirtd.service
  32.         # To:
  33.         #   Requires=libvirt-bin.service
  34.         #   After=libvirt-bin.service
  35.         # and edit /etc/pam.d/kichmi and change:
  36.         #   auth sufficient pam_succeed_if.so user ingroup libvirt
  37.         # To:
  38.         #   auth sufficient pam_succeed_if.so user ingroup libvirtd
  39.         #
  40.         # ufw allow 8000
  41.         # ufw allow 8001
  42.         # ufw allow 64667
  43.     else
  44.         apt install qemu-kvm libvirt-bin virtinst uuid bridge-utils libosinfo-bin ntp git -y
  45.     fi
  46. else
  47.     echo "Not running a distribution with /etc/os-release available"
  48. fi
  49. #
  50. adduser $USER libvirtd
  51. mkdir /iso
  52. mkdir /vm
  53. mkdir /scripts
  54. virsh pool-define-as VMpool01 dir - - - - "/vm/"
  55. virsh pool-build VMpool01
  56. virsh pool-start VMpool01
  57. virsh pool-autostart VMpool01
  58. qemu-img create -f raw /vm/VM-Vol1.img 100G
  59. #
  60. # automated KVM installation scripts of CentOS 7, OpenSUSE 13, Ubuntu 16.04 LTS and Debian 8
  61. cd /scripts
  62. #
  63. # Download Popular Linux Distro ISOs. Put a # before line to skip
  64. cd /iso
  65. wget -c http://releases.ubuntu.com/16.04/ubuntu-16.04.2-server-amd64.iso
  66. wget -c http://ftp.tudelft.nl/centos.org/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1611.iso
  67. wget -c http://frafiles.pfsense.org/mirror/downloads/pfSense-CE-2.3.4-RELEASE-amd64.iso.gz
  68. gunzip pfSense-CE-2.3.4-RELEASE-amd64.iso.gz
  69. wget -c https://cdimage.debian.org/debian-cd/8.8.0/amd64/iso-cd/debian-8.8.0-amd64-netinst.iso
  70. #
  71. # End of Downloading ISOs.
  72. #
  73. # virsh destroy centos7
  74. # virsh undefine centos7
  75. cd /root
  76. osinfo-query os > status.txt
  77. brctl show >> status.txt
  78. virsh pool-info VMpool01 >> status.txt
  79. virsh list >> status.txt
  80. virsh pool-list --all >> status.txt
  81. if [[ -r /etc/os-release ]]; then
  82.     . /etc/os-release
  83.     if [[ $ID = ubuntu ]]; then
  84.         ufw allow 22
  85.         ufw enable
  86.     else
  87.         echo "ufw"
  88.     fi
  89. else
  90.     echo "Not running a distribution with /etc/os-release available"
  91. fi
  92. cat status.txt
Advertisement
Add Comment
Please, Sign In to add comment