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

Linux mdadm tips & tricks

RAID arrays are an important part of any mission critical enterprise architecture. When we talk RAID here we are talking mirrored RAID, or mirrored and striped RAID, not simply striping which gives you a larger drive from several smaller drives. While that may be great for some home or desktop applications, for a enterprise application that simply doubles your changes of a failed system.

We often spec out RAID 1 or higher mirrored systems with RAID 1+0 being the most common (mirrored and striped) so that you increase access performance AND keep the system up if a single drive fails (on a 3 drive RAID 1+0 configuration). Along the way we’ve learned some tips & tricks that may help you out. To start with we’ll post some info on Linux RAID and eventually expand this article to include Windows information.

Fake v. Real Raid

One thing we’ve learned recently is that in the flood of new low cost servers there has also been a flood of those servers coming with on board RAID controllers. Unfortunately these new RAID controllers use a low cost solution that basically pretends to be a RAID controller by modifying the BIOS software. In essence they are software RAID controllers posing a hardware RAID controllers. This means you have all of the BAD features of both systems.

One easy way to tell if you have a server with “fake raid” is to configure the drives in RAID mode from the BIOS. Then boot and install Linux. If the Linux install sees both drives versus a single drive then the “on board RAID” is a poser. Skip it. Configure the BIOS in standard drive mode & use the software RAID.

Most current Linux distros have RAID setup and configuration built into the setup and installation process.   We’ll leave the details to other web articles.

MDADM – Linux RAID Utility

mdadm is the Linux utility used to manage and monitor RAID arrays.   After configuration a pair of drives, typically denoted with sda0, sdb0 etc. show up in your standard Linux command as md0.   They are “paired up” to make up the single RAID drive that most of your applications care about.

Status Report

mdadm is how you look “inside” the single RAID array and see what is going on.   Here is an example of a simple “show me the status” command on the RAID array.  In this case we have a failed secondary drive in a 2-disk RAID1 array:

[root@dev:log]# mdadm --detail /dev/md0
 Version : 00.90.03
 Creation Time : Thu Jan  8 12:20:13 2009
 Raid Level : raid1
 Array Size : 104320 (101.89 MiB 106.82 MB)
 Used Dev Size : 104320 (101.89 MiB 106.82 MB)
 Raid Devices : 2
 Total Devices : 1
Preferred Minor : 0
 Persistence : Superblock is persistent
 Update Time : Wed Jul 28 07:27:08 2010
 State : clean, degraded
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
 Spare Devices : 0
 UUID : a6ef9671:2a98f9e9:d1146f90:29b5d7da
 Events : 0.826
 Number   Major   Minor   RaidDevice State
 0       8        1        0      active sync   /dev/sda1
 1       0        0        1      removed

[root@dev:~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb[1] sda1[0]
 104320 blocks [2/2] [UU]

md1 : active raid1 sda2[0]
 1020032 blocks [2/1] [U_]

md2 : active raid1 sda5[0]
 482431808 blocks [2/1] [U_]

unused devices: <none>

Rebuild An Array

Shut down the system with the failed drive, unless you have a hot-swap drive setup. Pull the bad drive, partition it if necessary, and tell MDADM to rebuild the array.

[root@dev:~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[0]
 104320 blocks [2/1] [U_]

md1 : active raid1 sda2[0]
 1020032 blocks [2/1] [U_]

md2 : active raid1 sda5[0]
 482431808 blocks [2/1] [U_]

unused devices: <none>
[root@dev:~]# mdadm --add /dev/md0 /dev/sdb1
mdadm: added /dev/sdb1
[root@dev:~]# mdadm --add /dev/md1 /dev/sdb2
mdadm: added /dev/sdb2
[root@dev:~]# mdadm --add /dev/md2 /dev/sdb5
mdadm: added /dev/sdb5

This command adds the replaced drive, /dev/sdb in our case for our second SATA drive, to the first RAID array named md0.

Remove A Drive

To remove a drive it must be marked faulty, then removed.

[root@dev:~]# mdadm --fail /dev/md0 /dev/sdb
[root@dev:~]# mdadm --remove /dev/md0 /dev/sdb

We had to do this on our drive because we forgot to partition it into a boot and data (/ and /boot and /dev/shm) partition.  Thus the /dev/sdb instead of /dev/sdb1, etc. as it the norm for a partitioned drive.

Checking Rebuild Progress

[root@dev:~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
 104320 blocks [2/2] [UU]
md1 : active raid1 sdb2[1] sda2[0]
 1020032 blocks [2/2] [UU]
md2 : active raid1 sdb5[2] sda5[0]
 482431808 blocks [2/1] [U_]
 [>....................]  recovery =  0.8% (4050176/482431808) finish=114.5min speed=69592K/sec
unused devices: <none>

FDISK – Drive Partitioning

To properly re-add a drive to an array you will need to set the partitions correctly.  You do this with fdisk.  First, look at the partitions on the valid drive then copy that to the new drive that is to replace the failed drive.

[root@dev:~]# fdisk /dev/sda

The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
 (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

 Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   fd  Linux raid autodetect
/dev/sda2              14         140     1020127+  fd  Linux raid autodetect
/dev/sda3             141         741     4827532+  8e  Linux LVM
/dev/sda4             742       60801   482431950    5  Extended
/dev/sda5             742       60801   482431918+  fd  Linux raid autodetect

[root@dev:~]# fdisk /dev/sda

Use "n" to create the new partitions, and "t" to set the type to match above.
That should get you started.  Google & Linux man commands are your friend.  As we have time we’ll publish more Linux RAID tricks here.

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.