After having gone through the basics of a Vagrant install, with more to do yet, I need to record some of the commands I used to get things going.
This solution is based upon using Debian Stretch/Testing as the 'box'. Which I build in a minimal configuration. I create a 'vagrant' user during the build process. Also ensure that the first network card is of type 'Paravirtualized Network (virtio-net)' when being built under VirtualBox.
Once built, and rebooted, login as 'vagrant':
mkdir /home/vagrant/.ssh chmod 700 /home/vagrant/.ssh pushd /home/vagrant/.ssh wget --no-check-certificate \ 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' \ -O authorized_keys chmod 600 /home/vagrant/.ssh/authorized_keys chown -R vagrant /home/vagrant/.ssh popd
In order to clear the way for vagrant automation, create the following file, as root (sudo doesn't appear to work):
cat <<EOT >> /etc/sudoers.d/10-sudo-overrides Defaults env_keep += "GIT_*" Defaults>root env_keep += SSH_AUTH_SOCK Defaults>root !requiretty %sudo ALL=NOPASSWD: ALL EOT
VirtualBox extensions are required. They can be installed in one of two ways. The first is by using the gui to mount the cd and then run:
apt-get install linux-headers-$(uname -r) build-essential # attach guest extensions mount /dev/cdrom /media/cdrom KERN_DIR=/usr/src/linux-headers-$(uname -r)/ \ sh /media/cdrom/VBoxLinuxAdditions.runsh /media/cdrom/VBoxLinuxAdditions.run umount /media/cdrom apt-get remove binutils build-essential bzip2 cpp cpp-5 cpp-6 dpkg-dev fakeroot \ g++ g++-6 gcc gcc-5 gcc-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl \ libalgorithm-merge-perl libasan2 libasan3 libatomic1 libc-dev-bin libc6-dev \ libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-5-dev \ libgcc-6-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpfr4 libmpx0 libmpx2 \ libperl5.24 libquadmath0 libstdc++-6-dev libtsan0 libubsan0 \ linux-compiler-gcc-5-x86 linux-headers-4.7.0-1-amd64 \ linux-headers-4.7.0-1-common linux-kbuild-4.7 \ linux-libc-dev make manpages manpages-dev patch perl
The other way, courtesy of Creating a Base Box (and substituting the correct iso version):
wget http://download.virtualbox.org/virtualbox/4.3.8/VBoxGuestAdditions_4.3.8.iso sudo mkdir /media/VBoxGuestAdditions sudo mount -o loop,ro VBoxGuestAdditions_4.3.8.iso /media/VBoxGuestAdditions sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run rm VBoxGuestAdditions_4.3.8.iso sudo umount /media/VBoxGuestAdditions sudo rmdir /media/VBoxGuestAdditions
Minimize the resulting box by removing packages and zeroing out unused space:
apt-get autoremove apt-get purge apt-get clean dd if=/dev/zero of=/EMPTY bs=1M rm -f /EMPTY
Shutdown the template. Remove the boot cd if one is attached. Ensure the first network port is of type NAT.
Inside a vagrant project directory, I create a template file, it has a default config, but if I need to diddle adjustments later, it is available:
# stretch.vf: Vagrant::Config.run do |config| config.ssh.username = "vagrant" end
I create a package, a place it in place I can reach it. It is local, but could be put in a remote repository if desired.
vagrant package --base stretch --vagrantfile stretch.vf mkdir boxes mv package.box boxes/stretch.box
These commands are the key to a re-usable environment:
vagrant init stretch file://boxes/stretch.box vagrant up vagrant ssh
Some other useful commands:
vagrant reload (after changing Vagrantfile), page 29 vagrant halt vagrant suspend vagrant destroy vagrant box list vagrant box remove
And as a bonus check, once ssh'd into a guest, and a suitable port forward is in place, then check communication (without having to install a web server):
sudo python -m SimpleHTTPServer 80
Some Vagrant documentation: