You are here

Creating a Vagrant Debian base box with more disk space

tuxRecently, I decided to overhaul the email server I had been running for several years now. I had two main requirements in mind:

  • isolate the installation in such a way that I can easily move it from one machine to another one, when I need it (for instance, when my hosting service provider delivers a new, less expensive service)
  • use ISPConfig

For isolation, using Docker would have been a nice solution for me, as I already have moved most of the services I run on my server to Docker containers. But the "standard" paradigm for docker is one process per container. I do not like to use tools for something else than what there have been designed for (do you know the quotation: "if all you have is a hammer, everything looks like a nail" ? Smile). Of course, I could try to use Supervisor, or re-use one of the existing dockerizations of ISPConfig. But the first solution would require me to spend time in understanding how ISPConfig works. And, for the second solution, I'm not sure about the quality of existing containers.

What else could I use for isolation? A virtual machine, of course. As I already have a basic knowledge of VirtualBox, the best for me is to go with it here. But now another question: how to manage my (future) virtual machine from command prompt, with something simpler than vboxmanage? After a rapid search on the Internet, I discovered Vagrant. I already had heard this name. So this seemed to me an interesting solution. I spent a few days checking what Vagrant was exactly, and what I could do with it. And my conclusion was: go!

Nevertheless, there was a slight problem: I wanted to use Debian Jessie, to stay consistent with my server, and the Vagrant Jessie base box only provides 10 GB of disk space. Which is not enough for my email server: I'd like to get 50 GB for email storage, at least... So I had to create my own base box. This article presents what I did for this.

Reference material

I used those websites as reference:

Local configuration

Creation of VirtualBox VM

On my local development machine, I went through these steps:

  • download the Debian Jessie Small CD image (netinst)
  • create a new Debian virtual machine, using VirtualBox GUI, with following characteristics:
    • memory size: 1024 MB
    • using expert mode:
      • file name: DebianJessie
      • file size: 60 GB
      • virtual disk type: VDMK
      • dynamically allocated
    • set PAE/NX on
    • disable audio
    • disable USB
  • add the downloaded Debian image to the list of drives. Boot on it, after having added it as an IDE drive. Perform the installation, providing some specific answers:
    • root password: vagrant
    • full name for the new user: Vagrant
    • username for your account: vagrant
    • password for the new user: vagrant
    • software to install:
      • SSH server
      • standard system utilities
  • log in, and install guest additions:
    • apt-get install linux-headers-amd64 build-essential dkms
    • Devices / Insert Guest Additions CD Image...
    • mount /dev/cdrom /media/cdrom
    • sh /media/cdrom/
  • for easier information transfer between the guest and the host (namely: cut and paste + command history), ssh to the guest:
    • with VirtualBox GUI, add a port forwarding rule: host port 2222 to guest port 22
    • ssh to the guest with port 2222 and username vagrant (root is not authorized)
    • su
  • copy Vagrant public key into /home/vagrant/.ssh/authorized_keys
  • chmod 0700 /home/vagrant/.ssh
  • chmod 0600 /home/vagrant/.ssh/authorized_keys
  • apt-get install sudo
  • using visudo, add following line to sudoers file: vagrant ALL=(ALL) NOPASSWD: ALL
  • add UseDNS no to /etc/ssh/sshd_config. And uncomment the line AuthorizedKeysFile %h/.ssh/authorized_keys. Restart sshd: service sshd restart
  • cleanup:
    • dd if=/dev/zero of=/EMPTY bs=1M
    • rm -f /EMPTY
    • rm -rf /usr/share/doc
    • rm -rf /usr/src/linux-headers-3.16.0-4-*
    • find /var/cache -type f -exec rm -rf {} \;
  • power off the VM

Vagrant box packaging

  • install Vagrant
  • mkdir vagrantboxes
  • cd vagrantboxes
  • vagrant package --base "Debian Jessie"
  • test the box:
    • vagrant box add jessie
    • vagrant init jessie
    • vagrant up
    • vagrant ssh

Then, transfer the box to the target machine. The file to transfer is the one displayed by the vagrant package command issued above.