Ubuntu 12.04 Precise Pangolin failing to boot because of UEFI

Ubuntu 12.04 Precise Pangolin struggled to boot up after being installed on a Lenovo ThinkServer that features UEFI. Installer automatically created a FAT32 partition for UEFI, however Lenovo ThinkServer refused to boot up, complaining about no operating system being installed on that particular disk.

Amending boot mode in BIOS to “Legacy” instead of “EFI” and then proceeding with manual partitioning (e.g. root / and linux swap) during Ubuntu installation fixed the problem.

No Comments

Shrinking a dynamic Virtualbox hard disk on Ubuntu

Mount a Ubuntu Live CD and boot into it. Install zerofree

sudo apt-get install zerofree

If the package cannot be found, try enabling Multiverse repository (Software Sources).

Find out which drive you want to shrink


Run zerofree

sudo zerofree /dev/sda1

Once finished, shut down the Virtualbox machine and use Virtualbox to compact the hard disk image file

VBoxManage modifyvdi /path/to/the/image.vdi compact


No Comments

Compiz performance problem - Ubuntu Lucid Lynx 10.04

On 5th May 2010, there was an update to “libgnome-window-settings1” and related packages (”capplets-data” & “gnome-control-center”). This caused terrible compiz performance (CPU often spiking to 80%). Workaround is to downgrade to the previous version, I also recommend locking the version via Synaptic/Aptitude for the time being.

Workaround - downgrading the package:

aptitude install libgnome-window-settings1=1:2.30.0-0ubuntu4

Launchpad bug: https://bugs.launchpad.net/bugs/576604

No Comments

Zend Framework & Smarty with Zend view helpers

If you wish to use Smarty templating engine together with Zend Framework, the following will give you an idea how it can be accomplished.

1. Download Smarty class that extends Zend_View_Abstract

Download Smarty class

Zend Framework is located in its default location: project/library/Zend
Smarty should be located in project/library/Smarty

2. Define smarty and view variables in your application config:

smarty.compile_dir = APPLICATION_PATH "/storage/smarty/compiled"
smarty.cache_dir = APPLICATION_PATH "/storage/smarty/cache"
smarty.template_dir = APPLICATION "views/templates/"
smarty.config_dir = APPLICATION "views/config/"
smarty.layout_dir = APPLICATION "views/layouts/"
app.encoding = "ISO-8859-1"

3. Initialise the view in your bootstrap class, e.g. _initView() method:

