Skip to content

Create vagrant box for RescueMe

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

This procedure describes the creation of a Vagrant box for use with VirtualBox. Follow it precisely as described. There are many pitfalls that will make the box useless or difficult to use.

###Preparation

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

###Create Virtual Machine

We are currently using Ubuntu 12.04 LTS in production. Developers should do the same for stability reasons.

  • 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 when prompted:

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

Select following additional software when promped:

  • 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/*

Add RescueMe dependencies

sudo apt-get -y install php5-cli php5-curl php5-intl php-gettext

Enable Apache modules

sudo a2enmod rewrite

Configure Apache2

sudo nano /etc/apache2/conf.d/fqdn
  • insert
ServerName localhost

Configure RescueMe site

sudo nano /etc/apache2/sites-available/rescueme
  • insert
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/rescueme
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /var/www/rescueme>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride Options
    Order allow,deny
    allow from all
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/rescueme-error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/rescueme-access.log combined
</VirtualHost>

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 virtual machine into a 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 the 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