I am running a small linux box connected to my TV for playing retro games in emulators. I had serious problems getting retroarch (libretro) on gentoo up for running my N64 games because the required version of the emulator (mupen64plus) was way too buggy. However, the latest unstable version of standalone mupen (using an overlay) was able to run my Mario Kart 64 without texture glitches :-D

You can easily fire up games with a gamepad using emulationstation. And you can even shut down or run custom scripts with this frontend. But one thing was missing: Quitting the emulator without a keyboard or an IR-remote. As I use all the buttons of my gamepads for the games, defining one button to exit in the emulators key mapping was no option. I needed a way use a button combination for it.

I figured out how to put together a chain of three components to exit a running emulator without a keyboard.

First the ugly part: I use a „killall -9 emu“ to „end“ the emulator. To execute this command I use xbindkeys. It is a small daemon that listens for pressed key sequences. My config looks like this:
"killall -9 mupen64plus"
control + q

It listens for the control and q keys pressed and fires the killall. That’s it.

Having xbindkeys running in background I am able to stop the emulator with the keyboard shortcut. But unfortunately xbindkeys is not able to listen for gamepad buttons.

For the next step I need the gamepads button numbers for the combo. I used the GUI of mupen64 where you set up the key mapping. The GUI lists the pressed buttons numbers. In my case it is number 8 and 9.
Now I use the Xorg conf to map these buttons to the keyboard signals for „control“ and „q“.

Edit Xorg’s gamepad config /etc/X11/xorg.conf.d/50-joystick-all.conf:
Section "InputClass"
Identifier "joystick-all"
Driver "joystick"
MatchIsJoystick "on"
MatchDevicePath "/dev/input/event*"
Option "StartMouseEnabled" "false"
Option "MapButton8" "key=24"
Option "MapButton9" "key=37"

To get the codes 24 and 37 for the control and q-keys I used the command
# xbindkeys -k
It opens a small window and shows the key codes when a button is pressed.

When I press the buttons 8 and 9 on my gamepad now the X server tells the X environment that keys control and q are pressed. This gets caught by xbindkeys and it runs the killall -> Emu gets closed.

Have fun :-)

The common way of linux encrypting your harddrive is using LVM, DM and Luks. You’ll find most of the implementations used by popular distributions leaving the boot partition unencrypted as the kernel modules needed for opening the luks partition must first be loaded somehow. However, there is a way to encrypt the the whole disk including the boot partition and kernel: Make use of grubs cryptodisk feature.

Here is a rough sample how to setup full disk encryption with gentoo, LVM and Luks.

We use only one Luks-encrypted partition containing /boot and /root.

Before installing grub we take the following steps.

Get the UUID of the encrypted partition
# blkid /dev/sda1
/dev/sda1: UUID="057f8bad-c4d2-419c-95a0-f57aaa785a25" TYPE="crypto_LUKS" PARTUUID="0001c2d5-01"

Edit /etc/default/grub as follows
# Append parameters to the linux kernel command line
GRUB_CMDLINE_LINUX="root=/dev/ram0 crypt_root=UUID=057f8bad-c4d2-419c-95a0-f57aaa785a25 real_root=/dev/mapper/vg-root rootfstype=ext4 root_key=key dolvm"

Is this case our volume group is named „vg“ and the partition is „root“. Also we need „root_key“ set for the next steps.

Now we can install grub the usual way into the MBR.
# grub2-install /dev/sda
# grub2-mkconfig -o /boot/grub/grub.cfg

At this point grub will prompt for a passphrase for the encrypted partition just before loading the normal boot menu. By selecting the boot entry it will proceed with loading the kernel. But grub will not pass the passphrase to the kernel, meaning that the kernel will ask again for the key to open the luks partition.
To avoid the need of entering the password twice, we will place a keyfile in another key slot of our partition. And the trick: We will place the keyfile in the initramfs and tell the boot scripts to look for it. Sounds silly? Yes! But as the entire partition including the /boot directory is encrypted, the initramfs will be encrypted, too.

Gentoos boot script for luksOpen will look in /mnt/key/ for the keyfile. As we set the name „key“ in the kernel parameters, our keyfile in the initramfs will be /mnt/key/key.
The genkernel scripts know a parameter called „INITRAMFS_OVERLAY“ to put our own files in the initramfs. We create the folders /key/mnt/key/, put our keyfile in /key/mnt/key/key and tell genkernel to overlay the folder /key.

Edit /etc/genkernel.conf

Genkernel will now copy the directory structure of /key/ in the initramfs and our keyfile will be placed in /mnt/key/key.
While booting the script will try to mount a key device but as we have not set one, it will simply use the key file in the initramfs. Dirty, but it works and seems to be update-save.

This article is just a quick summery but will be extended soon. Comments are appreciated.