Creating a base box

Updated at 2015-04-01 09:38

This is a checklist for creating a custom Vagrant base box using VirtualBox.

  1. Download Ubuntu 14.04 64bit server image.
  2. Create virtual machine.
  3. Start with 512MB of memory and go higher if needed.
  4. Create dynamically resizing drive with a large maximum size.
  5. Use the downloaded server image.
  6. Use root password vagrant. Create user "vagrant" with password "vagrant".
  7. Place Vagrant public SSH key to ~/.ssh/authorized_keys
    # Make sure that `~/.ssh` is `0700`.
    # Make sure that `authorized_keys` is `0600`.
    mkdir -p /home/vagrant/.ssh
    chmod 0700 /home/vagrant/.ssh
    wget --no-check-certificate \ \
        -O /home/vagrant/.ssh/authorized_keys
    chmod 0600 /home/vagrant/.ssh/authorized_keys
    chown -R vagrant /home/vagrant/.ssh
  8. Initial virtual machine must have:
  9. The first network interface (adapter 1) must be a NAT adapter.
  10. The MAC address of the first network interface, set by config.vm.base_mac.
  11. Use SSH key from Vagrant git repo.
  12. Add vagrant user to the list of sudoers.
    vagrant ALL=(ALL) NOPASSWD: ALL
  13. To keep SSH speedy, set UseDNS to no is SSH server configuration.
  14. Install Guest Additions for folder sharing between host and slave.
    sudo apt-get install linux-headers-generic build-essential dkms
    sudo apt-get install -y gcc build-essential linux-headers-server
  15. Disable audio, disable USB.
  16. Enable SSH authorized keys configuration.
    sudo nano /etc/ssh/sshd_config
    AuthorizedKeysFile %h/.ssh/authorized_keys # uncomment
    sudo service ssh restart
  17. Package the virtual machine.
    vagrant box add my-box /path/to/the/
    vagrant init my-box
    vagrant up
    vagrant package --base my-virtual-machine-in-virtual-box