Creating Drupal environments using vmbuilder on Ubuntu 8.10
With some scripting on Ubuntu 8.10 (Intrepid Ibex) we can simple generate fully customised Drupal LAMP development servers, as virtual appliances to VMware, or to other virtualization environments like XEN or KVM. It's an effective and quick way to have various development or test servers in one hardware box running Ubuntu 8.10 and VMware Server 2.0.
You need a machine with Ubuntu 8.10 (Intrepid Ibex) and VMware Server 2.0, as host system to the appliances. VMware Server 2.0 install on Ubuntu 8.10. can be learned here or here. We will need free IP addresses for the virtual machines, so you will need a properly configured DHCP server or a router, as well.
vmbuilder
The magic happens with vmbuilder, a tool introduced in Ubuntu 8.10, and targeted to build virtual machines with Ubuntu as operating system for multiple virtualization environments. Currently it supports Xen, KVM, VMware Workstation 6, and VMware Server. In the following, we are going to create virtual appliances to VMware Server.
To install vmbuilder, type:
sudo apt-get install python-vm-builder
To learn the parameters for Ubuntu and VMware Server, type:
sudo vmbuilder vmserver ubuntu --help
Preparations
vmbuilder uses a configuration file to create virtual machines (/etc/vmbuilder/libvirt/) We create a copy and modify that one:
sudo mkdir /var/vm
cd /var/vm
sudo mkdir -p /var/vm/mytemplates/libvirt
sudo cp /etc/vmbuilder/libvirt/* /var/vm/mytemplates/libvirt/
sudo nano /var/vm/mytemplates/libvirt/libvirtxml.tmplChange the network section from
[...]
<interface type='network'>
<source network='default'/>
</interface>
[...]to
[...]
<interface type='bridge'>
<source bridge='br0'/>
</interface>
[...]because we want the VMs to use bridging in order to get to the network / Internet as a standalone server.
Defining the Drupal LAMP virtual machine
Defining a virtual machine with Ubuntu's vmbuilder is quite simple, there is set of command line parameters, but here we use a configuration file. So at the end, we'll create a Drupal LAMP server with Ubuntu for VMware with this simple command:
vmbuilder vmserver ubuntu -c lamp-vm.cfg
The content of lamp-vm.fg file is:
##
## config file for vmbuilder to build a LAMP server
##
## use: sudo vmbuilder vmserver ubuntu -c lamp-vm.cfg
##
## background: http://www.wepoca.net/doc/drupal-lamp-virtual-server
##
## created by doka@wepoca.net
## 2009-02-15
## www.wepoca.net
##
[DEFAULT]
arch = i386
overwrite = true
tmpfs = -
firstboot = lamp-vm-boot.sh
firstlogin = lamp-vm-firstlogin.sh
templates = mytemplate
part = lamp-vm.partition
mem = 1024
hostname = lamptest
domain = local
ip = dhcp
user = doka
name = Doka
pass = wepoca
[ubuntu]
flavour = virtual
suite = intrepid
iso = /home/<YOURHOME>ubuntu-8.10-desktop-i386.iso
mirror = http://192.168.2.4:9999/ubuntu
components = main,universe,restricted,multiverse
addpkg = acpid, apache2, php5, php5-mysql, php5-gd, phpmyadmin, wget, nano, mysql-server
[vmserver] Let's go through the parameters of lamp-vm.cfg:
- arch
- overwrite
- tmpfs
- firstboot
- firstlogin
- templates
- part
- mem
- hostname
- domain
- ip
- user
- name
- pass
- flavour
- suite
- iso
- mirror
- components
- addpkg
Specify the target architecture. arch = i386 means a 32 bit machine. If your virtual machine needs to use more than 3 GiB of ram, you should build a 64 bit machine (arch = amd64). Defaults to host arch.
Force overwrite of destination directory if it already exist, default: False
Because writing to RAM is a LOT faster than writing to disk, if you have some free memory, let vmbuilder perform its operation in a RAMdisk. So tmpfs option will help you do just that: vmbuilder will be working in the RAM during install. Either specify its size or just "-" to use tmpfs default (suid,dev,size=1G).
The first time the machine boots we'll need to install openssh-server so that the key generated for it is unique for each machine. We can also use this place to do other tasks, so we'll write a script called lamp-vm-boot.sh. See details at the lamp-vm-boot.sh section below. It is ran as root.
The first login script ,called lamp-vm-firstlogin.sh. Place for install tasks needing some user interaction during their setup, like setting MySQL root password, or keyboard preferences. See details at the lamp-vm-firstlogin.sh section below.
Place of the modified libvirt templates, so mytemplates in our case.
Allows to specify a partition table in a separate text file, each line should specify the mountpoint and size, one per line, separated by space, where size is in megabytes. You can have up to 4 virtual disks, a new disk starts on a line containing only '---'. My lamp-vm.partition file looks like this, and results in two disks, the second one contains the /var
root 2000
swap 1000
---
/var 1000Assign MEM megabytes of memory to the guest VM, default is 128MB. Given that RAM is much easier to allocate in a VM, memory size should be set to whatever you think is a safe minimum for your appliance.
Set as the hostname of the guest. Default:ubuntu. Also uses this name as the VM name.
Set as the domain name of the guest. Default is the dot (.)
IP address in dotted form [default: dhcp]. You'll need to set the usual networking parameters like gateway and mask, if you deviates from default. See the networking section in help (sudo vmbuilder vmserver ubuntu --help)
Username of initial user [default: ubuntu], with sudo rights on guest VM.
Full name of initial user [default: Ubuntu]
Password of initial user [default: ubuntu]
Kernel flavour to use. Default and valid options depend on architecture and suite.
Ubuntu suite to install. Valid options: dapper feisty gutsy hardy intrepid [default: intrepid]
Use an iso image as the source for installation. Copy an iso image to your home, and change this line accordingly. Full path to the iso must be provided. It requires suite and kernel parameter to match what is available on the iso, obviously.
Use an Ubuntu mirror at URL instead of the default, which is http://archive.ubuntu.com/ubuntu. See details below.
A comma separated list of distro components to include (e.g. main,universe)
Install PKG into the guest (can be specified multiple times). Used to list the components of the LAMP server.
vm-boot.sh_.txt: the booting script
In this script we set the locale to hu_HU, update&upgrade in order to finish the installation, install the OpenSSH server, and clean up after install. Before use, you might want to set the locale to your preferences.
vm-firstlogin.sh_.txt: the first login script
In this login script we set the MySQL root password, download and prepare the Drupal source in the home of the first user, define a catch-all vhost config file for Drupal 6 in Apache, configure phpMyAdmin, increase the PHP memory limit to 64 MB, and prepare the MySQL to use Drupal.
Accelerate the install process
- Using tmpfs
- Using Ubuntu local mirror
tbd.
tbd.
And putting all together
tbd.
| Attachment | Size |
|---|---|
| vm-boot.sh_.txt | 1.4 KB |
| vm-firstlogin.sh_.txt | 3.57 KB |

