May 052011
 

For my own future reference …

Today I encountered an interesting little issue where I could not send an ABORT signal to a running process to kill it with a core dump because the process had a limit of 0 for the core dump size. Try as I might, I could not find a way to change that process’s core dump limit.

Turns out there is another way of tackling the problem, which is to use gdb to generate a core image :-

gdb
>attach PID
>gcore /var/tmp/core.PID

There is of course the gcore shell script wrapper for this, but that may not work if the working directory of the process no longer exists.

Jan 292011
 

In the dim and distant past when keyboards were enclosed in metal cases and you certainly didn’t tuck one under the arm and walk around with it (actually I don’t do now either), the placement of many keys was continually up for debate. But apart from the main QWERTY section, one of the key placements you could rely on was the Control key next to the “A” key. These days it’s been turned into one of those silly CapsLock keys.

Back when I previously did some keymapping, I neglected to mention how I mapped CapsLock into a Control key. As appropriate punishment, changing window managers has somehow meant that my previous mapping had been lost. So I had to figure out how to do it again.

First thing to do is to switch to a text console – I’ll be mapping this at a very low level.

Next thing to do is to find out the scancode of the key I want to map :-

# showkey -s

One started I have to press the key I am interested in within 10 seconds or the program will edit. I press CapsLock and I get two numbers displayed – 3a and ba (they’re in hexadecimal for the base-16 challenged). The first is the key press, and the second is the key release. We can discard the second as Linux is clever enough to figure out one from the other.

The next thing we want to do is to obtain the keycode of the key that we want to map to – in this case the left control key. It probably doesn’t matter here, but it is worth noting that the left and right control keys are different scancodes and keycodes. So you could map then to different things. Anyway, to obtain the keycode of the key we want, run :-

# showkey -k

And press the key to map to.

Lastly we want to construct the command to actually do the mapping :-

setkeycodes 3a 29

This of course has to be added to a script being run when the system boots – you want this mapped as early as possible.

Aug 112010
 

Ten years ago? Bloomin’ heck! Still as this still seems to get frequent hits, I suppose quick update is in order – I no longer use the Unicomp “naked” but go through a Soarer converter which is an easier way of mapping the keys and allows macros to be added.

Thanks to these guys (the thread eventually gets to the meaty details), I have changed my Unicomp 122-key keyboard (UB40T56) from a funky “be friendly to Windows IBM Terminal emulators” mode into something a little more interesting. Specifically each key should be sending a unique keycode – which if you select the right model from Unicomp, you’ll get.

This can be done by opening up the keyboard and removing the jumper from JP3 (just below a small chip and close to the scroll LED). In addition, it is strongly suggested that you set the kernel parameter “atkbd.softraw=0” which can be done with Ubuntu 10.04 with the following :-

  1. Edit /etc/default/grub and change the variable GRUB_CMDLINE_LINUX_DEFAULT to include “atkbd.softraw=0” at the end of what is already there.
  2. Finish editing and run grub-update and finally reboot.

Without this, showkey -s only shows the scancodes of keys that the kernel knows about – not what scancodes are sent by the keyboard! It is possible to show the unknown scancodes by enabling the i8042 module debug mode, but atkbd.softraw does the same thing more effectively.

This is currently a work in progress, and will need further checking before it can be taken as gospel, but …

