I have been using Vagrant for quite some time now, its certainly one of the quickest and best ways, with some other tooling, to get access to devs of production similar environments. For ages I have been tied to Ubuntu and by ages, since well before Vagrant existed. Canonical have provided these base boxes so I have never had the need to do anything other than download it and build the requirements on top. New job, new silliness around support and security, ie Ubuntu isn't right so we have to go Redhat, for us that don't want to pay, as close as possible. In my case that is Centos. A little hunt around hasn't shown any official Vagrant images so I decided to build my own. As I'm likely to have to do this again in the future and to save me (and possibly others as this is on the internet) a bit of time looking round for all the docs I have thrown together the steps right here on my blog.
- Download the iso of the distro that you want, attach it to virtualbox.
- Call the machine something that identifies it.
- The defaults of memory (512MB) and disk size (8G) should be enough for this machine
- Disable peripherals such as USB and audio
- Start the install in the normal way.
- If you are asked to set a root password, make it vagrant. If you need to add a user, make it vagrant with vagrant as the password
- Setup passwordless sudo by visudo and add the line "vagrant ALL=(ALL) NOPASSWD: ALL"
- Remove the need for sudo tty if its set in the sudo setting but hashing out "#Defaults requiretty", this is normally found on a redhat based distro
- you need to install the guest additions, different distros have different ways so check the virtualbox manual <a href="https://www.virtualbox.org/manual/ch04.html#idp90863680">here</a>
- If not installed, openssh-server needs to be installed. To make it work faster, check the configuration has disabled UseDNS
- Set sshd to start on power on.
- Set the network card to autostart.
- Add the standard unsecured vagrant key to the vagrant user - "mkdir /home/vagrant/.ssh" - "curl -k https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub > /home/vagrant/.ssh/authorized_keys" - "chown vagrant:vagrant /home/vagrant/.ssh" - "chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys" - "chmod 0700 /home/vagrant/.ssh" - "chmod 0600 /home/vagrant/.ssh/authorized_keys"
- Shutdown the VM
- Now create the box "vagrant package --output centos7.box --base vagrant-centos7" where the --base is the name of the machine you have just been working on in virtual box.rn
The box is now created so to test, import into your local vagrant
"vagrant box add centos7 centos7.box"
Set a machine to use that image and start it up. You should now have a full functional vagrant/virtualbox image, with all your needs that you can spin up at any time.
More information about Vagrant boxes can be found here in the official documentation