Create Debian 8 Jessie Vagrant Box

This is the third and last post of this series.

  1. Create Debian 8 Jessie VirtualBox
  2. Install Debian 8 Jessie Virtual Machine
  3. Create Debian 8 Jessie Vagrant Box
We have now created a VirtualBox and a fresh install of Debian Jessie on it. Now we will prepare the box to roll it out to other developers. This post is a mix of Create a Debian Wheezy Vagrant box from Alexander Fahlke and Building a Vagrant Box from Start to Finish from Tyler Bird.
I hope you have installed the latest version of Vagrant.

Install and prepare

Please login as root user into the VirtualBox.

Update and upgrade

Next we will update aptitude package information and upgrade our packages with the two following comamnds

apt-get update
apt-get upgrade

Install

We will install build-essential, module-assistant, zerofree and openssh-server with the following three commands.

apt-get install -y build-essential module-assistant
module-assistant prepare
apt-get install -y sudo zerofree openssh-server

Permissions of vagrant user

We need to give the vagrant user some permissions. Please run visudo.

visudo

And add the following line, maybe after the root user and close the editor after saving the file.

vagrant ALL=(ALL) NOPASSWD: ALL

Please restart the machine with the two following commands.

shutdown -r now

Configure ssh

We want to configure ssh for the vagrant user. Please login as vagrant user and type the following commands.

mkdir -p /home/vagrant/.ssh

We now have to create the public key for the vagrant user. Please create the file /home/vagrant/.ssh/authorized_keys with the following content on your machine.

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
This is an insecure public key for the vagrant user. After that we edit the file /etc/ssh/sshd_config with any editor, for example nano.
sudo nano /etc/ssh/sshd_config
And uncomment the line.
AuthorizedKeysFile %h/.ssh/authorized_keys
Now we can restart ssh.
sudo service ssh restart

VBoxLinuxAdditions

Please click in the menu of the machine on Device and in the submenu on Insert Guest Additions CD image ....

Insert Guest Additions CD image

After that we will mount and run the guest additions with the following three commands.

sudo mount /dev/cdrom /mnt
cd /mnt
sudo ./VBoxLinuxAdditions.run

Cleanup

Let's remove some unused stuff.

sudo rm -rf /usr/share/doc
sudo rm -rf /usr/src/linux-headers*
sudo rm -rf /usr/src/linux
sudo find /var/cache -type f -exec rm -rf {} \;
sudo find /usr/share/locale/* -maxdepth 1 -type d ! -name "de*" ! -name "en*" -exec rm -rf {} \;
sudo rm -rf /usr/src/vboxguest*
sudo rm -rf /usr/src/virtualbox-guest*

Zerofree

Zerofree finds the unallocated blocks with non-zero value content in an ext2, ext3 or ext4 file-system and fills them with zeroes.

Run the following comamnd to get root.

sudo init 1

Let's run zerofree.

mount -o remount,ro /dev/sda1
zerofree /dev/sda1

Finish

We will now finish the box by shuting down.

shutdown -h now

And after that we can create the box with the following command from our host system.

vagrant package --base debian\ jessie
Next Previous