Skip to content

Instantly share code, notes, and snippets.

@lucassrg
Last active June 1, 2018 18:13
Show Gist options
  • Save lucassrg/c9d028a8ec351a69d5bcfe4833103bea to your computer and use it in GitHub Desktop.
Save lucassrg/c9d028a8ec351a69d5bcfe4833103bea to your computer and use it in GitHub Desktop.
Oracle Linux 7.x - Install KVM server with GUI support via VNC
#!/bin/bash
##Install KVM, Dependencies & utils
yum -y install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer oci-utils
yum groupinstall "Server with GUI" -y
##Install VNC Server
yum install xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils tigervnc-server mesa-libGL mesa-libEGL -y
cd /lib/systemd/system
cp vncserver@.service vncserver@:1.service
sed -i 's/<USER>/opc/g' vncserver@:1.service
firewall-cmd --permanent --zone=public --add-service vnc-server
mkdir /home/opc/.vnc
echo myvncpassword | vncpasswd -f >> /home/opc/.vnc/passwd
chown -R opc:opc /home/opc/.vnc
chmod 0600 /home/opc/.vnc/passwd
systemctl daemon-reload
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
##Modify grub
GRUBFILE=/etc/default/grub
TMPFILE=`mktemp`
sed -e 's/^\(GRUB_CMDLINE_LINUX=".*\)"/\1 intel_iommu=on kvm-intel.nested=1"/' $GRUBFILE > $TMPFILE
size=`du -b $GRUBFILE | awk '{print $1}'`
nsize=`du -b $TMPFILE | awk '{print $1}'`
if [[ $nsize -lt $size ]]
then
echo "Error"
exit 1
fi
chown --reference=$GRUBFILE $TMPFILE
chmod --reference=$GRUBFILE $TMPFILE
mv $TMPFILE $GRUBFILE
grub2-mkconfig -o /boot/grub2/grub.cfg
systemctl enable tuned
systemctl start tuned
sleep 10
tuned-adm profile virtual-host
##NAT / IP Forward
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/98-ip-forward.conf
#Attach scsi disks & vnics using oci-utils package/service
systemctl start ocid.service
sleep 10
oci-iscsi-config -s
##Steps below required in case you attached a block volume to the instance
##Create FS and Mount disk
mkfs.xfs /dev/sdb
mkdir /mnt/kvm-guest-disk
mount -t xfs /dev/sdb /mnt/kvm-guest-disk/
sdb_uuid=`blkid /dev/sdb -s UUID -o value`
echo "UUID=$sdb_uuid /mnt/kvm-guest-disk xfs defaults,noatime,_netdev,nofail" >> /etc/fstab
#after reboot
#oci-network-config -s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment