Skip to content

Create vagrant box for RescueMe

Kenneth Gulbrandsøy edited this page Aug 2, 2014 · 22 revisions

RescueMe requires a runtime environment, typically a Linux, Windows or OSX server with the LAMP stack installed. Developers need this runtime environment to test and debug RescueMe. They could manually install a LAMP stack on their development machines, but this is time-consuming and error-prone. A better solution is to provide a ready-made runtime environment, which developers can run on a host of their choice. This is only possible using visualization software like VirtualBox. which is free, and runs both Windows, Linux, Macintosh.

Creating and configuring lightweight, reproducible, and portable development environments is a complex task in it self. Luckily, there is a free and available tool for this also, called Vagrant. Vagrant use base boxes containing all the data necessary to import and build a virtualized development environment. This page describes how to build a box that is able to run RescueMe (almoust) without any need for manual configuration.

Vagrant supports more providers than just VirtualBox. This procedure however only describes the creation of a Vagrant box for use with VirtualBox.

###Preparation

Ensure that both VirtualBox and Vagrant is installed on your machine.

###Creation

This procedure is the combination of several tutorials out there for creating a Vagrant box. Follow it precisely as described. There are many pitfalls that will make the box useless or difficult to use.

Create VirtualBox Virtual Machine for Ubuntu 12.04 LTS

  • Download server install CD (*.iso file)
  • Create a new Virtual Machine with 512MB ram and 100GB Disk with dynamically allocated differencing storage
  • Give it the name vagrant-precise64-rescueme
  • Enable network adapter 1 and attach it to NAT (Vagrant uses this to connect the first time).
  • Attach server install CD

Install Ubuntu 12.04 LTS

  • Boot the machine an follow the instructions

Select following values

  • Default user: vagrant with password vagrant (convention)
  • Keyboard: English (US)
  • Locale: US
  • Timezone: London (GMT)

Select additional software

  • OpenSSH
  • LAMP Server, MySQL root password: vagrant

Post-install configuration

Set root password to vagrant (convention) with:

sudo passwd

Ensure admin group exists with:

groupadd -r admin

Add user vagrant to admin group with

usermod -a -G admin vagrant

Enable sudo without password for user vagrant (convension)

  • Open /etc/sudoers with: sudo visudo
  • Add following defaults if not exist: Default env_reset, Defaults exempt_group=admin
  • Change line admin ALL=(ALL) to admin ALL=(ALL) NOPASSWD:ALL
  • Save changes with CTRL+X and Enter

Prepare to install Guest Additions

sudo apt-get install linux-headers-generic build-essential dkms

Install Guest Additions (required to make shared folders work properly)

  • Goto "Devices" > "Install Guest Additions" in the virtual machine window.
  • Mount the CD-ROM with
sudo mount /dev/cdrom /media/cdrom
  • Install guest additions with
sudo sh /media/cdrom/VBoxLinuxAdditions.run
sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

Enable insecure key-based authentication for SSH (convention)

mkdir ~/.ssh
chmod 0700 ~/.ssh
cd ~/.ssh
wget --no-check-certificate "https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub"
cat vagrant.pub >> authorized_keys
chmod 0600 authorized_keys

Tweek sshd to prevent DNS resolution (speed up logins)

sudo echo "UseDNS no" >> /etc/ssh/sshd_config
  • Add -u0 to SSH_OPTS in /etc/default/ssh

Disable grub startup menu (speed up logins) by setting

GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0

in /etc/default/grub and apply changes with

sudo update-grub

Add NFS client with (faster)

sudo apt-get -y install nfs-common

Implement workarounds for known networking problems

  • Add following lines to script /etc/rc.local before exit 0
# Make sure eth0 is working. This works around Vagrant issue #391
dhclient eth0

Remove persistent rules

sudo rm /etc/udev/rules.d/70-persistent-net.rules
sudo mkdir /etc/udev/rules.d/70-persistent-net.rules
sudo rm /lib/udev/rules.d/75-persistent-net-generator.rules

Remove leftover leases (must be performed after every boot)

sudo rm -rf /dev/.udev/
sudo rm -rf /var/lib/dhcp/*

Compress current image size to save space in the final image (takes several minutes)

sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY

###Package into Vagrant box The next step is to package the virtual machine into a Vagrant box

vagrant package --base vagrant-precise64-rescueme

which will output package.box in working directory.

###Test Vagrant box

# Import box
vagrant box add vagrant-precise64-rescueme /path/to/package.box
# Create test project
mkdir -p ~/vagrant-precise64-rescueme-test
cd ~/vagrant-precise64-rescueme-test
vagrant init vagrant-precise64-rescueme
# Start server
vagrant up
# Login server
vagrant ssh
# Remove project
vagrant destroy
rm -rf .vagrant Vagrantfile
vagrant box remove vagrant-precise64-rescueme

which should be performed without errors of any kind.

Clone this wiki locally