Skip to content

Instantly share code, notes, and snippets.

@pavlakis
Last active February 15, 2017 09:17
Show Gist options
  • Save pavlakis/2c33f059491d82855bb9b369f5c6d134 to your computer and use it in GitHub Desktop.
Save pavlakis/2c33f059491d82855bb9b369f5c6d134 to your computer and use it in GitHub Desktop.
Creating a Centos7 vagrant box

(1) Start with a Vagrant box.

I've used: centos/7

(2) Install Guest Additions (dkms on its own fails when doing a vagrant reload)

sudo yum install wget
wget http://download.virtualbox.org/virtualbox/5.0.30/VBoxGuestAdditions_5.0.30.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_5.0.30.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
VBoxGuestAdditions_5.0.30.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions

(3) Disable Network Manager

systemctl disable NetworkManager

(4) Reduce VM size

sudo yum clean all

sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY

(5) Remove history

history -c
> ~/.bash_history

(6) Package the box

From the same directory (where the Vagrantfile is on):

vagrant package --output my-centos7-box.box

(7) Add box to vagrant

vagrant box add my-centos7-box.box --name My-Centos7

Troubleshooting

I've had some issues with vagrant mounts in /var/www could not be read in apache due to SELinux policies.

The fix: sudo setenforce 0

Note

For production you will need to setup SELinux policies. See here for more info:

http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment