RichardNeill.org

Installing Mandriva 2006 (Linux-Mandrake 11.0) on an IBM Thinkpad A22p

Permanent URL: http://richardneill.org/a22p-mdk11-0.php Last updated 2008-07-16

Introduction

This is my page dedicated to Mandrake/Mandriva Linux on an IBM Thinkpad A22p. This version covers Mandrake 11.0 (also known as Mandriva 2006), but there are earlier pages about Mandrake 8.0/8.1 and 9.1. This information has been drawn from many sources: thanks to all of you! Any feedback on this page would be welcome. Copying is permitted: see below.

This Thinkpad is actually very Linux-compatible. Although I haven't documented it here, I've run 8.0,8.1,8.2,9.0,9.1,and 10.2 on it (and Knoppix). Basically, everything works well, therefore, this is partly a quick run through the installer, partly a list of things I think are important/useful to change on a Linux system, and partly a memo-to-self about my preferences for the next install. I also have a desktop system, so there is a lot of general Mandrake information here. Lastly, I've included some useful scripts, binaries and config files. I have denoted commands and files like this.

It is worth mentioning also: Linux-Laptop.net and TuxMobil.org (Linux on laptops), Linux-Thinkpad.org (Linux on Thinkpads, and the mailing list), ThinkWiki, the Linux on Thinkpads webring and the Knoppix bootable Linux demo/rescue CD. This is also a good place to warn about lm-sensors: do not install it, since it can destroy some thinkpads. Lastly, don't forget to subscribe to the security announcement mailing list.

Contents

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This is an IBM A22p, model TA2USUK, with 15" 1600x1200 display, PIII 1 GHz, and CD-RW. The RAM was upgraded from 128 MB to the maximum supported 512 MB. (Crucial RAM is cheaper than IBM and seems fine; 128 MB is rather marginal for intensive use under Linux). Everything works (although I never tested the S-video in/out.) The interesting challenges are: encryption, trackpoint sensitivity, making suspend work reliably and the modem driver.

The hardware maintenance manual for the A22p is here. Spare parts can be purchased from IBM's online parts store, or from laptopbits. Parts are identified by their FRU ("Field Replacement Unit") number, for example, spare trackpoint caps are: 84G6536.

I also purchased a Port Replicator ($10 on eBay), which is extremely useful: it saves frequently plugging/unplugging many cables, and it acts as a stand to tilt the keyboard. Everything works, except the DVI connector. Lastly, the ugly 'Designed for Windows98' sticker was removed, and the top of the lid adorned with a 40mm-high tux.

  1. Download the ISOs (Yes, I joined MandrivaClub). Burn to CD using cdrecord. Test using dd if=/dev/cdrom | md5sum You can also buy the CDs cheaply from for example The Linux Emporium. Sometimes, a perfectly good CD will not verify correctly because of padding. I downloaded the set of 6 CDs available as Mandrake Club Silver Edition, however if you download just the 3 Free GPL CDs, and then add all the urpmi sources, then install non free packages (java,realplayer,flash,acroread) you will end up with the same result.
  2. Read the release notes and the Errata.
  3. Backup everything (especially /home, including hidden files within /home) on an external disk, or over the network (rsync via ssh). Check it using diff -r. It's also worth keeping the old /etc. If there is anything useful in /var, remember to keep that too (eg Postgres databases, html, logfiles, crontab, mailspool). If the IP address is static, write it down and the other network settings. This is true for updates as well as fresh installs.
  4. Power off...take deep breath, get coffee...
  5. In the BIOS, make sure that all the devices are configured to be enabled, and that the hardware clock is set to GMT. Set the boot order to CD-ROM, then HDD. Set the HDD password, but not the poweron password. Set the lid-close button to be inactive, not to suspend (this prevents a race-condition).
  6. Have a copy of Knoppix handy, and also note that the Installer Disk 1 is a recovery CD (especially useful if you destroy the bootloader)

Please note, I am not an authority on this - and I am only documenting what I did. Corrections would be welcome!

Consider: How important is security here? Given that it is a laptop, it might well be stolen, and in this case, the data would be compromised. Is encryption useful? Is it worth the performance penalty and hassle? I decided to do the following, however, you may decide otherwise. Here is a helpful "threat model". The worst thing, of course, is a false sense of security. "Nothing is guaranteed to be safe. Security means adding several layers which makes it more difficult to attack. The more layers you add, the more inconvenience you'll get until it actually stops you of getting any work done. You have to find the right balance looking at how important your data is, how much effort and resources your attacker will/can put into getting at the data, and how much inconvenience you're comfortable with in taking measures against a possible attack."

  1. I set the Hard Disk password in the BIOS. This is fairly impenetrable, (IBM certainly won't get it back for you), but it is probably circumventable by a talented data thief. Don't forget it!! [It also means that the laptop cannot boot up unattended.] I didn't set a BIOS password, since the HDD password is sufficient (and stronger than the BIOS password anyway). From the Linux-thinkpad mailing list:
    "[The Hard Disk password] is pretty secure. The protection is provided by the drive itself: one needs to disassemble the drive, separate the drive platters from its internal IDE controller and replace this controller to get to the data.

    One important thing to know about Thinkpads is that if you also set a poweron password in the BIOS, the harddrive password gets copied to an EPROM on the motherboard. As a consequence, not setting a poweron password and only a harddrive password decreases the risk of an attacker to get to the data."
  2. Most systems (given an attacker with physical access) can be booted up, either using Knoppix, or by pressing Escape while Lilo is starting, and then typing linux single. So the login password alone is no protection at all! Even if CD-ROM boot is prevented by a BIOS password, and Lilo single-user boot is disabled, the Hard disk can still be read by placing it in another machine,
  3. Encrypt: /home, since it contains my data.
  4. Encrypt /var, since it contains all sorts of things: logs, slocate.db, postgres database...etc.
  5. Encrypt swap, because anything could end up there (and in the clear). Swap is the easiest to encrypt, and most transparent, so I'd recommend to encrypt that, even if nothing else.
  6. Not encrypted: / (the root directory), because it's all open source anyway! Furthermore, this is quite a complex operation, especially if trying to install there! And the performance hit would be most significant if the applications were encrypted. Yes, there is a little information which could leak out via /etc, but for me, this isn't important - besides which, my email address is written on the bottom of the laptop!
  7. Not encrypted: /boot, because this would be impossible! [If worried about a trojaned kernel being installed here, boot only off a USB-key, and keep the key in your sight at all times!]
  8. I decided to use losetup rather than dm-crypt, since losetup is more established, and at least partially supported by a (broken) Mandrake rc.sysinit script. dm-crypt might actually work OK with Mandriva 2006, but it certainly didn't when I originally set this up under 10.2.
  9. Using losetup means that suspend-to-disk is dangerous, since the RAM will be in clear on the disk! But I only ever want suspend-to-RAM anyway. dm-crypt would allow cryptographic suspend-to-disk. Also, "newer versions of suspend2 also have native encryption support via the crypto-API of the Linux kernel." [But Mandriva doesn't seem to use suspend2.]
  10. Firewire can be dangerous. IEEE1394 devices can, by design, snoop on the host's memory. This is useful for debugging, but can be considered harmful. The laptop has no inbuilt 1394 device, but a PCMCIA card would be helpfully hotplugged by Mandrake! So prevent the modules from loading.
  11. The implication of the setup which I have chosen is that:
    • When the system is switched off, if someone tries to access the hard disk, we are protected by encryption.
    • When the system has booted up, all the encrypted partitions are mounted. We are now protected by the kernel, the login program, file permissions, and a strong password.
    • When the system is left running, but unattended, xscreensaver is used to lock the display. We now are protected by xscreensaver. (And sshd, if on a network)
  12. Obviously, choose a strong password and passphrases. Also, there are some useful articles on data-hygiene published by The Register, on internet anonymity and data security.
  13. Here are some other encryption resources which may be of interest. Note that losetup is older than dm-crypt.
  14. Other considerations:
    • Can the encrypted home partition be locked without unmounting it? Eg before invoking the screensaver, or suspending, somehow forget the key, without first having to close all the applications and unmount /home. I can't see why this shouldn't be possible, but it would appear to need a kernel modification.
    • Can we trust the login program? Yes, probably (provided the password is good enough). Thus, when the system is running, we are protected by the passwords. The encryption protects against someone with physical access to the machine, who can remove the hard disk (or use a bootable CD).
    • Can we trust xscreensaver to do the locking? Yes, probably, provided that the password is sufficiently strong, and that there are no root logins on the virtual consoles, which xscreensaver cannot protect. Xscreensaver uses PAM, so it is as good as login. Disabling Ctrl-Alt-Backspace would be a good idea. If there were some way to crash X (or xscreensaver) without logging out, this would leave /home exposed.
    • What about the daemons? Could sshd or apache compromise things? Make sure that permissions are not world-readable! What about ~/public_html? Obviously, we need to run a fully up-to-date system, with no known local-root exploits.
    • What about the risk of a dictionary attack on /etc/shadow? Obviously, I use a password which is not a dictionary word! But a really sophisticated attacker could perhaps surreptitiously "borrow" the unattended laptop, copy /etc, run some crack against /etc/shadow, return the laptop, wait for me to log in, then steal it. "A possible improvement is adapting your pam configuration to replace the standard unix authentication (pam_unix.so) with pam_ssh.so (use your ssh passphrase to log in) or pam_usb.so (use a usb-stick to log in)" But obviously, losing a usb-stick is very easily done!
    • Can we use PAM to automate any of this, to reduce the number of times the passphrase needs to by typed. Is there any reason why root password, my user password, and SSH passphrase should be different?
    • Can the SysRQ key do anything bad? It appears not, according to the documentation in /usr/src/linux-xxx/Documentation/sysrq.txt
    • We are still vulnerable to a brute-force attack with sufficient computing power; to theft of the laptop while unlocked; or to theft while locked, but powered on, and with sufficiently clever electronic probing of the motherboard (or via firewire).
    • Newer thinkpads, with 'biometric fingerprint sensors' should not rely on these. The sensors do not reliably discriminate between users, and are very easy to fool. Furthermore, one's fingerprints can easily be retrieved...from the laptop!
    • If any of this is wrong, please tell me!

If you want to have an encrypted system, first initialise the HDD by filling it up with random data. This will destroy any previous information there, so be warned! Either boot knoppix, or run this from the current system, and run:
dd if=/dev/urandom of=/dev/hda bs=1M
This will take about 5 hours for a 32GB disk. /dev/random is better cryptographically, but would take a year!

Now, the install itself. This went fine, with no problems. So just a quick summary:
  1. The new Mandrake installer is very slick, and just works. "expert" mode has gone away. There is a very useful rescue mode on the first CD, in case you mess up the system.
  2. It did prompt me to upgrade from 9.1, which would probably have worked fine. However, I decided to do a full reinstall, and re-partition.
  3. Accept license. Read release notes. British English. UK keyboard.
  4. Security=high (don't choose paranoid - you can make your system almost unusable!). Security admin = rjn (this is the person who gets the email from msec etc).
  5. Mouse = any PS/2 or USB (the default).
  6. Partitions. If you are not using encryption (or just encrypting swap), I would recommend something simple, eg:
    PartitionSizeMount pointFilesystem
    hda17 GB/ReiserFS
    hda5550 MB (slightly larger than RAM)swapswap
    hda61 GB/spareReiserFS
    hda721 GB/homeReiserFS
    However, I decided that I wanted to encrypt /var, and hence the partition scheme is slightly more complex. Diskdrake has an "encryption" option, which doesn't work well. Don't use it - and install everything unencrypted for now. Thus:
    PartitionSizeMount pointFilesystem
    hda1200 MB/bootReiserFS
    hda56.5 GB/ResierFS
    hda6550 MB (slightly larger than RAM)swapswap
    hda71024 MB/varReiserFS
    hda81024 MB/spareReiserFS
    hda920 GB/homeReiserFS
  7. Package Selection: it is usually easier to install a small system, then add urpmi sources, and select more packages once it is done. So I just accepted the default groups.
    NOTE: DO NOT install lm_sensors (it can destroy some thinkpads - see linux-thinkpad.org). Mandrake do not include it by default, and lm_sensors should now safely exit before damaging vulnerable machines, but it's worth making sure. This also means avoiding glms, ksensors, and not running sensors-detect.
  8. Define a root password, a user (rjn) and password.
  9. Put the Lilo bootloader on the MBR (Master Boot Record)
  10. At "Summary", I went through all the config options:
    • Timezone -> London, Hardware Clock = GMT, Use NTP
    • Printers -> configure after install.
    • GUI -> Generic Flat Panel Display, 1600x1200, Rage 128 Mobility, Xorg 6.8.2 with hardware acceleration, 16 bit per pixel.
      Note: It is necessary to choose 16 bit/pixel and not 24 bpp in order to have hardware acceleration working. glxgears gives 787 FPS at 16 bit, but only 158 FPS at 24 bit.
    • Network -> LAN: set eth0 to DHCP. Do NOT assign host name from DHCP address. Do not set "DHCP hostname". Choose start at boot. Get DNS servers from DHCP. Hostname="toffee-pecan.baddiant.org.uk". Zeroconf hostname=blank. Note: Unlike earlier versions, 10.2 will background the DHCP request to allow boot to proceed faster. However, you can also set a timeout.
    • Firewall off all but SSH, and ping.
    • Bootloader -> 5 second delay. Clean /tmp at boot. No need to specify precise RAM size. ACPI is now supported, so allow it. (Previously, I used APM). Add "splash=verbose panic=60" to the bootloader options (respectively: make bootsplash verbose, so that the boot messages are visible; reboot after a kernel panic rather than hang.)
    • Services -> deactivated many of these. In particular, unless you need them, deactivate anything to do with NFS (netfs,nfslock,portmap) and Zeroconf (mdadm, mDNSResponder,nifd). Here is what I am running on my laptop. Note that some of these choices may not suit everyone. [I don't have a printer on the laptop, (no cups); I do web-development (postgresql,httpd), and I have internet connection sharing enabled for use when travelling (dhcpd,squid,named). ACPI is now supported, (although APM works too). I have no bluetooth hardware, and I never change the ultrabay. Irda causes crashes, and anacron causes the disk to thrash (rpmv,msec) for 20 minutes!]
      • These are running: alsa, acpi, acpid, atd, cpufreq, crond, dhcpd, dm, haldaemon, harddrake, hotplug, httpd, keytable, kheader, messagebus, named, network, ntpd, partmon, pcmcia, postfix, postgresql, shorewall, smartd, sound, squid, sshd, syslog, udev, xfs

      • These are not running: anacron, apmd, apmiser, bluetooth, cups, cpufreq, cpufreqd, dund, hidd, iptables, irda, laptop-mode, mDNSResponder, mdadm, netfs, netplugd, nfslock, nifd, oki4daemon, pand, pcscd, rawdevices, ultrabayd, vncserver
  11. Reboot.

The system booted straight up - all seems well. Nevertheless, there is a lot left to do. This being Linux, there is a huge amount that can be configured....
In particular, before trying to do any further setup, I'd recommend configuring sudo, and urpmi and then installing bash-completion.

[1] Quick tests

Some quick tests to check status:
  • check hard disk performance: Is DMA enabled (it should be): hdparm -tT /dev/hda. Test data rate: hdparm -tT /dev/hda [I get 287 MB/s, 19 MB/sec respectively].
  • check memory status: free -m [more info]
  • check disk space: df -h, and what is mounted where: mount
  • is swapenabled? swapon -s
  • check which kernel is running: uname -a
  • check 3D acceleration: glxgears [I get 787 FPS]
  • check which processes are running: top; ps aux | less; chkconfig --list; service --status-all
  • check network: ifconfig -a
  • check for system error messages: dmesg; /var/log/boot.log; /var/log/messages; /var/log/kernel/*

[2] Configuring lilo

The kernel parameters are listed in /usr/src/linux/Documentation/kernel-parameters.txt. I use the following:
  • splash=verbose -> so that the boot-up messages are visible. Mandrake defaults to hiding them with splash=silent. The old way (just text) is splash=none.
  • panic=60 -> so that, if there is a crash, the system will try to reboot after 60 seconds. Useful if unattended. (We could also install the watchdog).
  • acpi=off -> this would be used if we want APM rather than ACPI. To have ACPI, no entry is required.
  • inotify -> so that inotify is enabled, which allows KDE's volume manager to detect changed media (eg CDROMs or USB-keys.)
  • vga=794 -> so that the console uses a much higher resolution, which makes it far more pleasant. (To see which modes are possible, run hwinfo --framebuffer, then convert it using this table.)
Thus, a typical stanza might look like:
image=/boot/vmlinuz-2.6.12-12mdk-i586-up-1GB
        label="2612i586up1GB-12"
        root=/dev/hda5
        initrd=/boot/initrd-2.6.12-12mdk-i586-up-1GB.img
        append="resume=/dev/hda6 splash=verbose panic=60 inotify"
        vga=794
For faster bootup, reduce the value of timeout from 50 to 30. Then, remember to run /sbin/lilo so the changes take effect!

[3] Configuring Modprobe.preload

Add the following to /etc/modprobe.preload so that these modules are automatically loaded on bootup:
pcspkr
e100
The pcspkr module provides the ability to have the PC-speaker/system bell eg Ctrl-G at a console, or gnubeep. [See this bug.]
The e100 module is loaded here to force it to be loaded instead of eepro100 and before pcmcia starts (see the network section for why).
This is to save having to type the password each time I, the only user of this laptop, wish to become root. Add the 'rjn' line to /etc/sudoers under the currently existing 'root' line (where rjn is your login name):
# User privilege specification
root    ALL=(ALL) ALL
rjn     ALL=(ALL) NOPASSWD:ALL
Then add to ~/.bashrc: alias "sud"="sudo su". So, you can now become root by simply typing "sud".

Note: sudo su does not usually set up X authentication, so if you then try to run a GUI application (eg xclock), it fails with the error message: Xlib: connection to ":0.0" refused by server. The solutions are any of:
  • Permit the root user to access your normal xsession: run (as yourself) xhost local:root
  • Invoke the GUI application directly: sudo xclock
  • Use the sux wrapper script instead of su, to transfer the X credentials.

[1] Introduction

Urpmi ("user RPM install") is the Mandriva package manager. It is a delight to use: once configured, simply urpmi PACKAGENAME and it will download and install it for you. However, first you must set up some software sources ("urpmi media"). Virtually every package that you will ever need is available via an urpmi source, and it is important to choose the correct sources! Also, you should never bypass or force RPM. When installing from source, I recommend using checkinstall, so that RPM is always correctly aware of the system status. [There is a graphical interface to urpmi, which is rpmdrake.]

For more urpmi information, see the Advanced uses of Urpmi section.

[2] Systems and Sources

There are 3 possible systems; do not mix and match! These are:
  • Official - this is the "stable" release. Recommended for servers.
  • Devel = Community - this is the slightly more bugfixed and updated system (and is required by some PLF packages). Recommended for desktops.
  • Cooker = Bleeding edge, and usually broken! Recommended only for Mandriva developers.
Official vs Community: "PLF only support the Community branch of Mandriva, which is actually a living version of the official branch, with all updates merged instead of being distributed separately. Moreover, some limited backports are provided, whereas official is absolutly frozen. Using PLF packages with official will often work, but not always."

To set up the urpmi sources, it is possible to use urpmi.setup, but probably easier to visit: Easy Urpmi, or the Mandriva Club Mirror Finder.

Firstly, remove the sources corresponding to the install discs: urpmi.removemedia -a. Then, set up the following sources via EasyUrpmi:
  • Main = the 3-6 CDs you download. (Core distribution).
  • Contrib = packages built by other volunteers - over 2GB of useful stuff, but not officially in the main distribution.
  • PLF = "Penguin Liberation Front" - packages that might cause legal headaches in some countries, mainly multimedia. PLF is split into plf-free and plf-nonfree. [Note: PLF is designed to work with Community, not Official.]
  • Updates = updated packages fixing bugs and security problems. [Only official has an updates source; for devel or cooker, updates are subsumed into the other media.]
If you are a member of the Mandriva Club, you may also wish to add the Club media. I would recommend removing the club media after you have downloaded the desired packages. [Remember: log into MandrivaClub first, and make sure to replace PASSWORD with the actual value.] There are:
  • Club Open source packages = updated packages available to MandrakeClub members. You may wish to pick and choose these rather than adding the urpmi source: if so, browse the mirror with lftp.
  • Club Commercial = non-free, binary packages such as Java and Flash. These are available as RPMS from MandrivaClub; if you prefer, you can download these directly from Sun,Macromedia etc.
You may also wish to add the cooker backports source provided by the excellent Hawkwind at SeerofSouls:
  • 2006 RPMS - updates for many and various packages, built for Mandriva 2006.
  • KDE 3.5 RPMS - packages for KDE 3.5

[3] Applying updates and adding packages

Now, apply the updates, using: urpmi.update updates; urpmi --auto-select. Also, install the latest kernel, from the updates source, using: urpmi kernel-i686-up-4GB-2.6.12.12mdk and then remember to edit lilo.conf and run lilo.

Now, if desired, you can add any other package. I'd recommend adding the following:
gnome-alsamixer, anacron, abiword, antiword, bash-completion, catdoc, checkinstall, dos2unix, faces-penguin, gscanbus, lyx, nc, nano, sane, openssh-clients, unix2dos, mandriva_doc-en, shorewall, units, xfig, X11R6-Contrib.

[4] My Urpmi Configuration

Hopefully, that isn't too confusing! By way of example, these are the urpmi sources I am using:
  • main_community (ftp://anorien.csc.warwick.ac.uk/Mandrakelinux/devel/2006.0/i586/media/main)
  • contrib_community (ftp://anorien.csc.warwick.ac.uk/Mandrakelinux/devel/2006.0/i586/media/contrib)
  • plf-free and plf-nonfree (ftp://ftp.free.fr/pub/Distributions_Linux/plf/mandrake/free/2006.0 and mandrake/non-free/2006.0)
  • SoS-KDE (http://seerofsouls.com/KDE-3.5)
  • mandriva_club [Only temporarily configured, to download Java,Flash,OpenOffice2; then removed]

The Bash shell is extremely versatile, and can be customised by editing ~/.bashrc.

Bash completion (sophisticated tab-completion)

Tab completion is wonderful, and installing the bash-completion package is incredibly useful: it makes tab-completion far more pervasive. For example, it will complete on urpmi packagename; killall processname ; ssh hostname; and it will suggest completions in KDE's "run command" dialog (Alt-F2). Under Mandriva 2006, the installation of bash-completion has changed, and if you already are an existing user on the system, it won't "just work". These are the steps:
  • urpmi bash-completion
  • Pick one of:
    • cp /etc/skel/.bash_completion $HOME
    • . /etc/bash_completion in your ~/.bashrc
    • edit the file: /etc/sysconfig/bash_completion
To test if it is working, create a file and directory with similar prefixes: touch test_file; mkdir test_dir. Then type cd test_[TAB].
If bash-completion is installed, it will know that cd can only apply to a directory, and will complete the command to cd test_dir. Otherwise, it will print both options.

Lastly, bash-completion will occasionally refuse to complete a command which you know is valid. Use Alt-/ to force filename completion.

Optimising tab-completion

Most other distributions which I have tried have tab-completion configured far less-than-optimally. (This usually manifests itself as the question "how do I disable the system bell?")
  • In all distributions , if the word is unambiguous, pressing [Tab] once will complete it.
  • In Mandrake, if the word is ambiguous, pressing [Tab] once will print a list of options. (with no beep).
  • In most other distributions, if the word is ambiguous, pressing [Tab] once will just beep at you. You have to press [Tab] twice to get the completion options. This rapidly gets irritating, and causes lots of beeping!
The secret: edit either /etc/inputrc or ~/.inputrc, and add these lines:
# Show all if ambiguous.
set show-all-if-ambiguous on
Then, the beeps become useful (and much rarer).

More Bash tips

  • Typing 'help' will give a guide to the bash builtins. 'info bash' or 'man bash' are extremely useful; reading the man page in konqueror ('man:/bash') is easier.
  • Here is a useful reference: the Advanced Bash Scripting Guide. (Also, a list of special characters and string functions )
  • Mandrake defines a lot of helpful aliases, such as 'cd..' and 's'. Type 'alias' to list them.
  • Keyboard shortcuts in bash/readline are described in info bash "Command Line Editing" or man readline. There are very many: here are some of the most useful:
    Shortcut key Function
    Ctrl-a,Ctrl-e Move to start,end of line
    Ctrl-b,Ctrl-f Move back/forward one character
    Alt-b,f Move back/forward one word
    TAB Smart completion (within uniqueness) of command or filename
    Alt-/ Force completion on filename (override smart completion).
    Ctrl-u,k Cut ("kill") from cursor to start/end of line
    Ctrl-w,Alt-d Cut from cursor to previous whitespace,end of word
    Ctrl-y Paste ("yank") previous cut text
    Ctrl-_ Undo previous edit
    Ctrl-l Clear screen (except for current line)
    Ctrl-r Reverse-search through history
  • Quoting.
    • Single quoted phrases in bash are literal. Within sinqle quotes, you may never use another single-quote, not even with a preceeding backslash (\'). See QUOTING in the bash manpage
    • Double-quoted phrases in bash treat $, `(backtick), and \(backslash) specially. Double-quoted doublequotes may be escaped by \". Beware of ! characters within interactive shells: echo "Oops!" will cause an error.
    • Conatenation is allowed: TEXT="What's your name?\n"'My name is "Richard"'; echo -e $TEXT
    • Without quoting, filename globbing takes place. *, ? and [...] have special meanings: see PATTERN MATCHING in the manpage.
  • Globbing is the process by which special characters are expanded to match filenames. For example ls *.jpg lists all files ending in .jpg. But consider what happens when there are no matches. By default, bash falls back to a literal '*'. shopt -s failglob makes it throw an error; shopt -s nullglob makes it result in the empty string. All choices are problematic - consider:
    • i=0; for file in *ZZZ; do let i++; done; echo "There are $i files matching '*.ZZZ'" when there are no relevant files. Without failglob/nullglob, this will give the answer '1' when it should be zero. nullglob is best.
    • ls *ZZZ. The default (neither nullglob nor failglob) results in "ls: *ZZZ: No such file or directory". However, with nullglob, it becomes just ls, listing the entire directory.
  • $IFS is the input field separator. By default, it is <space><tab><newline>. Any of these characters are treated as delimiters when tokenising input. For example:
    set `echo "first second"` ; echo "'\$1' is $1 and '\$2' is $2" results in '$1' is first and '$2' is second, whereas
    IFS=':'; set `echo "first second:third"` ; echo "'\$1' is $1 and '\$2' is $2" results in '$1' is first second and '$2' is third.

My .bashrc

Some customisations in .bashrc make it very much more useful. Here are some of the things I have added:
export EDITOR=/usr/bin/nano             #Use nano as the default editor (not vi !)
COMP_SCP_REMOTE=true			#Enable tab-completion for scp on remote hosts.

HISTIGNORE=l:ls:ll:la:cd:pwd		#Don't clog up .bash_history with useless commands<br>

alias nanw="nano -w"                    #Word wrap in nano
alias sud="sudo su"                     #Become root (see /etc/sudoers)
alias grep="grep --color=auto"          #Turn on color in grep
alias l.='ls -d .*'                     #Show ONLY hidden files.
alias lx="ls -X"                        #ls, sort by extension
alias duh="du -h --max-depth=1"         #Total size of this directory
alias x11vnc0="x11vnc -display :0"      #Run x11vnc on the existing X display

					#Konsole tab-name for database session (timpani).
alias timpani='echo -ne "\033]30;DB_timpani \a\033]0;\a"; psql -U timpani'  

#Set up a helpful session name in Konsole, making the tabs much more useful. Include username@hostname for remote logins (where $DISPLAY != :0).
#The first part:  \[\e]30;XXXX\a\] sets the session name to XXXX
#The second part:   \[\e]0;\a\]   sets the window title to "" (to which the session name is then appended anyway)

if test "$DISPLAY"; then
        if [ "$DISPLAY" == ":0"  -o "$DISPLAY" == ":0.0" ];then
                 export PS1=$PS1"\[\e]30;\W/ \a\]\[\e]0;\a\]"
        else
                export PS1=$PS1"\[\e]30;\u@\h:\W/ \a\]\[\e]0;\a\]"
        fi
fi

Root's .bashrc

Here are some snippets from root's .bashrc. In particular, the "root" prompt is in red, and the konsole tab has a '*' in it.
alias urpmiupdate="nice -n 19 urpmi.update updates ; nice -n 19 urpmi --auto-select"

#Bash prompt (the word 'root' is in red)
export PS1="[\[\033[0;31m\]\u\[\033[0m\]@\h \W]# "

#Set up a useful shell name in Konsole. Use * for root, and include hostname for remote logins (where $DISPLAY != :0)
if test "$DISPLAY"; then
        if [ "$DISPLAY" == ":0" -o "$DISPLAY" == ":0.0" ];then
                export PS1=$PS1"\[\e]30;*\W/ \a\]\[\e]0;\a\]"
        else
                export PS1=$PS1"\[\e]30;*\h:\W/ \a\]\[\e]0;\a\]"
        fi
fi

Now that we have a system installed, it is time to encrypt it. It is possible to encrypt partitions on-the-fly, and it is maybe even possible to install to an encrypted disk. But the following is the easy (well, easiest!) way.

Note that you aren't really supposed to put a journalled file system on a loopback device: you may need to use reiserfsck --rebuild-tree if you are unlucky!

[1] Encrypt Swap

Encrypted swap is the easiest thing to set up, and potentially the most useful: since you never know what gets swapped out, you can never be sure what is on the swap file! Try reading it using cat /dev/[swap-partition] | strings and you may be surprised! (If you have *lots* of RAM, you might consider disabling swap altogether). Even better, encrypted swap is all automatic, and you never need to set a password. It adds no significant overhead to the system. See man swapon for more details.

CommandExplanation
su     Become root
init 3     Change to runlevel 3 (non-graphical)
swapoff -a     Turn off swap
dd if=/dev/urandom of=/dev/hda6 bs=1M     Fill up the swap partition with junk (if you didn't already do this to the entire drive)
modprobe cryptoloop     Load the cryptoloop module if necessary
Modify the relevant line in /etc/fstab:
/dev/hda6 swap swap defaults,loop=/dev/loop0,encryption=AES256 0 0
    This tells swapon to use encryption. Unlike the other partitions, it is required to specify a particular loop device /dev/loopX
swapon -av     re-enable swap
swapon -s     Check that swap is enabled
losetup -a     Check that the loopback device is enabled.

In the 2006.0, I find that there is an error message at bootup: "Activating swap: unable to open device /dev/loop0". This arises because the symlink /dev/loop0 -> /dev/loop/0 doesn't get created fast enough. (It's OK on faster machines.) Also, when rebooting after a kernel panic, the loopback device itself doesn't get created, and we need to 'encourage' udev a bit.

The cure is to modify /etc/rc.sysinit to include the 2nd paragraph below:
if egrep -q "[[:space:]]swap[[:space:]].*encryption=" /etc/fstab; then
    modprobe loop 2> /dev/null
    modprobe aes 2> /dev/null
    modprobe cryptoloop 2> /dev/null
fi
# /MiB

#BEGIN EXTRA SECTION
#/dev/loop* should appear as a result of modprobing loop. However, it sometimes takes a while, 
#and if we are rebooting after a crash, it is sometimes necessary to give udev a prod with udevstart.
if [ ! -b /dev/loop0 ] ;then     #If /dev/loop0 not there, sleep 2.
        action "Sleeping for 2 seconds, to allow /dev/loop* to appear: " sleep 2
        if [ ! -b /dev/loop0 ] ;then #If still not there, prod udev and sleep 2.
                action "/dev/loop0 still not ready. Poking udev with sharp stick: " udevstart
                sleep 2
                if [ ! -b /dev/loop0 ] ;then #If *still* not there, we are in trouble.
                        action "Bother! /dev/loop0 still not found - we have a problem. " /bin/false
                fi
        fi
fi
#END EXTRA SECTION

action "Activating swap partitions: " swapon -a -e
rc_splash swap 5

If you wish to undo the encrypted swap (eg to use suspend-to-disk), you will have to re-create a normal swap partition with mkswap: mkswap /dev/hda6.

[2] Encrypt other partitions: /spare, /home and /var. Using losetup

This is the easier way to do it on Mandrake, since the init-scripts sort-of understand. Here is how it works: losetup creates an encrypted loopback device, such that /dev/loopX is unencrypted (and can have a filesystem mounted on it), but connects to a matching hard disk partition (/dev/hdaX) which is encrypted. The first time, losetup will require a passphrase: I use at least 30 characters, and have all 3 partitions with the same passphrase. The mount options in /etc/fstab are loop (use loopback device), encryption=aes256 (type of encryption) and encrypted (used by rc.sysinit to know that it is encrypted). When mounting, if you get an error about a bad superblock, it means you used the wrong passphrase. It is possible to encrypt a partition leaving the data in place, but it is easier to back it up. The partition should be prepared by filling it up with random noise.

[2.1] Encrypt partition /dev/hda8, mounted as /spare:

CommandExplanation
umount /spare     Unmount it, before encrypting.
dd if=/dev/urandom of=/dev/hda8 bs=1M     Fill up the partition with junk (if you didn't already do this to the entire drive)
losetup -Tv -e aes512 /dev/loop1 /dev/hda8     Set up an encrypted loop device. Type the passphrase twice
mkreiserfs /dev/loop1     Put a filesystem on the new device
losetup -d /dev/loop1     Detach the loop device
Modify the relevant line in etc/fstab:
/dev/hda8 /spare reiserfs loop,encryption=aes512,encrypted,notail,noatime 1 2
    Unlike swap, if a particular loop device, such as loop=/dev/loopX is not specified, a spare one will be chosen.
mount /spare     Check you can mount it - and type the passphrase as required. If mount complains about errors, you probably mistyped the passphrase.

[2.2] Encrypt partition /dev/hda9, mounted as /home:

Do exactly the same as above, but substitute /dev/loop2, /dev/hda9. Back up the files in /home (or alternatively, just re-create the user). Thus:

cp -a /home /spare     Back up /home
umount /home     unmount
dd if=/dev/urandom of=/dev/hda9 bs=1M     Fill up the partition with junk (if you didn't already do this to the entire drive)
losetup -Tv -e aes512 /dev/loop2 /dev/hda9     (Note, /dev/loop1 is still in use). Type the passphrase twice
mkreiserfs /dev/loop2     Create filesystem
losetup -d /dev/loop2     Detach loop device
Modify the relevant line in /etc/fstab:
/dev/hda9 /home reiserfs loop,encryption=aes512,encrypted,notail,noatime 1 2
    (The 3 options: loop, encryption=aes512,encrypted are the relevant ones to change)
mount /home     Check you can mount it - and type the passphrase as required.
mv /spare/home/* /home     restore contents of /home
rmdir /spare/home     remove backup directory

[2.3] Encrypt partition /dev/hda7, mounted as /var:

Do exactly the same as above, but substitute /dev/loop3, /dev/hda7. We need to back up /var, and it is also difficult to unmount

init 1     Switch to runlevel 1, so we can unmount /var.
cp -a /var /spare     Back up /var
umount /var     unmount
dd if=/dev/urandom of=/dev/hda7 bs=1M     Fill up the partition with junk (if you didn't already do this to the entire drive)
losetup -Tv -e aes512 /dev/loop3 /dev/hda7     (Note, /dev/loop1,2 are still in use).
mkreiserfs /dev/loop3     Create filesystem
losetup -d /dev/loop3     Detach loop device
Modify the relevant line in /etc/fstab:
/dev/hda7 /var reiserfs loop,encryption=aes512,encrypted,notail,noatime 1 2
   
mount /var     Check you can mount it - and type the passphrase as required.
mv /spare/var/* /var     restore contents of /var
rmdir /spare/var     remove backup directory

[2.4] Make sure that the partitions will mount at bootup.

So far, so good. We've done the hard part, BUT there will be problems when we reboot. When we boot, we want to always mount the encrypted partitions. However the init script /etc/rc.d/rc.sysinit will give only one chance to mount, and if you mistype the passphrase, it will just skip it. This will cause serious difficulties, since the system cannot properly boot without /var, and you cannot start kde without /home.

Edit /etc/sysconfig/autofsck and change the line to: AUTOFSCK_CRYPTO_TIMEOUT=600.
This should mean that instead of timing out after 15 seconds, the computer will wait 10 minutes for a user to enter a passphrase before it continues to boot. However, this setting only applies in the case where the filesystem is unclean, and the normal setting is hardcoded in rc.sysinit. (!)

Back up rc.sysinit: cp /etc/rc.d/rc.sysinit /rc.d/rc.sysinit.OLD. Now, edit it...
  • [2.4.1] Fix the timeout for mounting encrypted filesystems on boot-up. It should wait a long time.
    Edit the line just above the comment: #Mounting Encrypted filesystem
    and change the timeout to 600. The correct line reads:
    [[ -z $AUTOFSCK_CRYPTO_TIMEOUT ]] && AUTOFSCK_CRYPTO_TIMEOUT=600
  • [2.4.2] Fix rc.sysinit so that, if you get the passphrase wrong, it asks you again...and again (10 times).
    Edit the section which begins: #Mounting Encrypted filesystem

    Replace this part of the script:
    echo "We have discovered Encrypted filesystems, do you want to mount them now ?"
    MSG=`gprintf "Press Y within %%d seconds to mount your encrypted filesystems..."`
    KEYS=`gprintf "yY"`
    if /sbin/getkey -c $AUTOFSCK_CRYPTO_TIMEOUT -m "$MSG" "$KEYS"; then
    	echo -e '\n'
    	for i in ${encrypted};do
    		echo -n "${i} "; mount ${i}
    	done
    else
    	echo -e '\n'
    fi

    with this new version:
    echo "We have discovered Encrypted filesystems, do you want to mount them now ?"
    MSG=`gprintf "Press Y within %%d seconds to mount your encrypted filesystems..."`
    KEYS=`gprintf "yY"`
    if /sbin/getkey -c $AUTOFSCK_CRYPTO_TIMEOUT -m "$MSG" "$KEYS"; then
    	echo -e '\n'
    
    	#We *really* don't want to boot up without this mounting successfully, so give
    	#10 chances for the user to type the passphrase.  If there is more than one
    	#encrypted partition, try the same passphrase before making the user re-type it.
    
    	unset crypto_passphrase
    	for i in ${encrypted}; do
    		failcount=0
    		while [ $failcount -lt 10 ]  ;do
    			if [ -z "$crypto_passphrase" ];then
    				read -s -p "Enter passphrase for encrypted partition(s) ${i}: " crypto_passphrase
    				echo -e '\n'
    			else
    				echo "Trying the same passphrase for encrypted partition ${i}"
    			fi
    			echo "$crypto_passphrase" | mount -p0 ${i} ; result=$?
    			if [ $result == 0 ];then
    				echo "Successfully mounted encrypted partition ${i}"
    				break
    			else
    				let failcount++
    				echo "Failed to mount ${i}; used $failcount attempt(s) out of 10 allowed."
    			fi
    			unset crypto_passphrase
    		done
    	done
    	unset crypto_passphrase
    
    	else
    	echo -e '\n'
    fi
  • [2.4.3] Fix the section beginning with: Check loopback filesystems, so that it doesn't check filesystems which are both loopback AND encrypted.
    It should read:
    # (pixel) Check loopback filesystems
    	if [ ! -f /fastboot ]; then
    		modprobe loop
    		gprintf "Checking loopback filesystems"
    		#Fsck -T -R -A -a -t opts=loop $fsckoptions
    		Fsck -T -R -A -a -t opts=loop,noopts=encrypted $fsckoptions
    	fi
  • [2.4.4] Side effect: service udev status is untruthful
    udev is started very early by rc.sysinit, before /var is mounted. service udev start tries to save the status by touching /var/lock/subsys/udev. This failure is harmless, but it will mean that service udev status wrongly claims that udev is stopped when it isn't. To check the truth, use pgrep udevd instead. If desired, add this to rc.sysinit immediately after mounting /var (in section 2.4.2 above):
    #Udev has already been started, but the lockfile hasn't been created, because /var wasn't mounted at that time.
    	[[ -d /var/lock/subsys/ ]] && pgrep udevd >/dev/null 2>&1 && touch /var/lock/subsys/udev 2>/dev/null

[3] Other considerations

Set the hard disk password in the BIOS. See above.

Firewire modules could be harmful. Prevent them from being loaded (run /bin/true instead of installing the module) by adding this to /etc/modprobe.conf:
#We don't want to risk host memory snooping. Kill off firewire.
install raw1394 /bin/true
install ieee1394  /bin/true
install ohci1394 /bin/true

[4] Conclusions:

  • This now works. Test it by comparing the result of cat /dev/hda9 | strings with what you would usually see. It is gobbledegook!
  • Don't use diskdrake to set up encryption: it won't work, and it won't allow you to encrypt /var anyway.
  • As a consequence of /var being on a separate partition, and the need not to waste disk space, postgresql may need to live in /home rather than /var/lib/pgsql/.
  • Remember to lock the screen if you use a screensaver!
  • See note below on suspend to RAM.
  • Keep a copy of your new /etc/rc.d/rc.sysinit, because if you upgrade or update with urpmi, it will be overwritten by the defaults. In order to prevent this occuring, add this to /etc/urpmi/skip.list:
    #Keep modified rc.sysinit for mounting encrypted partitions at boot.
    initscripts

[5] An aside on dm-crypt/cryptsetup

Actually, dm-crypt is the most promising way, but it involves too much fighting with Mandrake's init-scripts. Also, diskdrake doesn't understand, and I would guess that drakupdate_fstab won't. There is no need to use it (loop-AES is fine), but since I attempted it, here are some brief notes.

Here is how to Encrypt an existing device using the device-mapper.
init 3    
umount /home    
modprobe dm-crypt    
cryptsetup -yv -c aes -s 256 create hda9-aes /dev/hda9     #hda9 = /home. Passphrase = usually 256 = max key size.
dd if=/dev/hda9 of=/dev/mapper/hda9-aes bs=64k     #this should encrypt the data in place.
reiserfsck /dev/mapper/hda9-aes     #check the filesystem.
Modify /etc/fstab:
/dev/mapper/hda9-aes /home reiserfs notail,noatime 1 2
   
Create/edit /etc/crypttab and add the line:
hda9-aes /dev/hda9
   
mount /home     #It works - but it won't work on reboot yet.

To make it automatically mount on reboot, we need to get the cryptdisks init script. Download it from here, save in /etc/init.d/ with mode 700, and comment out the line which reads "set -x".
ln -s usr/bin/cryptsetup /sbin/cryptsetup (since the Mandrake package puts cryptsetup in usr/bin and the script expects it in /sbin).

Save a copy of /etc/rc.d/rc.sysinit, then edit it. Just after the line: service udev start, put:
#Start the device-mapper for the encrypted partitions using dm-crypt.
#Prompt for the passphrases as required.
#Do NOT boot until the correct passphrases have been supplied.
modprobe dm-crypt >/dev/null 2>&1
service cryptdisks start

This will work, provided that we fix the cryptdisks script so that it keeps prompting for a passphrase if the wrong one is entered. It might be possible to make udev do this. However, cryptsetup create returns 0, whether or not it succeeded! This makes it hard to distinguish success from failure in a script!

Note that, unlike losetup, umounting a mapped-device does not cause the encryption key to be forgotten. This may, or may not, be a good thing. (You can forget the key with cryptsetup remove).

Most of this works just fine as installed. But, we can do better. Note: to make a change take effect, it is necessary to restart X. Logging out is not sufficient (if using kdm). Restart the display manager from the console with service dm restart.

[0] Upgrading the version of Xorg to 6.9.0

When Mandriva 2006 was released, an unstable version of xorg was used: xorg-cvs20050915. This basically works, but EmulatedScroll didn't work quote properly. Since 6.9.0 is now out (as of December 2005), and SeerofSouls have provided a cooker backport, it is worth installing! UPDATE: (April 2006): Xorg 6.9 is now in the mandriva community main urpmi source, so just use urpmi.
  1. Find out which xorg packages are installed: rpm -qa | grep -E 'xorg|X11R6'. I had the following:
    xorg-x11-6.9-1.cvs20050915.2mdk xorg-x11-server-6.9-1.cvs20050915.2mdk libxorg-x11-6.9-1.cvs20050915.2mdk libxorg-x11-devel-6.9-1.cvs20050915.2mdk xorg-x11-xfs-6.9-1.cvs20050915.2mdk xorg-x11-100dpi-fonts-6.9-1.cvs20050915.2mdk xorg-x11-75dpi-fonts-6.9-1.cvs20050915.2mdk xorg-x11-xauth-6.9-1.cvs20050915.2mdk xorg-x11-Xprt-6.9-1.cvs20050915.2mdk X11R6-contrib-6.9-1.cvs20050915.2mdk.i586
  2. Download these from http://seerofsouls.com/RPMS-2006/. I didn't set this as an urpmi source because I don't want to pull in all the upgrades from here.
  3. Install the packages with urpmi:
    urpmi ./xorg-x11-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-server-6.9.0-1.2006.SoS.i586.rpm ./libxorg-x11-6.9.0-1.2006.SoS.i586.rpm ./libxorg-x11-devel-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-xfs-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-100dpi-fonts-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-75dpi-fonts-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-xauth-6.9.0-1.2006.SoS.i586.rpm ./xorg-x11-Xprt-6.9.0-1.2006.SoS.i586.rpm ./X11R6-contrib-6.9.0-1.2006.SoS.i586.rpm
  4. Get the updated packages from the community mirror. urpmi.update -a; urpmi --auto-select
  5. Log out. Then restart X: service dm stop; service xfs restart; service dm start

[1] Graphics Driver and 3D

The graphics card is an "ATI Rage 128 Mobility". This used to use the r128 driver. But now, use the ati driver. [This is correctly detected by Mandriva, and the driver is both free and stable]. In case of difficulty, the vesa driver works universally.

3D acceleration just works on this ThinkPad under Mandrake, without any need to install binary drivers from ATI. [ATI drivers only started being binary-only (ugh!) for 3D in their later cards]. However, it is necessary to set the graphics to 16 bit colour, as there is insufficient memory for DRI at 24 bit color. You can test 3D acceleration by running glxgears: I get about 780 frames/sec at 16-bit. The performance is good enough to enjoy tuxracer, or helios. [In case of 3D problems, see below.]

Various graphics modes (resolutions) are available: by default there are: 1600x1200, 1280x1024, 800x600 and 640x480. To switch between these, (eg to play tuxracer, or to use a projector), use xrandr or xvidtune.
  • xrandr is invoked: xrandr -s [NUMBER] and allows you to re-size the entire desktop. (xrandr is "X rotate and resize")
  • krandrtray is invoked: krandrtray and is a KDE system-tray GUI for xrandr.
  • xvidtune is invoked: xvidtune -next and changes the "viewport" onto the desktop. For example, an 800x600 viewport which can be panned around on top of a 1600x1200 desktop.
[In Mandrake 9.1, it was necessary to increase the HorizSync and VertRefresh ranges in xorg.conf, but this is no longer requred. The defaults of 31.5-90 and 60 are fine.]

The resolution at the virtual terminals may be increased by using vga=794.

Aside for X22 laptop: install driconf, and run driconf as normal user. (No need to restart X afterwards). This allows you to enable HyperZ which improves glxgears performance from 400fps to 970fps.
[This option isn't relevant for the A22p.]

[2] External Display

The external display is normally a copy of the LCD (although it can be used as a dual-head setup - I've seen this in W98, and believe that it can be done using Xinerama). The BIOS uses Fn-F7 to cycle between {Internal LCD only, External CRT/Projector only, Both}, and it takes about 3 seconds for the display to initialise.

However, most projectors won't work at 1600x1200. In order to guarantee success:
  1. Make sure that the mode (such as 1024x768 or 800x600) is working on the internal LCD.
  2. Plug in the projector, and use Fn-F7. If both LCD + Projector are enabled, then with some projectors, there may be problems with timing errors. (The symptoms are: Distortion/Flickering; LCD monitor may complain about timing frequencies; Projector may fail to display anything, or mis-sync giving a "sliced" image). If so, use Fn-F7 again to have only the projector: of course, this means that there is no 'Autocue', so have a printout of the slides available!
  3. Use xrandr -s 800x600 to resize the desktop as necessary to fit onto the projector.
  4. Give the presentation. NB: practice in advance; text not too small; test projector in advance; have printout of notes; check timing; speak slowly; be calm.

Aside for X22 laptop: ibm_acpi doesn't properly co-exist with Fn-F7. To enable Fn-F7 to switch displays between LCD/CRT/Both, it is necessary to enable BiosHotKeys in the Device section of xorg.conf:
Section "Device"
   ...
   Option "BiosHotKeys" "on"      #Enable Fn-F7 for switching between CRT,LCD,Both.
EndSection

[3] S-video ports

The A22p has S-video input and output ports. I've never had occasion to use them, but atitvout -f may help.

[4] Font Sizes

The fonts are too small. This is because most monitors are 75 dpi, whereas this one is actually a wonderful 133 dpi. Three alterations are needed:
  • Add the DisplaySize line to /etc/X11/xorg.conf:
    Section "Monitor"
        Identifier "monitor1"
        VendorName "Generic"
        ModelName "Flat Panel 1600x1200"
        HorizSync 31.5-90
        VertRefresh 60
        DisplaySize 304 228     # <-- Added by rjn to sort out tiny fonts - these are width, height in mm
        ....
    EndSection
  • Change the dpi line in /etc/X11/Xresources to:
    Xft.dpi: 133
    where 133 is the value of xdpyinfo | grep resolution.
  • Unfortunately, the gnome-font-properties program (which configures GTK applications) does not respect the value from the X-server. Start gnome-font-properties, click 'details', and manually change the resolution from 96 dpi to 133 dpi.
Then, logout and re-start X. The fonts should all look better (and larger). The fonts faces themselves (and anti-aliasing) are described below.

[5] Mouse

[5.1] Mouse device

As of kernel 2.6, instead of using separate devices for each mouse, the kernel merges them together into /dev/input/mice. This is fine, provided that you are not trying to do anything too clever (such as having a graphics tablet). However, we can, if desired, specify the correct mouse. This will be one of /dev/input/mouseX but the value of X may vary depending on what is plugged in. The solution is to use udev to create a symlink to the correct device:
  1. We can discover which mouse we want by doing cat < /dev/input/mouseX and wiggling the mouse. In this case, it happens to be /dev/input/mouse0
  2. We want to create a udev rule to symlink /dev/input/trackpoint -> /dev/input/mouse0
  3. Find out about the device with udevinfo: udevinfo -a -p /sys/class/input/mouse0
  4. Add the following to /etc/udev/rules.d/10-local.rules:
    #Symlink the relevant /dev/input/mouseX by /dev/input/trackpoint:
    BUS=="serio", kernel=="mouse*", SYSFS{description}=="i8042 Aux Port", NAME="input/%k", SYMLINK="input/trackpoint"
  5. Modify xorg.conf to refer to /dev/input/trackpoint rather than /dev/input/mice
  6. Reboot (since the PS/2 port doesn't like hotplugging)
This works. Note the following:
  • If multiple mice are now needed, the ServerLayout section should have one "CorePointer" and the others to "SendCoreEvents".
  • For the A22p, it is also valid to use /dev/psaux for the trackpoint device.
  • Note: we don't want /dev/input/eventX nor do we want /dev/input/tsX, since these can cause subtle errors.
  • If the Xserver fails to start, Mdk will 'helpfully' re-detect the mice, and over-write your carefully constructed file. So keep a copy!

[5.2] Mouse buttons

The buttons on the Thinkpad A22p are exceptionally well-arranged, and the resulting behaviour is extremely flexible:
  • Button 1 = ordinary Left-click
  • Button 3 = ordinary Right-click
  • Button "X" = ordinary Middle-click (i.e. paste.) [Button X is achieved by pressing btn1 and btn3 together]
  • Button 2 + move trackpoint = Vertical AND Horizontal scroll
Here is a diagram of the layout:
trackpoint button layout
To achieve this, we need the following:
  • Emulate3Buttons on: this means that (Button 1 + Button 3) => emulated middle button.
  • EmulateWheel on: this means that Button 2 + move mouse => emulated scroll wheel
  • EmulateWheelTimeout = 0: this means that Button 2 does not generate middle-clicks. Only Button X does.
  • YAxisMapping = "6 7": Vertical scroll generates a series of button 4,5 events, which the application treats as a vertical scroll.
  • XAxisMapping = "4 5": Horizontall scroll generates a series of button 6,7 events, which most applications treat as a horizontal scroll.
  • No, that's not a mistake: it cancels another bug, namely the existence of /etc/X11/xinit.d/mouse_buttons which swaps buttons 4<=>6 and 5<=>7
Notes:
  • Horizontal scrolling is misinterpreted as forward/back in Mozilla. See below for fix.
  • Newer Thinkpads have 3 buttons in a row. As of Xorg-6.9, they can use EmulateWheelTimeout, to allow Button 2 to be *both* scroll and middle-click. This works extremely well, except for a few applications (xfig,pcb) which use middle-button drag, so cannot coexist with EmulateWheel. [For older versions of X, see here for alternatives.]
  • The mouse options are documented in man (4) mouse. [But there is sometimes another mouse manual page of the same name documenting the electronic protocol for mice. To get the right man page, use: man /usr/X11R6/man/man4/mouse.4x.bz2]
  • For testing, use xev to identify button presses and xmodmap -pp to show the button mapping.
Note, before upgrading xorg to 6.9.0 as above, the following things were different:
  • The X and Y axes were switched (i.e Option "YAxisMapping" "4 5" Option "XAxisMapping" "6 7") because /etc/X11/xinit.d/mouse_buttons didn't work.
  • EmulateWheelTimeout had no effect. It was stuck on the default 200ms.
  • The ZAxis mapping to some non-existent buttons was needed.

[5.3] Cursor Theme

The cursor theme can be selected by running choose_cursor or from kcontrol->Peripherals->Mouse. I like the crystal cursors theme.

[5.4] xorg.conf (mouse)

Here is the mouse section of my xorg.conf:
Section "InputDevice"

#Mandrake's defaults.
#    Identifier "Mouse1"
#    Driver "mouse"
#    Option "Protocol" "ExplorerPS/2"
#    Option "Device" "/dev/mouse"		#symlink to /dev/input/mice
#    Option "ZAxisMapping" "6 7"

#My settings
    Identifier "Mouse1"
    Driver "mouse"
    Option "Protocol" "PS/2"
    #Option "Device" "/dev/psaux"
    Option "Device" "/dev/input/trackpoint"    #with udev symlink

    Option "Emulate3Buttons" "on"       #Button 1+3 =>t; emulated middle button
    Option "Emulate3Timeout" "50"
    Option "EmulateWheel" "on"          #Button 2 =>; emulated scroll wheel.
    Option "EmulateWheelButton" "2"

    Option "EmulateWheelTimeout" "0"    #If button 2 is pressed for less than this time, then the original button-2 press will pass
                                        #through. Otherwise, we get emulated scroll. Set to 0 to disable. [Default timeout: 200]

    Option "YAxisMapping" "6 7"         #EmulatedWheel vertical/horizontal pointer motion causes fake button 4,5 or 6,7 presses.
    Option "XAxisMapping" "4 5"         #Map these fake presses to vertical and horizontal scroll respectively.
    #Option "ZAxisMapping" "10 11"      #Previously necessary to map this out of the way, to prevent the default (6,7) breaking emulated scroll.
                                        #Note: there is a stupid bug: /etc/X11/xinit.d/mouse_buttons swaps 4<=>6 and 5<=>7
EndSection

[6] Trackpoint sensitivity

The trackpoint can be set to have a very light touch, which I prefer. The old way, using the excellent tp4d is described here, but it doesn't work with Mandriva 2006, preferring a 2.4 kernel with apm and XFree86. There is now a driver in the kernel, but it requires either a patch and recompile, or a kernel 2.6.14 or later. See below for the kernel upgrade.

Once the kernel has been upgraded to ≥ 2.6.14, the trackpoint can be configured by echoing values (from 0-255, without a trailing newline) into the appropriate file in /sys. Eg: echo -n 255 > /sys/devices/platform/i8042/serio0/sensitivity. Once adjusted to taste, add to ~/.kde/Autostart/kde-startup.sh:
#Set trackpoint sensitivity to highest.
#Requires kernel >= 2.6.14
if [ -f /sys/devices/platform/i8042/serio0/sensitivity ];then
        echo "Making trackpoint more sensitive..."
        sudo sh -c "echo -n 255 > /sys/devices/platform/i8042/serio0/sensitivity"   #Makes it a very light touch. Default: 128
        sudo sh -c "echo -n 100 > /sys/devices/platform/i8042/serio0/speed"         #Not much effect.
        sudo sh -c "echo -n 3 > /sys/devices/platform/i8042/serio0/inertia"         #Negative inertia. Default: 6
else
        echo "Cannot adjust trackpoint; /sys/devices/platform/i8042/serio0/sensitivity not found"
fi

The result is a very light sensitivity for the trackpoint. Note: don't rest your finger on the trackpoint; if it starts to "drift", take your finger off it for a second to allow it to re-calibrate; this is normal behaviour, especially at high sensitivity. "Negative inertia" is explained by IBM.

Lastly, set up the Xorg mouse acceleration in kcontrol->Peripherals->Mouse->Advanced. I use Pointer acceleration=2.0x; Pointer threshold = 4 pixels; Mouse wheel scrolls by = 5 lines.

[7] Keyboard

CAPS-LOCK is evil! It always seems to lurk in waiting on top of the tab key! Furthermore, it is the correct, and natural position for the Control Key.
  • Either use xmodmap, by including this in ~/.kde/Autostart/kde-startup.sh:
    #Get rid of Caps Lock and make it into an additional Control Key.
    xmodmap -e "remove Lock = Caps_Lock" \
            -e "keysym Caps_Lock = Control_L"    \
            -e "add Control = Control_L"
  • Or: use the KDE control center: Accessibility->Keyboard Layout->Xkb Options->Make CapsLock an additonal Control

Special and Accented Characters can be entered using the AltGr key. For example, the μ symbol is entered with AltGr-M. To get accented characters, such as é ç ö use AltGr and one of ;'#[] followed by the character to accent. (Alt-Gr is 'sticky' in this context.)

Ctrl-Alt-[Del|Backspace|Esc] are used to respectively reboot,restart X,kill an application. KDE now traps Ctrl-Alt-Del, so it won't instantly reboot the machine. But Ctrl-Alt-Backspace will instantly kill the X-server. This is dangerous (especially if you use sticky keys!). So, uncomment this line in the "ServerFlags" section of /etc/X11/xorg.conf:
DontZap # disable <Crtl><Alt><BS> (server abort)
Ctrl-Alt-Esc is occasionally useful: it's a shortcut for xkill.

There are quite a few modifier keys used by X, and listed in kcontrol->Keyboard Layout->Xkb Options. Here is a brief summary:
  • Meta is (roughly) Emacs-speak for Alt. Sun keyboards have Meta, whereas PC keyboards have Alt.
  • AltGr (Right_Alt) is AlternateGraphic for other characters such as μ, which is entered as AltGr + m.
  • Compose is an alternative way to get composite characters. Eg © is entered with the sequence Compose, o, c. However, (unless using Unicode), it only duplicates the functionality of AltGr and isn't really required.
  • Super is often mapped to the Windows-key [which isn't present on ThinkPads], and is usually used for extra Window-manager functions and custom global program-shortcuts.
  • Hyper is also sometimes, but uncommonly used. It may be mapped to the Menu key [not present on ThinkPads].
  • Mod1 - Mod4 are the internal names used by the X-server for the modifiers: up to 4 are allowed. Usually, Mod1 = Alt/Meta; Mod2 = NumLock; Mod3 = AltGr (= KDE 3rd level), and Mod4 is free.
  • Space Cadet Keyboards have all of the above, and can enter 8000 characters! Of course, this leads more to parody than to usabilty!

Note that many Linux programs still only understand ASCII (7-bit, 128 characters max, see man ascii), or if you are lucky, they understand one of the extended upper-half character sets such as Latin-1 (8-bit, 256 characters). The right way to do it is Unicode with UTF-8.

See below to fix the GTK keyboard shortcuts.

[8] Miscellaneous

Here are a few random snippets of information:
  • Fn-F7 switches between LCD, LCD+CRT, CRT. But if you are in a virtual console, the LCD is blank in LCD+CRT mode. Under X, the LCD works as expected.
  • Switch on screen expansion in the BIOS. Otherwise, 800x600 will only use the central quarter of the screen!
  • LCDs look horrible at non-native resolution. But it's much better for games since it reduces the CPU-load, and allows a higher frame-rate. Eg tux-racer at 640x480.
  • There was (in 9.1) a bug in the r128 driver which caused occasional lockups with 3D GL things. This appears to have been fixed, but for reference, here is the information.
  • The xev (XEvent) program is very useful to see what is going on - it prints keycodes/keysyms/button-press diagnostics to the screen.
  • xmodmap allows you to change particular keyboard and mouse-button mappings.
  • setxkbmap gb allows you to set default keyboard mappings. Useful if you did something stupid with xmodmap!
  • xbindkeys allows you to define key-combinations to launch programs.
  • xclip copies and pastes from stdin/out to/from the clipboard.
  • xmacro lets scripts generate key/mouse events. (eg: echo -e "KeyStr Z\n" | xmacroplay :0)
  • For the PC-speaker, or Bell see sound.

[9] Mouse Emulation

Mouse emulation in X/KDE works as follows. The keys below refer to the numeric keypad, so this is really more relevant to desktop machines.
  • Shift-Numlock: turn mouse emulation on or off.
  • 82,46,7913: move mouse pointer up,down,left,right,diagonally.
  • 5: press the mouse button.
  • ÷, ×, : select which mouse button is emulated by pressing 5 (respectively: left,middle,right).
  • +, 0: double-click, click-and-drag

[10] xorg.conf

Here is my xorg.conf.

Note 1: when restarting the X-server, it is necessary to restart the dm service. Logging out is insufficient.
Note 2: Make sure to keep a copy of xorg.conf, since Mandriva "helpfully" re-writes it whenever anything goes wrong.

[11] Aside: EmulateWheelTimeout for X- and T- series

In the recent updates for Xorg, the EmulateWheelTimeout function has temporarily broken. This is irrelevant on the A-series, but of vital importance for users of T- and -X series thinkpads which have 3 buttons in a row. For these machines, we have to use EmulateWheelTimeout in order to have both scroll and middle-click functionality. Unfortunately, although it has been fixed in xorg, the Mandriva packages have not included the patch. This means compiling it directly. To do so, use rpmbuild.
  1. Get the latest xorg .src.rpm from the SRPMS/ directory on the mirrors. I used the one from SeerOfSouls: xorg-x11-6.9.0-11.1.20060.SoS.src.rpm.
  2. Install with rpm -i.
  3. Get this patch (attached to comment #8 on the xorg Bugzilla).
  4. Apply it to the source:
    
    cd /usr/src/RPM/SOURCES/
    mkdir TMP; cp  X11R6.9.0-src.tar.bz2 TMP/; cd TMP
    tar xvzf X11R6.9.0-src.tar.bz2
    cd xc/programs/Xserver
    patch --verbose -p0 < /home/rjn/xorg-hack/mousepatch.4318.patch
    cd ../../..
    tar cvfz X11R6.9.0-src.tar.bz2  xc
    mv  cvfz X11R6.9.0-src.tar.bz2 .. ; cd ..
    
  5. Now build the RPM: cd /usr/src/RPM/SPECS; rpmbuild -bb xorg-x11.spec
  6. Finally, the RPMS will be in /usr/src/RPM/RPMS/i586: install the packages as desired.
  7. Now, clean up or there will be over a GB of wasted disk space! When the rpm tool installs a .src.rpm, it merely unpacks its source into the /usr/src/RPM/SOURCES directory. Thereafter, it isn't listed by rpm -qa, and cannot be removed with rpm -e. So, some judicious use of rm -rf in the directories /usr/src/RPM/SOURCES and /usr/src/RPM/BUILD is required.

[1] Font sizes

First, sort out the font-sizes by configuring X correctly: see above. This is necessary, since the 1600x1200 screen has a much higher DPI than normal.

[2] Font Types (bitmap,truetype,antialiased,hinted) - Introduction

De-uglification of the fonts is quite easy to do (examples), but fairly long to explain. Here is my "short" summary....
There are several types of fonts:
  • Bitmap fonts. (75dpi, 100dpi). These are the old-style X fonts, and cannot be scaled. They also cannot be printed. However, they look excellent on screen, iff they are displayed at their native size. Only certain point-sizes are available, and these fonts cannot be anti-aliased. (Eg Helvetica 8,9,13pt look excellent; 11pt looks poor, 10,12pt are unavailable)
  • True-type (scalable) fonts. These fonts are the "modern", resizable ones, which look curvy. The outlines are generated from vectors, and mapped onto a pixel-grid. However, how exactly should the fonts be scaled to match the pixels?
    • Scale, but don't anti-alias. Each pixel is either black or white. This means that the font is sharp, and easy to focus on, but the coarse pixellation usually results in a horrid, "spidery" effect with jagged outlines. This is the well-known "bad Arial fonts on Linux" problem.
    • Scale and anti-alias. "Fudge" the curves by setting the intermediate pixels to varying shades of grey. This blurs the edges of the font, creating a smooth outline which is (on average) faithful to the original vector. For very large fonts (in headlines), and fonts used in images, it looks good. But for normal text, it is a matter of taste. Some people like the smooth edges, but I personally find them blurry, and "out of focus" - and they give me eye strain! (It's not quite so bad on this wonderful 133dpi monitor of the ThinkPad, but dreadful anywhere else). Sub-pixel rendering is a possible solution: it uses the 3 coloured pixels of the LCD to triple the horizontal resolution of the anti-aliasing. But the result is colour-fringing of the fonts. If you look at the result using xmag/kmag, you will see what I mean! However, some people do really like this smoothing effect. The Bitstream Vera (or DejaVu) fonts are the best for this.
    • Use properly "Hinted" fonts and don't anti-alias. Hinting means that when the font is scaled, instead of keeping its shape perfectly the same, it is carefully distorted to fit better over the pixels. The result is that the font face looks slightly different, but it is always sharp, and free from ugly artifacts. (For example, the letter "e" sacrifices its "Times-New-Roman-nature" in favour of clarity.) These correctly hinted fonts do not need anti-aliasing (and anti-aliasing often makes them worse at small sizes). The Microsoft fonts are best for this. [For interest, here's a comparison of Microsoft's and Apple's different approaches to smoothing.]
    • Lastly, when the font is very large (eg > 15 pt or used in an image), anti-aliasing makes the edges less jagged, without harming readability.
Here are some images of the different fonts. Try enlarging it with kmag to see the details. More examples are here (scroll down).
Bitmapped:
(clear, but un-scaleable)
bitmap fonts
True Type, non-antialiased:
("spidery")
spidery fonts
True Type, antialiased:
(correct average shape,
but blurred)
antialiased fonts
True Type, hinted:
(slightly distorted shape,
but it is clear)
optimised fonts
TTF, hinted, antialiased:
(not quite so good)
hinted antialiased fonts
You've probably guessed that this means I like the hinted, non-anti-aliased fonts. The snags are that most of the Linux fonts are not well hinted, and that the bytecode interpreter (for interpreting hinting information) is covered by an evil software patent. The Mandriva packages use the autohinter, which works adequately with the Bitstream fonts, but very badly with the MS fonts. The PLF packages use the bytecode-interpreter which works very well with the MS fonts, but not with the Bitstream fonts! Furthermore, many fonts look better at certain sizes than at others. This means:
  • Install the Microsoft corefonts (which are free-as-in-beer). These are very well hinted.
  • Install the plf version of libfreetype6.
  • Set up the applications to use the new fonts.
  • No half-measures: a compromise will be much worse than either extreme!

[3] Configuring Freetype, installing well-hinted fonts

So, actually doing it:
  1. Take a screenshot of how things look now (with ksnapshot) for later comparison.
  2. Install the Microsoft Core Fonts. Before I wiped out Win98, I kept a tarball of C:\Windows\fonts\. Install the .ttf files, (but not the .fon files) using either the Mandrake Font Installer (in Mandrake Control Center), or KDE's font installer (KDE->kcontrol->System->Font Installer). Alternatively, there are the Microsoft webfonts which are free (as in beer), which can be downloaded from sourceforge.
  3. Installing a version of libfreetype with support for the Bytecode interpreter (hinting):
    1. First, download the penguin-liberation-front packages for libfreetype6 (and -devel): libfreetype6-2.1.10-8plf.i586.rpm and libfreetype6-devel-2.1.10-8plf.i586.rpm
    2. Then, install them instead of the Mandriva packages. However, urpmi won't upgrade them since the replacement version is in fact slightly earlier. If you use urpme to remove the Mandriva packages before installing the PLF ones, you'll end up uninstalling your entire system! This is one of those rare occasions when using rpm with --nodeps is justified. Find the names of the packages which are installed:
      rpm -qa | grep libfreetype
    3. Forcibly uninstall them, without removing packages which depend on them:
      rpm -e --nodeps libfreetype6-2.1.10-9.1.20060mdk libfreetype6-devel-2.1.10-9.1.20060mdk
    4. Install the PLF packages:
      urpmi ./libfreetype6-2.1.10-8plf.i586.rpm ./libfreetype6-devel-2.1.10-8plf.i586.rpm
    5. Prevent urpmi --auto-select from re-installing the mandriva packages. Add this to /etc/urpmi/skip.list
      #Don't mess up the libfreetype: keep the PLF packages.
      libfreetype6
      libfreetype6-devel
      libfreetype6-static-devel
    6. Restart X (logout, service dm restart)

[4] Font settings for applications

Now, we need to configure the applications to use the new fonts. We want to use hinted fonts, with anti-aliasing off (except for large font sizes). Note that the precise font sizes need to be controlled per machine, since the display resolution affects their weight. Eg Tahoma 10 looks a lot better than Tahoma 9 or 11. Also, it is worth playing with the upper limit of the Antialiasing exclude range: generally, the higher the resolution (DPI) of the monitor, the smaller this number can be; the aim is to make headlines look smooth, and text look sharp. Lastly, to add confusion, OpenOffice and Mozilla/Firefox work in pixels not points. Here are the settings which I use on the A22p (at 133 dpi) and, for comparison, my desktop machine (at 99dpi):
Application Font
(Thinkpad A22p, resolution: 133dpi)
Font
(Desktop, resolution: 99dpi)
kcontrol -> LookNFeel -> Fonts:    
    -   General: Tahoma (8) Tahoma (10)
    -   Fixed Width: Courier New (10) Lucida Typewriter (10)
    -   Toolbar: Tahoma (8) Tahoma (10, bold)
    -   Menu: Tahoma (8) Tahoma (10)
    -   Window title: Arial (10) Terminal [DEC] (11, bold)
    -   Taskbar: Tahoma (6) Helvetica (8)
    -   Desktop: Tahoma (8) Tahoma (10)
    -   Use Antialiasing for fonts: yes
    -   Use sub-pixel hinting: no
    -   Hinting style: medium.
Exlude range 0-14pt (inclusive) Exlude range 0-14pt (inclusive)
Konqueror as file manager
(kcontrol -> Components -> File Manager):
Tahoma (8) Tahoma (10)
Konqueror as web browser
(kcontrol -> WebBrowsing -> Fonts):
   
    -   Minimum fontsize: 6 7
    -   Medium fontsize: 8 12
    -   Standard font: Verdana Verdana
    -   Fixed font: Courier New Courier New
    -   Serif font: Times New Roman Times New Roman
    -   Sans serif font: Arial Arial Unicode MS
    -   Cursive font: Perpetua Park Avenue
    -   Fantasy font: Blue Highway Blue Highway
Kwrite: Fixed [Misc] (8) Courier New (11)
Konsole: Fixed [Misc] (8) "Unicode". Or Fixed [Misc] (12). Or Terminus 11
Settings for most GTK applications
(gnome-font-properties):
   
    -   Application font: Tahoma (8) Tahoma (10)
    -   Desktop font: Tahoma (8) Tahoma (10)
    -   Window title font: Arial (10) Terminal (11,bold)
    -   Terminal font: Courier New (10) Terminal (10)
    -   Font Rendering: Monochrome Monochrome
Gnumeric -> Format -> Preferences -> Font: Tahoma (7) Tahoma (10)
OpenOffice 2.0:    
    -   Tools -> Options -> OpenOffice.org -> View: Screen font antialiasing: from 25 pixels (≈14 pt) Screen font antialiasing: from 20 pixels (≈14 pt)
Optionally, to change U.I. font (probably already Tahoma via KDE/Ooo integration), uncheck "Use system font for user interface".
    -   Tools -> Options -> OpenOffice.org -> Font: If changing U.I. font, select "Apply replacement table" and replace "Andale Sans UI" (which is not listed) with Tahoma. Select "Always".
Mozilla (suite)
[Version from Mozilla.org, GTK1]
(Uses the 100dpi fonts. Very clear):
   
    -   Proportional: [not tried this] Sans Serif (14 pixels)
    -   Serif: n/a adobe-times-iso8859-1
    -   Sans-serif: n/a adobe-helvetica-iso8859-1
    -   Cursive: n/a adobe-courier-iso8859-1
    -   Fantasy: n/a adobe-courier-iso8859-1
    -   Monospace: n/a adobe-courier-iso8859-1 (14 pixels)
    -   Minimum font size: n/a 10 pixels
    -   Display resolution: n/a 99 dpi
Mozilla (suite)
[Version from Mandriva, GTK2]
(Uses the TTF fonts):
   
    -   Proportional: Sans Serif (14 pixels) [not tried this]
    -   Serif: Times New Roman n/a
    -   Sans-serif: Verdana n/a
    -   Cursive: Perpetua n/a
    -   Fantasy: Blue Highway n/a
    -   Monospace: Courier New (16 pixels) n/a
    -   Minimum font size: 11 pixels n/a
    -   Display resolution: 133 dpi n/a
Firefox    
    -   Proportional: Sans Serif (14 pixels) Sans Serif (13 pixels)
    -   Serif: Times New Roman Times New Roman
    -   Sans-serif: Verdana Verdana
    -   Monospace: Courier New (16 pixels) Courier New (16 pixels)
    -   Minimum font size: 11 pixels 10 pixels
    -   Display resolution: 133 dpi 99 dpi
Thunderbird    
    -   Proportional: Sans Serif (14 pixels) Sans Serif (14 pixels)
    -   Serif: Times New Roman Times New Roman
    -   Sans-serif: Tahoma Tahoma
    -   Monospace: Courier New (16 pixels) Courier New (16 pixels)
    -   Minimum font size: 11 pixels 10 pixels
    -   Display resolution: 133 dpi 99 dpi
Repeat for root. If desired, repeat the above (with sudo) for applications when they run as root (eg Mandriva Control Center).

[5] Fix GTK weirdness

Fix GTK applications with KDE. Unfortunately, there is a problem with GTK applications: every time X is restarted, they lose their font settings (which are defined by gnome-font-properties), and go back to (ugly!) defaults. The way to fix this is to run gnome-settings-daemon. This could also be achieved by starting and stopping gnome-font-properties. Note that the side effect is to start xscreensaver and the gnome-accessibility stuff (key repeats). Unfortunately, there doesn't seem to be a simple workaroud in the (complicated) ~/.gtkrc-2.0. Thus, I append this to the end of my kde-startup script:
#Fix GTK fonts. GTK applications don't use the right fonts unless gnome-settings-daemon is running.
#Side effect: xscreensaver is also started, as is the gnome-accessibility stuff (key repeats) and gnome-volume-manager

sleep 5	 #Allow KDE to finish starting.
/usr/lib/gnome-settings-daemon &

[6] Test

Log out and in again (if desired) to check everything. Take another screenshot if desired, and enjoy the difference!

[7] A few (more) notes on fonts

  • Selecting fonts: xfontsel is useful. A font is unambiguously described by both foundry and name (and size,style...) eg: adobe-times-iso8859-1 However, in KDE, fonts are known just by their name when unambiguous e.g. Bitstream Vera Sans and with the foundry in brackets when it is required, e.g. Fixed [Misc] or Fixed [Sony]. Also, note that Times (=adobe-times-iso8859-1) and Times New Roman (= Microsoft TTF) are quite different fonts! FIXME - explain fc-cache, fc-match fc-list fonts.conf ttf vs type1 (no real difference) helvetica/univers vs arial (wkipedia articls)
  • For desktop users, with antialiased fonts and LCD monitors without DVI: LCD monitors auto-adjust by aligning their clock with vertical lines in the image. But, if all the fonts are antialiased, there are no hard edges to crunch on, and the monitor calibration is often poor. Here is a 1280x1024 chessboard: view it at 100% size, then press audo-adjust on the monitor.
  • The point is a unit of length, defined as 1 point = 1/72.27 inch; in computing, it is usually redefined to 1/72 instead. A 10-point font means that that the full height of a row of text is 10 points. The "em" is the height of an 'M' or the width of an 'm' in that font. [For example: at 96dpi, 12pt = 16 px; at 133dpi, 10pt = 18px]
  • The GIMP freefonts are good, and may be downloaded from here. Also, myfonts.com have a large number of fonts available for preview.
  • Summary: it's all about personal choice. If you get used to AA, then switching back to non-AA feels a bit weird for a while. Likewise, vice-versa.

[1] Introduction

Xscreensaver is a much nicer package than the KDE screensaver, and has a wonderful configuration program/toy: xscreensaver-demo. The really slick screensavers and fireflies are also great! Install the following packages: xscreensaver,xscreensaver-gl,xscreensaver-extrusion,xscreensaver-matrix,rss_glx,fireflies,rss_glx-matrixview.
Configure xscreensaver (xscreensaver-demo) to lock the screen (and when suspending the laptop), or there is no use having an encrypted laptop! To start xscreensaver automatically, first disable the KDE screensaver, then add the following into ~/.kde/Autostart/startup.sh:
kstart xscreensaver -nosplash 2>/dev/null &

[xpenguins -a -b and xearth are also fun - but you need to enable "Programs in desktop window" in KDE->Control Centre->Look and Feel->Behaviour.]

[2] r128/ati Workaround

There is an obscure bug in the r128/ati graphics card driver when it interacts with GL programs and the mouse cursor theme. The effect is that, whenever a GL program is running, the mouse cursor changes from the nice blue crystal-cursors theme to a black-and-white mottled one. I suspect this bug is too obscure to troubleshoot! However, it can be worked-around by one of:
  • Revert to "core" (X-default) cursor-theme, or
  • De-select the GL screensavers in xscreensaver-demo, or
  • Kill and restart xscreensaver every time it unblanks.
Here is a script to do the last one automatically; save it as ~/bin/xscreensaver_monitor.sh and start it in ~/.kde/Autostart/startup.sh instead of directly running xscreensaver. Note this must be started before gnome-settings-daemon:
#!/bin/bash
#Xscreensaver on Rage128 Mobility card with any cursor-theme other than core messes up the cursor. It is borked
#if last xscreensaver process was a GL one. So kill/restart xscreensaver every time it unblanks.

while : ; do
        echo "Starting xscreensaver; monitoring for unblank..."

	#Watch the xscreensaver status. When unblanking, the line will begin 'UNBLANK'
        xscreensaver -verbose -no-capture-stderr -no-splash 2>&1 | while read LINE; do
                if echo $LINE | grep 'unblanking screen at' &>/dev/null 2>&1 ; then

			echo "Unblank detected. Killing xscreensaver..."
                        killall xscreensaver
                        break;
                fi
        done
done

[1] Sound configuration (ALSA)

In Mandriva 2006, sound just works. The snd-cs46xx modules are correctly detected for ALSA, and even better, ALSA now has dmix enabled by default. Previously, sound applications required an exclusive lock on /dev/dsp and would not share it. Sound servers such as Artsd were a partial solution, but the latency was a problem: and not every application had an arts-output capability. Artswrapper/soundwrapper didn't always work. However, with dmix, all is happy! Multiple applications can output sounds to the sound card simultaneously, provided that they use ALSA output rather than OSS (i.e. /dev/dsp):
  • Most applications (eg mplayer, amarok, vlc) can do this: simply set the output plugin to be alsa.
  • Even the KDE sound server can output to Alsa. (But see below).
  • Some applications only understand OSS. (eg /usr/bin/play). In these cases, use aoss to intercept the call to /dev/dsp and redirect it to ALSA. eg aoss /usr/bin/play Beethoven5.ogg [Actually, play itself is just a script, and can be edited to include the aoss anyway.]
  • QEMU doesn't work with aoss, so it has to have the sound card to itself.
  • CD playback can be done digitally, via alsa (eg by alsaplayer,kscd,vlc) or directly through the sound card.
For more technical details on ALSA, see this excellent introduction, this tutorial, and this page about dmix. If you have multiple sound devices (eg external USB soundcard), finding the correct name in alsa-terminology is slightly complex. To get information, use aplay -l, amixer -c 0 scontrols and look in /proc/asound. For example, default:1,0 means "use the default alsa-interface to the second soundcard, on the first channel"; dmix:1,0 explicitly forces alsa to use dmix, whereas hw:1,0 usually prevents dmix from working.

[2] Arts

Finally! Artsd has a very noticeable startup latency (especially when playing system notifications), and it is finally obsolete! Arts can be configured to use ALSA for output, but it is unncessary. I have the KDE sound system (kcontrol->Sound->Sound System) disabled, and play system-notification sounds thus:
  • kcontrol->LookNFeel->System Notifications->Player Settings->Use external player.
  • External player is sox_aplay.sh
  • In ~/bin/, I have the following script named sox_aplay.sh:
    #!/bin/bash
    #Play audio file immediately (avoid arts startup delay). Volume decreased to 0.4
    sox "$1" -t wav -v 0.4 - | aplay
    
    #Note: in newer versions of sox, the argument order is different; use this instead:
    #sox "$1" -t wav - vol 0.4 | aplay

[3] System bell

To get the system bell to work, it is necessary to load the pcspkr module. See above. Then, in kcontrol->Sound->system Bell, make sure "Use system bell instead of system notification" is checked, and set the beep to 440 Hz (Concert A!) and duration 30ms.

Make sure Konsole is set to use it by choosing: Settings->Bell->System Bell. Then, test by pressing Ctrl-G, and you should be instantly greeted by a short, friendly beep.

For use in scripts: echo -e "\a". Or install gnubeep, and try: for ((i=200;i<=400;i=i*10611/10000)); do sudo gnubeep -f $i -l 100000; done

[4] Sound Mixer

The mixer volumes are changed with kmix (or gnome-alsamixer alsamixergui), and if required, can be manually saved/restored with alsactl. [aumix is obsolete, and doesn't support all the mixer-controls.] To reduce hiss, keep all volumes below 90%, and ensure that the Mic channel is muted. As with all internal soundcards, one can hear some interference from the CPU.

The Thinkpad has some buttons for Volume up/down/mute. These are in "series" with the mixer. If desired, their state can be displayed on-screen by using tpb.

amixer is a very useful non-interactive command-line mixer control (usable in scripts etc).

speaker-test is helpful for identifying which channel is connected where, and emitting a test sine-wave.

[5] Microphone

On my Thinkpad, the internal Mic is broken. However, the Mic input is fine. This input provides a bias voltage, capable of powering an electret microphone. A pair of headphones will work as a quasi moving-coil microphone, however I have been extremely impressed by the Microphonics microphones: tiny, high-quality electret condensers built into a stereo 3.5mm jack plug and costing a mere £7 ($10). It is also necessary to enable the +20dB Mic Boost in the mixer.

Recording sound isn't as straightforward as expected! You may find that even though you can get the mic to work through the speakers, you can't record from it! (This usually indicates that the ADC is disabled.) Here's what I had