Group Key Make Break Keycode
Function Keys
F13 5b db
F14 5c dc 95
F15 5d dd 183
F16 63 e3
F17 64 e4
F18 65 e5
F19 66 e6
F20 67 e7
F21 68 e8
F22 69 e9
F23 6a ea
F24 6b eb
(next row) F1 3b bb 59
F2 3c bc 60
F3 3d bd 61
F4 3e be 62
F5 3f bf 63
F6 40 c0 64
F7 41 c1 65
F8 42 c2 66
F9 43 c3 67
F10 44 c4 68
F11 57 d7 87
F12 58 d8 88
Left Keypad (Top left is “Esc”)
Esc 7e fe 121
Cent 76 f6 85
Print Screen 72 f2
Pause e1 1d 45 e1 9d c5 119
Print 74 f4
Help 6d ed
Record e0 2a e0 37 e0 b7 e0 aa 99
Play 6f ef
GUI (Windows) 75 f5
Menu 6c ec
Editing Pad (between QWERTY and Number Pad)
Backtab 5a da
Insert e0 49 e0 c9 104
PageUp e0 51 e0 d1 109
(next row) Blue Return e0 4f e0 cf 107
Delete e0 52 e0 d2 110
Page Down e0 53 e0 d3 111
(next row) Up Arrow e0 48 e0 c8 103
(next row) Left Arrow e0 4b e0 cb 105
Home e0 47 e0 c7 102
Right Arrow e0 4d e0 cd 106
(next row) Down Arrow e0 50 e0 d0 108
Number Pad
(top row) End 01 81 1
Scroll Lock 46 c6 70
(shifted Scroll Lock) Number Lock 45 c5 69
/ 37 b7 55
* e0 c5 e0 b5 98
(next row) KP-7 47 c7 71
KP-8 48 c8 72
KP-9 49 c9 73
4e ce 78
(next row) KP-4 41 cb 75
KP-5 4c cc 76
KP-6 4d cd 77
+ 4a ca 74
(next row) KP-1 4f cf 79
KP-2 50 d0 80
KP-3 51 d1 81
Enter e0 1c e0 9c 96
(next row) KP-0 52 d2 82
KP-. 53 d3 83
  • Group. To break things up a little, I’ve grouped the keys into the 5 separate parts of the keyboard – the function keys, the keypad to the left, the qwerty pad, the editing pad, and the number pad (“keypad”). The details of the qwerty pad will be the last as the other groups are more interesting (‘qwerty’ keys just work).
  • Key. This is the label on the key on my keyboard. This may be different on different variants so in all cases I have started with the top left, worked left and down (the “qwerty” row before the “asdf” row).
  • Make. This is the scancode produced when the key is pressed.
  • Break. This is the scancode produced when the key is released.
  • Keycode. The configured keycode produced on the Linux console. The red cells are values that are wrong, but in addition many are missing because they are not produced on a keypress. I say wrong because the keycode gives a result that does not match the key legend – in some cases dangerously wrong such as PageDown generating Delete. One thing to be aware of is that you must use “showkey -k” at the console to get the same numbers I have – X seems to add 8 to each keycode.

Three interesting oddities here … F14 and F15 have somehow been graced with keycodes by default; their scan codes must coincide with keys defined on more popular keyboards. And of course Num Lock and Scroll Lock sharing the same key is a little … odd. And lastly the Record key is effectively sending two keystrokes in one.

Fixing The Wrong Keys

The first place to start is to map the keys that return a keycode that represents a key other than that written on the keycap – such as the key marked “End” which thinks it is an “Esc” key. I have left out two of the wrong keys from this group as they fit better into the next section.

The wrong keys can be fixed with the following commands :-

setkeycodes 7e         1    # Esc
setkeycodes e049      82    # Insert
setkeycodes e051     105    # PageUp
setkeycodes e052     111    # Delete
setkeycodes e053     109    # PageDown
setkeycodes 01       107    # End
setkeycodes 37        98    # KP-/
setkeycodes e035      55    # KP-*
setkeycodes 4e        74    # KP--
setkeycodes 4a        78    # KP-+

I have left out a couple of the wrong keys from this section as they do not return dangerously incorrect values, and they fit more logically into the next section (being Record and Blue Return).

Dealing With The Extra Keys

Now onto dealing with the extra keys. The tricky bit here was coming up with new keycodes for these keys that did not conflict with existing keycodes, and were reasonable. This is effectively impossible, as xmodmap -pk appears to show no significant range of unused keycodes although some of the used keycodes are for things like “Shop” buttons!

So I picked a range with a larger number of useless key symbols and some unused ones :-

setkeycodes 5b       222    # F13
setkeycodes 5c       223    # F14
setkeycodes 5d       224    # F15
setkeycodes 63       225    # F16
setkeycodes 64       237    # F17
setkeycodes 65       238    # F18
setkeycodes 66       228    # F19
setkeycodes 67       229    # F20
setkeycodes 68       230    # F21
setkeycodes 69       231    # F22
setkeycodes 6a       232    # F23
setkeycodes 6b       233    # F24
setkeycodes 72        99    # Record (after keyswap)
setkeycodes 74       209    # Print
setkeycodes 6d       138    # Help
setkeycodes 6f       239    # Play
setkeycodes 75       234    # Windows (GUI)
setkeycodes 6c       240    # Menu
setkeycodes 5a       235    # Backtab
setkeycodes e04f     236    # BlueReturn

