Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IMelker/0f1d6c2541a3584378d8a329eb23c3c4 to your computer and use it in GitHub Desktop.
Save IMelker/0f1d6c2541a3584378d8a329eb23c3c4 to your computer and use it in GitHub Desktop.
Centos7 VirtualBox Guest Additions installation
#!/bin/bash
# ------------------------------------------------------------
# Centos7 VirtualBox Guest Additions installation
# Update kernel headers and install requirements for it
#
# USAGE sudo prepare.sh
#
# sudo requires for installation, export KERNEL_DIR and reboot
# ------------------------------------------------------------
## Requie run as sudo ##
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
## CentOS/RHEL 7/6/5 ##
yum update -y kernel*
## Install following packages ##
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y gcc kernel-devel kernel-headers dkms make bzip2 perl
## Add KERN_DIR environment variable ##
export KERN_DIR=/usr/src/kernels/$(uname -r)
## Mount VirtualBoxGuestAdditions ##
mkdir /media/VirtualBoxGuestAdditions
mount -r /dev/cdrom /media/VirtualBoxGuestAdditions
## Run installation ##
cd /media/VirtualBoxGuestAdditions
./VBoxLinuxAdditions.run
## Reboot after install ##
while true; do
read -p "Do you wish to reboot now(it's necessary)?" yn
case $yn in
[Yy]* ) reboot; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment