Create a new Virtual Machine in VirtualBox with the following settings:
- Name: my-vagrant-box
- Type: Linux
- Version: Ubuntu64
- Memory Size: 512MB (to taste)
- New Virtual Disk: [Type: VMDK, Size: 40 GB]
- Disable audio
- Disable USB
- Ensure Network Adapter 1 is set to NAT
- Add this port-forwarding rule:
- Name: SSH
- Protocol: TCP
- Host IP: blank
- Host Port: 2222
- Guest IP: blank
- Guest Port: 22
Mount the Linux Distro ISO, boot up and install.
Create a main user called vagrant with password vagrant.
Set root password to vagrant (sudo passwd root
).
Add vagrant user to sudoers list:
sudo visudo -f /etc/sudoers.d/vagrant
Add this line, save and exit:
vagrant ALL=(ALL) NOPASSWD:ALL
Test if you still need a password for sudo:
sudo pwd
Check for updates and bring everything up to date.
sudo apt-get update
sudo apt-get upgrade
mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate \
https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
-O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
If not already installed, install openssh server now:
sudo apt-get install openssh-server
Find and uncomment the following line:
AuthorizedKeysFile %h/.ssh/authorized_keys
Restart openssh server:
sudo service ssh restart
Install requirements for guest additions:
sudo apt-get install gcc build-essential linux-headers-server
Insert the guest additions image via Devices menu in VirtualBox, then mount and run:
sudo mount /dev/cdrom /mnt
cd /mnt
sudo ./VBoxLinuxAdditions.run
Remove unnecessary and downloaded packages.
sudo apt-get autoremove
sudo apt-get clean
Fix fragmentation issues with the underlying disk to alloe more efficient compression later:
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY
Clear history and shutdown:
cat /dev/null > ~/.bash_history && history -c && sudo shutdown -h now
Use vagrant package
to package and compress your VirtualBox machine called my-vagrant-box:
mkdir ~/my-vagrant-box_package
cd ~/my-vagrant-box_package
vagrant package --base my-vagrant-box
vagrant box add test package.box
vagrant init test
vagrant up