Once this has run, we can look at fixing the X mappings … which is why F17 and F18 are out of sequence in the above! One key has to be (at least until someone comes up with a better solution!) sorted out with a keycap swap. Take the keycap from the Record key and swap it for the one marked “Print Screen”. This is because the scancode for Record is effectively two scancodes in one and attempting to remap it will result in strange things happening.

Sorting Out X11

Once you have a set of keycodes that don’t do funny things under X (for instance F17 and F18 when in sequence produce not a keystroke under X11 but some other event), you can move onto configuring the X keyboard. The following attempts to map as close to the keycaps as possible without going to extremes :-

xmodmap -e "keycode 230 = F13"
xmodmap -e "keycode 231 = F14"
xmodmap -e "keycode 232 = F15"
xmodmap -e "keycode 233 = F16"
xmodmap -e "keycode 245 = F17"
xmodmap -e "keycode 246 = F18"
xmodmap -e "keycode 236 = F19"
xmodmap -e "keycode 237 = F20"
xmodmap -e "keycode 238 = F21"
xmodmap -e "keycode 239 = F22"
xmodmap -e "keycode 240 = F23"
xmodmap -e "keycode 241 = F24"
xmodmap -e "keycode 217 = Print"
xmodmap -e "keycode 9 = Escape 3270_Attn"
xmodmap -e "keycode  93 = cent bar"
xmodmap -e "keycode 175 = 3270_Record"
xmodmap -e "keycode 175 ="
xmodmap -e "keycode 247 = 3270_Play"
xmodmap -e "keycode 242 = Super_L"
xmodmap -e "keycode 248 = Multi_key"
xmodmap -e "keycode 243 = 3270_BackTab"
xmodmap -e "keycode 118 = Insert 3270_Duplicate"
xmodmap -e "keycode 112 = Prior 3270_Jump"
xmodmap -e "keycode 117 = Next 3270_Rule"

This results in a keyboard that more or less matches the key caps. For some of the blue symbols, you press the key in combination with shift.

The number pad could do with a little more attention in the realm of X-mapping, and there are a few blue symbols on the main qwerty pad that might be usefully mapped, but this is sufficient for my purposes.

Dec 222009
 

So in the interests of science (ok, I wanted a new toy with a large amount of storage for music), I bought a pre-upgraded iPod 5.5 with a 240Gbyte hard disk in it. Loaded up Rockbox as soon as it arrived with the special version for upgraded iPods and everything was working …

