Skip to content

Instantly share code, notes, and snippets.

@TomasKulhanek
Last active September 15, 2022 11:07
Show Gist options
  • Save TomasKulhanek/21e4544823dfcd181b3d0787a5b525a1 to your computer and use it in GitHub Desktop.
Save TomasKulhanek/21e4544823dfcd181b3d0787a5b525a1 to your computer and use it in GitHub Desktop.
Script to prepare SL7 vagrant box, full instruction including manual steps are documented at https://h2020-westlife-eu.gitbook.io/virtual-folder-docs/virtual-machines/preparing-vagrant-vm-template

Preparing vagrant VM template

The following section describes how to prepare VM template from scratch, e.g. to be used as base vagrant box or as a base VM template. It's not needed to perform these steps when installing any products, however, might be usefull to maintain version of base OS.

Scientific Linux 7

Download ISO

As a base for most VM templates, Scientific Linux is used. Download the latest version from http://ftp1.scientificlinux.org/linux/scientific/7x/x86_64/iso/

recommended is Network installation ISO - SL-*-netinst.iso

Install minimal system

In installation packages - select Minimal system.

Define root and vagrant user

Set root password (vagrant) and create new user (vagrant:vagrant)

Post-installation script

In Virtualbox - Insert VBoxGuest Additions Devices -> Insert Guest Additions CD image ....

Log-in as root, and execute one of the following script:

  1. for non-GUI environment: bash <(curl -L https://bit.ly/2xDpLwR)
  2. for GUI environment: bash <(curl -L http://bit.ly/2GfrE7z)

Reset, check if everything works, if new kernel was installed - then manually uninstall old kernel

uname -a
# outputs which kernel is loaded
rpm -q kernel
# outputs which kernel is installed
yum remove kernel-...
# uninstalls unused kernel
bash <(curl -L ....)
#repeat post-install script 1. for non-GUI or 2. GUI

Create box

Stop virtualbox, remove unused IDE, sound card, change video memory etc.

Launch vagrant script to package box. Expecting the virtual machine name is my-sl7-virtualmachine

vagrant package --output sl7mini.box --base my-sl7-virtualmachine

Explanation:

  • package instruct vagrant to get virtual machine from virtual box and package it into separate file
  • --output sl7mini.box writes the result to file named as sl7mini.box
  • --base my-sl7-install takes VirtualBox virtual machine named my-sl7-virtualmachine
#enable sudo
echo 'vagrant ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo
# update system
yum update -y
# expected that SL7 is installed as minimal system, vagrant account as administrator, run with sudo privileges
yum -y install epel-release
yum -y groupinstall "X Window System" "Xfce"
yum -y install xfce4-netload-plugin xfce4-systemload-plugin
yum -y remove openbox orage pavucontrol postfix tigervnc*
# start gdm
systemctl set-default graphical.target
# automatic login vagrant
sed -i '/^\[daemon\]/,/^\[security\]/{//!d}' /etc/gdm/custom.conf
sed -i '/\[daemon\]/ aAutomaticLoginEnable=True\n AutomaticLogin=vagrant' /etc/gdm/custom.conf
# systemctl set-default graphical.target
# enable ssh
systemctl enable sshd
yum install -y wget
mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate \
https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
-O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
#install vboxguest
yum install -y bzip2 gcc kernel-devel
mount /dev/cdrom /mnt
cd /mnt
./VBoxLinuxAdditions.run
# clean
yum remove -y gcc kernel-devel
yum autoremove -y
yum remove -y perl-*
cd /home/vagrant
wget https://gist.github.com/TomasKulhanek/21e4544823dfcd181b3d0787a5b525a1/raw/1973aad8ebb9754ee1c598c0cb568b55fd625c5a/sshd_config -O /etc/ssh/sshd_config
bash <(curl -L https://gist.githubusercontent.com/TomasKulhanek/fb3554f1265fb9b9fc71310a2678a0bc/raw/vagrant-clean.sh)
#enable sudo
echo 'vagrant ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo
# update system
yum update -y
# enable ssh
systemctl enable sshd
yum install -y wget
mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate \
https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
-O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
#install vboxguest
yum install -y bzip2 gcc kernel-devel
mount /dev/cdrom /mnt
cd /mnt
./VBoxLinuxAdditions.run
# clean
yum remove -y gcc kernel-devel perl-* newt-python *-firmware freetype
yum autoremove -y
cd /home/vagrant
wget https://gist.github.com/TomasKulhanek/21e4544823dfcd181b3d0787a5b525a1/raw/1973aad8ebb9754ee1c598c0cb568b55fd625c5a/sshd_config -O /etc/ssh/sshd_config
bash <(curl -L https://gist.githubusercontent.com/TomasKulhanek/fb3554f1265fb9b9fc71310a2678a0bc/raw/vagrant-clean.sh)
Port 22
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication no
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
UsePrivilegeSeparation sandbox # Default for new installations.
UseDNS no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment