Friday, March 30, 2012

DVD Playback: The Missing Package

This took a while to figure out: I had all sorts of weird errors while trying to play a DVD on my laptop, until I did this:
aptitude install libdvdcss2
(requires the Debian Multimedia package repository).

Friday, March 23, 2012

Digging Tunnels: socat

When digging tunnels, an alternative for stunnel on the client side is socat. Here's how to use it in ~/.ssh/config:
Host tunnel.example.com
  Port 443
  ProxyCommand socat - OPENSSL:%h:%p,verify=0



Friday, March 16, 2012

One Liner: Increase the Size of /tmp

The temporary space on /tmp may not be enough for some programs. The following command will re-size it to 2GB, without destroying any existing files:
mount -t tmpfs tmpfs /tmp -o size=2000M,mode=1777,remount
(source: http://wiki.linuxquestions.org/wiki/Tmpfs).

If you find yourself doing this often then you have at least two options:
  1. either add a suitable line for /tmp in /etc/fstab:
    none /tmp tmpfs size=2000M,mode=1777 0 0
  2. or avoid using tmpfs entirely, by modifying /etc/default/rcS like this:
    RAMTMP=no
    (not recommended: may impact both security and performance)
the changes will take effect after you reboot.

[02 Sep 2012] UPDATE: just noticed that RAMTMP=no is now the default setting, again, and that it is set in /etc/deafult/tmpfs

Friday, March 9, 2012

Install Quake and Quake3 on Debian Linux

A long time ago, in a galaxy far away, I was an avid Quake, and later on Quake2 and Quake3 player and modder.

I seem to be getting old: I find myself reminiscing about all sorts of stuff, and Quake is one of my favorite subjects. In one of these nostalgia attacks I decided to relive the fun and install the games on my Linux laptop. I still have all the relevant CD-ROMs, so all that's needed is a suitable game engine. Quake and Quake3 are packaged in Debian, but Quake2 is not packaged.

Here's how to install Quake, with both mission packs:
  1. install the game engine:
    aptitude install quake
  2. mount the game CD-ROM (e.g. on /media/cdrom0)
  3. change directory to a temporary directory
  4. package the game data:
    game-data-packager quake -m /media/cdrom0
  5. repeat the process for both mission packs, i.e. mount the relevant CD-ROM and then issue these commands:
    game-data-packager quake -mp1 /media/cdrom0
    for the SOA mission pack, and
    game-data-packager quake -mp2 /media/cdrom0
    for the DOE mission pack



  6. install the generated packages (as root):
    dpkg -i quake-registered_29_all.deb
    dpkg -i quake-armagon_29_all.deb
    dpkg -i quake-dissolution_29_all.deb
    




And here's how to install Quake3:
  1. install the game engine:
    aptitude install quake3
  2. download the latest point release:
    cd ~/Downloads
    wget -c ftp://ftp.idsoftware.com/idstuff/quake3/linux/linuxq3apoint-1.32b-3.x86.run
  3. mount the game CD-ROM (e.g. on /media/cdrom0)
  4. change directory to a temporary directory
  5. package the game data:
    game-data-packager quake3 /media/cdrom0 ~/Downloads/linuxq3apoint-1.32b-3.x86.run
  6. install the generated package (as root):
    dpkg -i quake3-data_29_all.deb

Happy fragging!

Friday, March 2, 2012

Scripting a Simple Boot Time State Machine in GRUB2

There's a hardware compatibility issue between my laptop's on-board nVidia nForce4 antiquated and buggy SATA interface and the modern Western Digital hard disk that I've installed in it.

The hard disk seems to disappear in mid-boot - this can happen anytime it is being re-detected: when BIOS transfers control to the boot loader (either GRUB2 or the Windows Boot Loader), and when the initial kernel image (loaded by the boot loader) re-initializes the SATA controller. If the system comes up, then any power management event may cause the disk to disappear. Sometimes, the disk just disappears for no obvious reason. The kernel's libata error handling routines may manage to reestablish connection to the disk, but sometimes it does not come up and I have to power cycle the laptop.

None of the solutions/workarounds I tried did the trick: apart for the stuff I already mentioned, I added rootdelay=10 to the kernel command line, hoping that the extra delay would give libata a better chance of re-detecting the disk; I even installed the watchdog daemon, to get my laptop to reboot when it freezes, but either it doesn't really work, or (most likely) I don't understand how to configure it.

The last ditch workaround I came up with, was to boot the laptop into GRUB2 from a USB disk-on-key, thus avoiding the internal hard disk altogether, and have GRUB2 perform the following steps:
  1. check if boot related files on the internal hard disk are accessible
  2. if any file is not accessible then reboot
  3. if all files are accessible, then if this is the first success then reboot
  4. if this is the second success then boot GRUB2 on the internal hard disk
This procedure captures the sequence of steps that seems to get my box to boot - it's Voodoo, I know, but it does work (most of the time).

The script (boot/grub/grub.cfg) below implements this procedure. It uses get_env and save_env to keep a persistent state (the variable need_reboot) between reboots. The first few lines make sure that the state is properly initialized, even if the environment variables were not saved yet (i.e. if this is the first ever boot from this device).

The fact that one can control the boot process this way is pretty neat, in my opinion. The only trouble is that even with this, my system still fails to boot - albeit less frequently than before.

I must admit defeat. The laptop is usable now, but, in my eyes, just barely. The whole experience made me itch for a new PC, but with my luck being what it is, I fear that it won't be a much easier ride. So, for now, I've resigned myself to my fate, until I gather up the courage (and cash) to tackle a new box.


set need_reboot="yes"
if [ -s $prefix/grubenv ]; then
  load_env
fi

insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
set reboot_delay=5

insmod ntfs
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus

function wait_and_reboot {
  echo "Reboot in ${reboot_delay} seconds ..."
  if sleep --interruptible ${reboot_delay} ; then
    reboot
  fi
}

function find_or_die {
  if [ -e $1 ]; then
    echo "$1 found"
  else
    echo "$1 NOT found!"
    wait_and_reboot
  fi
}

set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue

find_or_die (hd1,msdos1)/Boot/BCD
find_or_die (hd1,msdos2)/config.sys
find_or_die (hd1,msdos5)/boot/grub/grub.cfg

if [ -z "${need_reboot}" ]; then
     set need_reboot="yes"
     save_env need_reboot
  else
     set need_reboot=
     save_env need_reboot
     wait_and_reboot
  fi
fi

set timeout=30
menuentry "GRUB on internal hard disk" {
        set root='(hd1)'
        drivemap -s (hd0) (hd1)
        chainloader +1
}