Posted on

Custom Ubuntu Keyboard Layouts

Sometimes a programmer just has to have certain keys in certain places.

For instance, I like my number keys and symbol key switched, so I don’t have

to press shift to type symbols.

Here’s how I created a custom keyboard layout in Ubuntu:

In the file /usr/share/X11/xkb/symbols/us, I added the following section, thus modifying my default layout:

partial alphanumeric_keys modifier_keys
xkb_symbols "basic" {
name[Group1]= "USA";

// Alphanumeric section
key <TLDE> {        [asciitilde,        grave            ]        };
key <AE01> {        [    exclam,        1                ]        };
key <AE02> {        [        at,        2                ]        };
key <AE03> {        [ numbersign,       3                ]        };
key <AE04> {        [    dollar,        4                ]        };
key <AE05> {        [   percent,        5                ]        };
key <AE06> {        [ asciicircum,      6                ]        };
key <AE07> {        [ ampersand,        7                ]        };
key <AE08> {        [  asterisk,        8                ]        };
key <AE09> {        [ parenleft,        9                ]        };
key <AE10> {        [ parenright,       0                ]        };
key <AE11> {        [     minus,        underscore       ]        };
key <AE12> {        [     equal,        plus             ]        };
key <AD01> {        [         q,        Q                ]        };
key <AD02> {        [         w,        W                ]        };
key <AD03> {        [         e,        E                ]        };
key <AD04> {        [         r,        R                ]        };
key <AD05> {        [         t,        T                ]        };
key <AD06> {        [         y,        Y                ]        };
key <AD07> {        [         u,        U                ]        };
key <AD08> {        [         i,        I                ]        };
key <AD09> {        [         o,        O                ]        };
key <AD10> {        [         p,        P                ]        };
key <AD11> {        [ bracketleft,      braceleft        ]        };
key <AD12> {        [ bracketright,     braceright       ]        };
key <AC01> {        [         a,        A                ]        };
key <AC02> {        [         s,        S                ]        };
key <AC03> {        [         d,        D                ]        };
key <AC04> {        [         f,        F                ]        };
key <AC05> {        [         g,        G                ]        };
key <AC06> {        [         h,        H                ]        };
key <AC07> {        [         j,        J                ]        };
key <AC08> {        [         k,        K                ]        };
key <AC09> {        [         l,        L                ]        };
key <AC10> {        [ semicolon,        colon            ]        };
key <AC11> {        [ apostrophe,       quotedbl         ]        };
key <AB01> {        [         z,        Z                ]        };
key <AB02> {        [         x,        X                ]        };
key <AB03> {        [         c,        C                ]        };
key <AB04> {        [         v,        V                ]        };
key <AB05> {        [         b,        B                ]        };
key <AB06> {        [         n,        N                ]        };
key <AB07> {        [         m,        M                ]        };
key <AB08> {        [     comma,        less             ]        };
key <AB09> {        [    period,        greater          ]        };
key <AB10> {        [     slash,        question         ]        };
key <BKSL> {        [ backslash,        bar              ]        };
// End alphanumeric section

Each line in this file tells Ubuntu what character to type when a particular key is pressed. For instance, in a line like

key  {        [ numbersign,       3                ]        };

…we can see that key “AE03” will produce the number sign by default, and “3” when shift is held down. This is reverse of the normal layout, since it reflects my customization. The original line would read:

key  {        [ 3,        numbersign                ]        };

All the spaces being used to line everything up are just to help make things look nice and neat, and could just as easily be left out.

After modifying this file, I went to “System > Preferences > Keyboard” and clicked the “Layouts” tab. I added the layout, which was found under the United States country. I had some problems with the layout switching arbitrarily, or applying in one program but not others, so I disabled all other layouts.

It’s as easy as that. Remember to make a backup of your original /usr/share/X11/xkb/symbols/us file, and hack away!

Posted on

Setting Up Raid 1 On Ubuntu 10.04

The following has been distilled from and revised to match our operating process.


Follow the installation steps until you get to the Partition disks step, then:

  1. Select Manual as the partition method.
  2. Select the first hard drive, and agree to “Create a new empty partition table on this device?”.
    • Repeat this step for the second drive.
  3. Select the “FREE SPACE” on the first drive then select “Create a new partition”.
  4. Next, select the Size of the partition. This partition will be the swap partition, and a general rule for swap size is twice that of RAM. Enter the partition size, then choose Primary, then Beginning.
  5. Select the “Use as:” line at the top. By default this is “Ext4 journaling file system”, change that to “physical volume for RAID” then “Done setting up partition”.
  6. For the / partition once again select “Free Space” on the first drive then “Create a new partition”.
  7. Use the rest of the free space on the drive and choose Continue, then Primary.
  8. As with the swap partition, select the “Use as:” line at the top, changing it to “physical volume for RAID”. Also select the “Bootable flag:” line to change the value to “on”. Then choose “Done setting up partition”.

RAID Configuration

With the partitions setup the arrays are ready to be configured:

  1. Back in the main “Partition Disks” page, select “Configure Software RAID” at the top.
  2. Select “yes” to write the changes to disk.
  3. Choose “Create MD device”.
  4. Select “RAID1”
  5. Enter the number of active devices “2”, or the amount of hard drives you have, for the array. Then select “Continue”.
  6. Next, enter the number of spare devices “0” by default, then choose “Continue”.
    • Choose which partitions to use. Generally they will be sda1, sdb1
    • For the swap partition choose sda1 and sdb1. Select “Continue” to go to the next step.
  7. Repeat steps three through seven for the / partition choosing sda2 and sdb2.
  8. Once done select “Finish”.


There should now be a list of hard drives and RAID devices. The next step is to format and set the mount point for the RAID devices. Treat the RAID device as a local hard drive, format and mount accordingly.

  1. Select “#1” under the “RAID1 device #0” partition.
  2. Choose “Use as:”. Then select “swap area”, then “Done setting up partition”.
  3. Next, select “#1” under the “RAID1 device #1” partition.
  4. Choose “Use as:”. Then select “Ext4 journaling file system”.
  5. Then select the “Mount point” and choose “/ – the root file system”. Change any of the other options as appropriate, then select “Done setting up partition”.
  6. Finally, select “Finish partitioning and write changes to disk”.
  7. The installer will then ask if you would like to boot in a degraded state, select Yes.
Posted on

Ubuntu – No Audio When Playing Videos

I recently tried to play a video on Ubuntu 10.04, but got no audio because of missing a Windows Media Audio codec. My video player tried to automatically find a suitable plugin and failed. So here’s how I fixed it by hand.

Step One: Update mplayer

The version of mplayer that comes with Ubuntu is behind the times.
But that’s easy to fix.

    $ sudo add-apt-repository ppa:rvm/mplayer
    $ sudo apt-get update
    $ sudo apt-get upgrade mplayer

Bam. Done. Also why not install smplayer while you’re at it—has a much better interface in my opinion.

*Note:* If you prefer to use something else like vlc then upgrading may not be necessary. Check the documentation for your preferred movie player to see about its WMA support.

Step Two: Discover the DLL You Need

This is easy: just try playing the file from the command line.

Something like

    $ smplayer legitimate_copy_of_a_movie_i_totally_own.wmv

If you see a ton of output, and hear no audio, then you are missing a library. Thankfully (s)mplayer will tell you exactly what this library is called; just look in the output for the name of a `.dll` file mentioned in conjunction with audio.

Step Three: Add the DLL

Get on your favorite search engine, enter the DLL, and find a copy to download.

Whatever DLL you need, take it and put it in the directory `/usr/lib/codecs`. The directory probably does not exist, so create it first, of course. Video players will automatically look there for the DLLs they need.

After that, you should all be set. That’s how I was able to get audio out of Windows Media Player 9 files. Hope it helps you too.

Posted on

PostgreSQL Cheat Sheet

PostgreSQL is one of our favorite database engines for a variety of reasons.  Here is our cheat sheet to help you get online and get around Postgres with minimal effort.

Database Access Security

Database security is handled primarily in two place, from the system service level via a file called pg_hba.conf and within the database metadata files themselves.   The pg_hba.conf file controls what level of credentials are needed based on what IP address the requesting connection is coming from.   The metadata within the engine itself generally controls user level access once they are connected and approved at the system level.

Systemwide Configuration via pg_hba.conf

This file matches IP address with a set of rules to determine how much data you need to provide in the first place before getting access to the database engine.   It includes the IP address, the username trying to connect, and what type of validation is needed.

The data comes in a series of tab separated columns including:

  • Connection Type
    • local = from local tty connection
    • host = from an internet connection
  • Database = which database is the user trying to connect to?
  • User = which user they are connecting as.
  • IP Address = what address are they coming from?
  • Method = how shall we authenticate them?
    • md5 = let them in if the password matches
    • ident sameuser = let them in in the password matches and their login user matches the user they are trying to connect as
    • trust = let them in as long as the ip address matches, no password required

Finding pg_hba.conf

The pg_hba.conf file lives in various places depending on the flavor of Linux.

  • Red Hat, CentOS, Fedora = /var/lib/pgsql/data/
  • Ubuntu = /etc/postgresql/<version>/main/

Command Line Access

You can do a lot of maintenance operations or test queries using the command line interpreter.  The command line in PostgreSQL is accessed via the psql command.   The most often used parameters with psql are to connect as a user other than your login user, provide your password, and give it the name of the database on which to connect.


# psql -U other_name -W other_db

Command Line Shortcuts

From the command line there are a variety of shortcuts to help you navigate around the database engine or see what is going on.  Here are a few of the most useful:

  • List Databases: \l
  • List (display) Tables : \dt
  • List Columns in a Table: \d <tablename>

Creating A Database

Here is how you create a new database that is owned by  a specific user.  This assumes a “clean slate” install.   You will need to have the postgres user login credentials and/or root access.  You will be creating a PostgreSQL user and password and will change the system-level postgres daemon security settings to allow access with the password regardless of which user you login as.

# # login as postgres user or su postgres if you are root

# psql
psql> create user lance with password ‘cleveland’;
psql> create database myfirstdb with owner lance;
psql> \q
# vi /var/lib/pgsql/data/pg_hba.conf

While in pg_hba.conf change this line:

local   all         all                              ident

to this:

local   all         all                              md5

Backing Up / Dumping Your Data

Data dumps are a quick way to put the schema, data, or a combination of both out into a file that can be used to re-create the database on other systems or just back it up to a remote location.  The PostgreSQL command for this is pg_dump.  It takes the same parameters as thecommand line access.

Simple Data Dump


# pg_dump -U myname -W the_db_name > dump_thedb_2010_0704_001.sql

Clean Data Dump

This is the format to use if you want to ensure the entire database is dropped & re-created when loading on a new system.


# pg_dump --clean --create -U myname -W the_db_name > dump_thedb_2010_0704_001.sql

Reloading Dumped Data

To reload such a script into a (freshly created) database named the_db_name :

# psql -d the_db_name -f dump_thedb_2010_0704_001.sql

If the clean data dump method was used you will want to login as postgres and let the sql script create the database:

# su postgres

# psql -f dump_thedb_2010_0704_001.sql


There are plenty more tips, tricks, and shortcuts.  These will get you started.  We’ll add more as time allows.