protected function _initView() {

/* Create view object, assign paths and disable checking of templates if in production */
$view = new Jazz_View_Smarty($this->_appConfig->smarty->template_dir, array(
  'cache_dir' => $this->_appConfig->smarty->cache_dir,
  'compile_dir' => $this->_appConfig->smarty->compile_dir,
  'config_dir' => $this->_appConfig->smarty->config_dir,
  'compile_check' => APPLICATION_ENV == 'production' ? FALSE : TRUE

/* Set correct encoding - omitting may cause problems with forms etc. */

  Zend view helpers will become available as $zendView-> in smarty templates
  Examples: {$zendView->headLink()} {$zendView->headScript()}
$view->assign('zendView', $view);

/* Notify the view helper */


If you use Zend_Layout, you can pass the view into it:

    'layout' => 'default_layout_template_name',
    'view' => $view,
    'viewSuffix' => Jazz_View_Smarty::TEMPLATE_EXTENSION)

4. Use the view in your controller as usual:

public function indexAction() {
  $this->view->someVariable = array('one', 'two', 'three');

This becomes


in Smarty templates

1 Comment

Fixing Plymouth in Ubuntu 10.04 Lucid Lynx (server)

Some time during the upgrades, Plymouth got broken. It seems that the theme got removed and so I was not getting a graphical interface and it also kept generating some warnings during updates such as:

grep: /lib/plymouth/themes/text.plymouth: No such file or directory
grep: /lib/plymouth/themes/default.plymouth: No such file or directory

Installing the following two packages fixed it for me:

sudo apt-get install plymouth-theme-ubuntu-logo
sudo apt-get install plymouth-theme-text

No Comments

Postfix relay setup in 5 minutes (Ubuntu)

The following procedure will install and set up postfix and use another mail server to relay emails. Tested on Ubuntu 10.04 (Lucid Lynx).

sudo su

apt-get install postfix
Choose “satellite/smarthost” type, all emails will be relayed to another mail server

cd /etc/postfix

vim main.cf
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =

vim sasl_passwd
relay.server.com user@name:password

chmod 600 sasl_passwd

postmap /etc/postfix/sasl_passwd

service postfix restart

sendmail email@domain.com

Read postfix documentation in order to make your installation more secure.

No Comments

Installing PHP4 & Apache2.2 from source (Ubuntu 9.04 Jaunty Server)

I had to install PHP4 on a server in order to a test an application that will run under PHP4. Being a fan of Ubuntu, I chose Ubuntu 9.04 Jaunty Server edition as OS.

At first, I tried to install Apache using apt but subsequent compiling of PHP failed, perhaps due to different location of apache installation when using apt. Possibly, this can be fixed with some directives where to find certain Apache modules etc.

I then decided to install both latest Apache 2.2x and latest PHP4 (4.4.9) from scratch - compiling it. The process is quite simple as outlined on (php.net website):

  1. make yourself root
    sudo su
  2. download both, Apache 2.2, PHP4
  3. decompress as necessary
    gunzip filename.gz
    tar -xvf filename.tar
  4. install “flex” and “bison”
    apt-get install flex
    apt-get install bison
  5. configure Apache
    cd httpxx
    ./configure --enable-so
  6. install make if missing
    apt-get install make
  7. compile Apache
    make install
  8. install apache2-threaded-dev
    apt-get install apache2-threaded-dev
  9. Configure PHP
    ./configure --with-apxs2=/usr/bin/apxs2 --with-mysql
    Please note this is the minimal configuration including mysql libraries, if you need more modules, you need to add them.

    If config fails because of missing libicu, install it using:
    apt-get install libicu-dev
    If you get xml2-config error message, install:
    apt-get install libxml2-dev

  10. Compile PHP
    make install
  11. Copy over default php.ini, amend as necessary and add handler for php files to Apache config file (if necessary).
  12. You can also modify default index page to include index.php.

No Comments

Fetching of emails from a POP3 server and serving via IMAP (Ubuntu)

One of the servers from which I download emails regularly doesn’t provide IMAP access. The obvious solution seemed to be install my own IMAP server and fetch emails from the original server via POP3.

After a brief research, I’ve decided to install Dovecot and getmail to accomplish the above.

First step was to install Dovecot:

sudo apt-get install dovecot-imapd

Then I followed instructions from Dovecot website, set the location of IMAP mail directories and configured it to use SSL connections only. I have also modified standard port in /etc/dovecot/dovecot.conf from 993 to a different one:

protocol imap {
ssl_listen = *:7777

Restarted Dovecot

sudo /etc/init.d/dovecot restart

and tested my first IMAP account using Thunderbird. As the SSL certificate I used on the server was self-signed, Thunderbird complained about it but that can be ignored and SSL certificate saved.

After that, I installed getmail:

sudo apt-get install getmail4

For each mailbox I wanted to download from a POP3 server, I defined a separate config file for getmail:

type = SimplePOP3Retriever
server = mailserver
username = user
password = pass

type = Maildir
path = ~/Maildir/

Note that emails will be saved into Maildir directory within home directory of a particular user. Maildir is also the format in which emails will be saved. This configuration works nicely with Dovecot when serving emails.

The last step was to set up a cron job to fetch emails from POP3 and save them into IMAP folder:

crontab -e
* * * * * getmail -d >> getmail.log

where “-d” means it will delete messages from the server after downloading them.

getmail can also load multiple config files at once, so if you have more then one account to fetch:

getmail -d -r configfile1 -r configfile2

No Comments

PHP Magic Methods - enforce defining of class properties

Sometimes it’s desirable to have a control over which properties can be assigned to an object. Typo mistakes, duplicating of property names, among others, are the commons pitfalls of PHP’s ability to set/get properties without defining them in a class.

The MagicMethods class enforces that class properties are defined in a class before we can set or get their values. Any class that extends this class will benefit from this behavior (unless magic method get overridden in the exteding class). If a getter or setter method is needed to manipulate a property, MagicMethod class will use these instead of directly accessing the value.

This functionality is especially handy for value objects or config classes.


class ConfigMagic extends MagicMethods_Abstract
  // note $name is protected, not private, so that MagicMethods_Abstract can access it
  protected $name;
  public function getName()
     // provides more complex way of getting a variable
     return $this->name;
  public function setName($value)
    // provides more complex way of setting a variable
   $this->name = $value;
$config = new ConfigMagic();
$config->name = 'magic';
var_dump($config->name); // string 'magic' (length=5)
var_dump(isset($config->name));  // true
var_dump(isset($config->name)); // false
// Exception: Cannot set property 'nonExisting'. Not defined in class ConfigMagic ...
$config->nonExisting = 'magic';

Download the files:

 * Magic Methods
 * Provides magic methods for other classes, enforces property names.
 * Undefined property name throws an exception
 * @package DAO
 * @uses MagicMethodsException
 * @example MyOwnClass extends MagicMethods_Abstract
 * @license Free to use and modify (including commercial use)
 * @see http://php.net/manual/en/language.oop5.magic.php
 * @author Juraj Seffer 
 * @copyright 2009, Juraj Seffer
 * @version $Id$
 * @access public
abstract class MagicMethods_Abstract
   * Magic getter
   * @param string $property
   * @access protected
   * @return mixed
  protected function __get($property)
    $getterMethod = "get" . strtoupper($property);
    if (method_exists($this, $getterMethod)) {
      return $this->$getterMethod();
    else if (!property_exists($this, $property)) {
      throw new MagicMethodsException(
        "Cannot get property '$property'. Not defined in class " . get_class($this)
    else {
      return $this->$property;
   * Magic setter
   * @param string $property
   * @param mixed $value
   * @access protected
   * @return void
  protected function __set($property, $value)
    $setterMethod = "set" . strtoupper($property);
    if (method_exists($this, $setterMethod)) {
      return $this->$setterMethod($value);
    else if (!property_exists($this, $property)) {
      throw new MagicMethodsException(
        "Cannot set property '$property'. Not defined in class " . get_class($this)
    else {
      $this->$property = $value;
   * Magic isset
   * @param string $property
   * @access protected
   * @return mixed
  protected function __isset($property)
    if (!property_exists($this, $property)) {
      throw new MagicMethodsException(
        "Property '$property' not defined in class " . get_class($this)
    else {
      return isset($this->$property);
   * Magic unset
   * @param string $property
   * @access protected
   * @return void
  protected function __unset($property)
    if (!property_exists($this, $property)) {
      throw new MagicMethodsException(
        "Property '$property' not defined in class " . get_class($this)
    else {
      $this->$property = null;
 * @copyright 2009, Juraj Seffer
 * @version $Id$
 * @access public
class MagicMethodsException extends Exception
   * Constructor
   * @param string $exception
   * @access public
   * @return void
   public function __construct($exception)
    throw new Exception($exception);

, , , ,

No Comments

Forwarding of ports via SSH - multiple hops

So you have a server to which you can’t connect directly because it’s behind a firewall? Or even two firewalls/computers ?

In my example, I wanted to set up port forwarding of port 80 from server via pc1 and gateway to pc2.

First thing is to connect from pc2 to gateway
ssh user@gateway

Then when logged into gateway, map port 80 of server via pc1
ssh -N -L8888:server:80 user@pc1

Last step is to forward port from gateway to cp2
ssh -N -L8888:localhost:8888 user@gateway

Note that port number 8888 is random, you can use any open port. You can also fork any of the above commands to the background using “-f” option, e.g:
ssh -f -N -L8888:localhost:8888 user@gateway

No Comments

Java applets Ubuntu 8.10 64bit

The following made Java applets work in Firefox 3 on Ubuntu 8.10 64bit:

sudo apt-get install icedtea6-plugin openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib

No Comments

Gnome / Nautilus hangs?

I had a problem with Gnome starting late and hanging while Nautilus would start but would not show. It turned out to be one of the bookmarks in Nautilus causing both of them to hang. This is the file where Nautilus’ bookmarks are kept (Ubuntu 8.10):


This problem can be also caused by an unresponsive samba share mounted to your filesystem.

No Comments

Default terminal size in Ubuntu

Too small for you?
sudo gedit /usr/share/vte/termcap/xterm
and replace :co#80:it#8:li#24:\ with say :co#180:it#8:li#30:\
That will give you 180×30

No Comments


Stumbled upon this lovely monitor today.

Conky is a free, light-weight system monitor for X, that displays any information on your desktop.

Here is a screenshot of my configuration:


To get the same:

$ sudo apt-get install conky
$ vi .conkyrc

paste the contents of this conky config:

… save the file, download and extract this archive into your home directory (cd ~) and run

$ conky

Please note that I have removed CPUs 2-4 from the config to make it more compatible with single processor systems. Full list of Conky variables.

If you wish to monitor a remote Ubuntu computer and display conky’s output on your desktop:

$ scp .conkyrc scp username@remoteserver:
$ ssh -X username@remoteserver
$ sudo apt-get install conky
$ conky

UPDATE: If your server doesn’t have Xorg installed (which most don’t), you can use {execi} to issue commands over ssh and grep the info you need. The below part of conkyrc is based on a Ubuntu Jaunty server, your distribution may vary in where some of the details are stored.
${voffset 30}
${execi 43200 ssh vds hostname} ${hr 2}
${voffset 2}${font OpenLogos:size=16}u${font}   Kernel:  ${alignr}${execi 43200 ssh vds uname -r}
${execi 43200 ssh vds less /proc/cpuinfo | head -n 5 | tail -n 1 | cut -d @ -f 2 | cut -c 2-} ${alignr}Load: ${execi 60 ssh vds uptime |cut -d , -f 4- | cut -c 17-}
${execibar 60 ssh vds bash ~/cpuload.sh}
${execigraph 60 ssh vds bash ~/cpuload.sh}
${font StyleBats:size=16}q${font}   Uptime: ${alignr}${execi 60 ssh vds uptime |cut -d , -f 1 | cut -c 2-}
${font StyleBats:size=16}q${font}   Users logged in: ${alignr}${execi 60 ssh vds w | head -n 1 | cut -d \  -f 7- | cut -d \, -f1}

HD ${hr 2}
${execi 600 ssh vds df -h | head -n2 | tail -n1 | cut -c 24-}
${voffset 4}${execibar 600 ssh vds df -h | head -n2 | tail -n1 | cut -c 41-42}

NETWORK ${hr 2}
${voffset 4}${font PizzaDude Bullets:size=14}N${font}   Download: ${alignr}${execi 600 ssh vds ifconfig | head -n 8 | tail -n 1 | cut -d \( -f 2 | cut -d \) -f 1}
${voffset 4}${font PizzaDude Bullets:size=14}T${font}   Upload: ${alignr}${execi 600 ssh vds ifconfig | head -n 8 | tail -n 1 | cut -d \( -f 3 | cut -d \) -f 1}
${voffset 4}${font PizzaDude Bullets:size=14}b${font}   Public IP: ${alignr}${execi 43200 ssh vds ifconfig | head -n 2 | tail -n 1 | cut -c 21- | cut -d \  -f 1}

TOP: ${hr 2}
${voffset 4}${execi 60 ssh vds ps -eo pcpu,pid,user,args | sort -k 1 -r | head -5}

Note that if you run both local and remote conky, you may need to amend conky’s position on the remote server in .conkyrc so they won’t overlap.

To start conky from a remote computer and have it displayed on yours, create this as a .sh script and run:

ssh -X username@remoteserver 'conky'

And finally, if you wish to start conky automatically after your log in, create a bash script with the following and add it into your Ubuntu start up programs:

sleep 20 && conky;

Halting it for 20 seconds prevents compiz from applying border and drop down shadows etc. to conky’s window.

No Comments

Need drive space? Look into root’s Trash

I came across files stored in /root/.local/share/Trash/files that were taking quite a lot of space. I presume this were deleted during various installations/updates and command line deletions (as root).

To delete root’s Trash files, type in terminal:

$sudo su
$ cd /root/.local/share/Trash/
$ rm -f files

No Comments