Category Archives: HowTo

How To: Export a VMWare VM to XenServer

This How To covers exporting a VMWare Virtual Machine to an existing XenServer installation.

A quick one today. I created a VM in VMWare Workstation and after testing some things decided I wanted to add it to my Xen cluster.

Luckily you can export machines into the OVF standard, which can then be imported natively by XenServer.

Select your Virtual Machine in Workstation and power it down. Suspend may also work but I didn’t test this. While still selected, select from the File menu -> Export to OVF and select a location to export the machine to.


From the File menu in XenCenter click `Import` and select `Import OVF/OVA Package` and follow the steps.


How To: Create an LVM

Home Infrastructure Part 3 – Creating an LVM

An LVM is a `Logical Volume Manager`. You can think of it as a system for managing how the space on your disks is used.

It’s sometimes beneficial to use LVM for your storage because you can’t always plan ahead for how large partitions should be sized. LVM means you can have a “virtual” storage pool, and add space when required to increase its capacity by adding new physical drives. You can move your virtual disks around and resize as you need to.

Some basic partitioning

First you want to find the physical device that you want to install LVM on to. A useful command for this is `lsblk`, this lists your block devices (usually things like USB sticks, hard drives but technically a block device is anything that provides buffered access to hardware devices. From the output you can see that there’s a disk at “sda” and a partition at “sda1” already.

Fdisk is a program that will let you partition your drives. The reason I choose fdisk is that it’s present on mostly all systems, although be aware that some distributions (FreeNAS in particular) don’t include versions that allow you to create GPT formatted partition table , in which case run parted.

Run the fdisk command on the disk (in this case /dev/sda).

What we want to do in this case is create a GPT partition table. This is because the other commonly used type (DOS) has certain restrictions (a 2TB size limit on disks for one, but also a restriction in using the primary/secondary/extended paradigm if you want a large number of partitions).

Configure your disk partitions

Assuming it’s a fresh disk, OR you are happy that you will wipe the disk and it will be irretrievable, follow the steps below. A safe way to try this out would be in a Virtual Machine.

Pick the options :

  • ‘l’ to list your partitions (there should be none if you’ve just created a partition type)
  • ‘n’ to create a new partition. Pick the partition number (default is 1)
  • ‘t’ to set the partition type to Linux LVM (30)
  • ‘w’ to write out the partition table to the disk. You should now have a drive with one unformatted partition at its maximum capacity.

Note: we don’t want to create any more partitions at this point, as we’re just using it as a substrate for the LVM storage. More ‘partitions’ would be added through LVM itself as that’s the technology that manages the partitions.

Configuring LVM

So first we create the physical volume on the Linux LVM partition at /dev/sda1.
Then we want to create the Volume Group. You can think of this as a collection of Logical Volumes which themselves are a bit of virtual storage, like a partition, but that can be moved around and resized at will (well, with some caveats – namely the file system inside)


[root@archbang ablive]# pvcreate /dev/sda1                                 
  Physical volume "/dev/sda1" successfully created                         
[root@archbang ablive]# pvdisplay                                          
  "/dev/sda1" is a new physical volume of "40.00 GiB"                      
  --- NEW Physical volume ---                                              
  PV Name               /dev/sda1                                          
  VG Name                                                                  
  PV Size               40.00 GiB                                          
  Allocatable           NO                                                 
  PE Size               0                                                  
  Total PE              0                                                  
  Free PE               0                                                  
  Allocated PE          0                                                  
  PV UUID               sQ1aHi-0gVH-zlAL-MFvp-2vlg-2vDt-CbvtAa             
[root@archbang ablive]# vgcreate vg-root /dev/sda1                         
  Volume group "vg-root" successfully created                              
[root@archbang ablive]# vgdisplay                                          
  --- Volume group ---                                                     
  VG Name               vg-root                                            
  System ID                                                                
  Format                lvm2                                               
  Metadata Areas        1                                                  
  Metadata Sequence No  1                                                  
  VG Access             read/write                                         
  VG Status             resizable                                          
  MAX LV                0                                                  
  Cur LV                0                                                  
  Open LV               0                                                  
  Max PV                0                                                  
  Cur PV                1                                                  
  Act PV                1                                                  
  VG Size               40.00 GiB                                          
  PE Size               4.00 MiB                                           
  Total PE              10239                                              
  Alloc PE / Size       0 / 0                                              
  Free  PE / Size       10239 / 40.00 GiB                                  
  VG UUID               TbuJk8-gGeO-0lfG-MuOQ-7L5u-02Pq-ouAgda             
[root@archbang ablive]#                                                    

Creating your Logical Volumes

Create a Logical Volume, choosing the size (L) and the name (n) and the name of the Volume Group you want to add it to.

lvcreate -L 30G -n root vg-root

You could create a volume that spans the entirity of the available space, or create smaller ones and use them for each partition (/boot, /home, /etc)

Activating your LVM

The Logical Volumes can then be made known to the kernel using the command `lvchange`

lvchange -ay vg-root

This makes them available under `/dev/vg-root` (or equivelent vg name)

mkfs.ext4 /dev/vg-root/root # create a file system (make your own choice here depending on need)

Striping and Mirroring (if you like)

When you write your data to a logical volume, LVM decides how best to store your data on the underlying physical volumes that the volume group resides upon. As you can see above, this means we’re storing out ‘vg-root’ logical volume on the physical volume /dev/sda1 (the LVM partition we made earlier). Don’t worry if you get confused with the terminology, with practice it becomes clear.

Something a bit more advanced would be to create a Striped Logical Volume. This means you can intentionally add multiple physical devices to an LVM and then choose to stripe, which means data can be written and read in parallel with multiple physical drives but it also increases the chances of data loss. This can be thought of as being along the same lines as a Software RAID 1+0.

There’s also a Mirrored Logical Volume, which as the name implies maintains identical copies of the data written onto multiple physical drives. This means that recovery is possible if one of the underlying physical drives fails.


So there you have it, the LVM should be up and running.

How To: Compile Mono for FastCGI & Nginx in Ubuntu 11.10

So if you want to install mono from the comfort of apt-get you can look forward to something like version 2.10 which means that the latest and greatest MVC projects wont work, you’ll run into async issues, and a bunch of other stuff so it’s time to get down and dirty with the mono source code.

Get dependencies

sudo apt-get install build-essential autoconf automake \
bison flex gtk-sharp2-gapi boo gdb valac libfontconfig1-dev \
libcairo2-dev libpango1.0-dev libfreetype6-dev libexif-dev \
libtiff4-dev libgif-dev zlib1g-dev libatk1.0-dev libjpeg8-dev \
libjpeg-turbo8-dev libglib2.0-dev libgtk2.0-dev libglade2-dev \
libart-2.0-dev libgnomevfs2-dev libgnome-desktop-dev \
libgnome2-dev libgnomecanvas2-dev libgnomeui-dev libgnomeprint2.2-dev \
libgnomeprintui2.2-dev libpanel-applet-4-dev \
libnautilus-extension-dev librsvg2-dev libgtkhtml3.14-dev \
libgtksourceview2.0-dev libgtksourceview2.0-dev libvte-dev \
libwnck-dev libnspr4-dev libnss3-dev libwebkit-dev libvala-0.18-dev

Get the source

First we’ll need the following sourcecode:

  • libgdiplus: An Open Source implementation of the GDI+ API. [latest snapshot – see below]
  • mono: Mono open source ECMA CLI, C# and .NET implementation [release 3.2.5]
  • XSP: Monos ASP.NET hosting server. Includes an apache module, fastCGI module and standalone server [release 3.0.11]

note: if we get the latest release version of libgdiplus you may run into an issue during make

/usr/bin/ld: testgdi.o: undefined reference to symbol ‘g_print’
/usr/bin/ld: note: ‘g_print’ is defined in DSO /lib/x86_64-linux-gnu/ so try adding it to the linker command line

getting the latest version linked above includes the pull request that fixes this issue.


Untar/unzip each of the archives:

unzip # unzip libgdiplus
tar -zxf 3.2.5 # untar mono
tar -zxf 3.0.11.tar.gz # untar XSP

for each project the process is exactly the same (before you do this though, read the section on uninstalling below)

# change to project directory (mono in this example)
cd mono
# run autogen to configure the build
./ --prefix=/usr
# build
# install
make install

You may run into missing packages depending on your system configuration, but usually apt-get install the missing dependency is all you really need to do.

Configuring Nginx and FastCGI

coming soon, no really…


I have in the past stayed away from building software on my production server as it can be a pain to remove or upgrade but I’ve found a great tool called CheckInstall. What this does is keep track of the files being copied during the ‘make install’ step and gives you a handy .deb or .rpm file which you can then use to uninstall (or even use this file on other systems instead of having to repeat the build)

To use it, replace ‘sudo make install’ with ‘sudo checkinstall’

How To: Fix Silex & Composer Autoloading – Class Not Found Error

I started a new project in Silex this weekend and spent a while trying to figure this one out.

Fatal error: Class 'App\Model\MyAmazingClass' not found in /var/www/app/public/index.php on line 18

So, silex depends on Composer for its autoloading functionality. I normally handle my dependencies myself and build stuff from source but this is a quick project, let’s give composer a go. So, off to the composer blog to get my composer.json set up. It tells me to add the following section:

    "autoload": {
        "psr-0": {
            "App" : "src"

Okay, now a “composer update” to register the new dependency with composer and I can see that this line has been added to AutoLoad_Namespaces.php:

    'App' => $baseDir . '/app',

Long story short, I was expecting this line to have mapped my ‘App’ namespace to the ‘/app’ folder and expecting that a model folder under /app with my class in it would be autoloaded (crazy right?). What composer needs you to do is create your ‘App’ namespace folder under the directory that you’ve already defined for it.

Anyway, hope this helps someone else out there.