Well … sort of. I could copy most of my music onto it, but nothing with a filename that broke the rules of pure FAT … no long extensions (so no FLAC files!!), no UTF-8 filenames (and “f#a#oo” isn’t quite a catchy a name as “f♯a♯∞”). So I rebuild the filesystem with the standard Linux tool mkfs.vfat

Bad move! Whilst all the files now copied onto the iPod, the Rockbox bootloader was now unable to load the main rockbox binary (“rockbox.ipod”). Seems that Rockbox’s idea of FAT32 on large disks isn’t quite the same as Linux’s version (or to be fair OSX either). So I spend ages hunting around to see how to create an appropriate filesystem on the iPod to allow things to work, without success.

Thus this page.

First of all, connect up the iPod and determine what device it is (mine showed up as /dev/sdh). The command fdisk -l is quite helpful here particularly as we use that next.

Once you find the iPod’s device, use that to display the partition table using fdisk :-

# fdisk /dev/sdh
# fdisk /dev/sdh
Note: sector size is 2048 (not 512)

The number of cylinders for this disk is set to 22506.
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/sdh: 240.1 GB, 240057409536 bytes
84 heads, 62 sectors/track, 22506 cylinders
Units = cylinders of 5208 * 2048 = 10665984 bytes
Disk identifier: 0x20202020

 Device Boot      Start         End      Blocks   Id  System
/dev/sdh1               1          13      128394    0  Empty
Partition 1 does not end on cylinder boundary.
/dev/sdh2              13       22507   234302542    b  W95 FAT32

Command (m for help): q

Here we use the “p” command to list the partition table, and “q” to quit. The key bit of information we are looking for are the number of cylinders, heads and sectors per track (22506, 84, 62). For the number of cylinders, we need to subtract the number of cylinders used by the first partition … or perhaps easier the value of the cylinder that the second partition starts on (13). This gives the values we use for mformat to format the filesystem.

Next we need to create a “drive letter” (!! – why doesn’t mtools allow you to specify a device to work with in the proper Unix fashion?) by editing /etc/mtools.conf and adding a line at the end like “drive z: file=”/dev/sdh2″”.

Finally we need to use mformat to create the filesystem :-

mformat -t 22493 -h 84 -n 62 -S 4 -M 2048 -F -v FATBOX -N deadcafe z:

The “-v” and “-N” options are unnecessary, but at least the “-v” option is kind of handy to allow the iPod to be automatically mounted in an appropriate place. And I usually take every opportunity to assign some funky hex value 🙂

Nov 022009
 

So I quickly install the CD in a virtual machine, login, get delayed by doing something with a passphrase, install the “guest additions”, and reboot. But why doesn’t Ubuntu include the drivers for various different virtual machine environments ? It would certainly make it easier to quickly setup a machine to test the feasibility of switching or upgrading.

One tiny little niggle with the first boot – the passphrase request to “unlock” the encrypted drive (I wanted to say “unencrypt” there but of course it doesn’t actually do that) is a little less than obvious. It should perhaps be a little more “in your face” – a popup. And of course the new Ubuntu boot straight into X might look a little prettier than the previous mechanism, but it isn’t quite “geeky” enough for me (my OSX machines are set to boot in verbose mode to scare those who think the command line is scary). This new startup is supposedly significantly quicker than previous releases; I’m afraid I didn’t notice. Perhaps it is of concern more to others than to me, but I rarely restart my machines – my somewhat less than totally reliable main machine has been up for 7 days, so a faster boot time is not of great significance to me.

I couldn’t seem to find anything to tweak the desktop effects settings. Perhaps not that important, but sort of peculiar. I dare say there’s an addon to do that.

I next dove into “Software Centre” to find a couple of applications that I use, but couldn’t. Admittedly they are somewhat towards the geeky side of things, but they are not that unpopular (zsh and enlightenment). Dropping to a terminal window and they were quickly found using apt-cache. Perhaps the Software Centre intentionally hides things to make the default list of new application choices a little less scary ? Maybe, but it needs an easily found button to say “show more”. Of course the Synaptic package manager can still be found, so this isn’t a real problem although having two ways of installing/removing software could be.

After I installed my favourite window manager (Enlightenment for now), I went on to try setting it up in my usual way with a .xsession file. No luck! It seems that Ubuntu’s version of gdm has accidentally (?) removed this functionality. This is quite a serious problem for those who like to run seriously customised environments. Perhaps not Ubuntu’s major audience, but it seems rather unfortunate to remove this functionality as it will seriously annoy those like me who prefer their own environment.

Going back to the default environment, I take a quick look at Firefox to realise that there is no Flash plugin. A dive into the Software Centre fixes that, although it would have been nice to be taken through a “wizard” when starting Firefox for the first time to suggest installing a number of proprietary extensions (and explain why they are not installed by default). Not that it does not install with a good selection already, but a browser without flash is perhaps not what people are expecting (although there are advantages in not having flash or turning it on only for those pages you want it turned on for).

Browsing through the settings, and I find the theme browser which does not really offer much choice by default – you have to install some additional themes. The choice of backgrounds is fine, although I’m not too sure why the frog was included (I chose the falling coffee). The most obvious improvement here, would be to include a hint on how to include your own photos as a background – quite possibly the first thing that many want to do! At least the Font tab defaults to using a method of rendering suitable for LCD panels (I’m not sure if this is new with the Koala).

In the keyboard preferences, the Layout options are somewhat confusing. Admittedly the number of options here is bound to make it more confusing, and those who choose “Layout Options” are likely to be self-educated to some degree. However it may be worth looking again at how the options are described. Oddly enough the Mouse preferences shows an option to “Show mouse pointer position when Control is pressed” but does not allow you to enable it!

Going through the applications, most (without extensive testing) seem fine. However Empathy (the replacement for the Pidgin instant messaging client) does seem a little on the flaky side with a few “misfeatures” – for instance the “Room” dialog box is a little immature and it is not obvious what you should do with it. Are you supposed to know some sort of “server name” ? Seems a little odd.

This may get added to when I find the time and patience to do more, but I am sure there are plenty of other far more complete looks at Ubuntu 9.10 out there!