Actions: | Security

AllGoodBits.org

Navigation: Home | Services | Tools | Articles | Other

Using Vagrant to create a relocatable yum repository mirror

Create an installation mirror

Creating an installation server as a Virtual Machine, which you can then pick up, run it wherever you can and you will have mirror(s) to install from. This was my first foray with Vagrant and very handy it was too.

Use vagrant to install a clean VM

cd ~/vagrants
vagrant box add CentOS-6.5-i386 http://puppet-vagrant-boxes.puppetlabs.com/centos-65-i386-virtualbox-puppet.box
vagrant init CentOS-6.5-i386

Feel free to choose a different vagrant provider such as VMWare if you want; just get/make a box that supports it. It might even work out that these instructions work perfectly, but this was built with VirtualBox.

Ensure TCP port 80 (http) is forwarded from host to guest

Vagrantfile:

config.vm.network "forwarded_port", guest: 80, host: 8080

Bring up the new VM

vagrant up
vagrant ssh

Install EPEL, update the VM

sudo bash
yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum -y upgrade
reboot

The reboot is necessary if there was a kernel upgrade and advisable anyway.

[Optional] Update Guest Additions

If your host machine has a different version of VirtualBox from the version that the vagrant box is for, you'll want to make them match.

yum -y install dkms
/etc/init.d/vboxadd setup
reboot

Technically, you can probably get away with running modprobe for each of the vbox kernel modules, but this is a brand new, clean VM - go on, reboot it.

Create a yum repository mirror for your VMs to install from

Make sure you have plenty of storage available!

vagrant ssh
sudo yum -y install createrepo
reposync --newest-only --download_path=/vagrant --plugins
createrepo -d

Next steps in automated installation

Foreman or Cobbler