Control Beep-Media-Player with Multimedia Keys

Start xev to find the keycodes. You get as result somthing like:

KeyRelease event, serial 43, synthetic NO, window 0x2400001,
    root 0x3d, subw 0x0, time 3939566, (84,27), root:(1498,49),
    state 0x10, keycode 232 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes:

So we have keycode 232 for this key. Now edit .xmodmaprc in the following style:

keycode 232 = XF86AudioMedia

Allowed symbols can be found in /usr/X11R6/lib/X11/XKeysymDB.

My KeySonic has the following keys:

! config for KeySonic
keycode 153 = XF86AudioNext
keycode 162 = XF86AudioPlay
keycode 144 = XF86AudioPrev
keycode 164 = XF86AudioStop
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume
keycode 178 = XF86HomePage
keycode 236 = XF86Mail
keycode 234 = XF86Back
keycode 233 = XF86Forward
keycode 229 = XF86Search
keycode 231 = XF86Refresh
keycode 230 = XF86Favorites
keycode 232 = XF86AudioMedia
keycode 160 = XF86AudioMute
keycode 227 = XF86WakeUp
keycode 223 = XF86Sleep
keycode 222 = XF86PowerOff

Now load the settings with:

xmodmap .xmodmaprc

In Beep-Media-Player activate the plugin “XF86Audio Keys Control” and everything should work.

Crypt a partition

Kernel Configuration

Device Drivers | Multi-device support | Device mapper support | Crypt target support

Enable the wanted encryption algorithm Cryptographic options | Cryptographic API (sha and aes)

Create a small testfile

Create a container.

dd if=/dev/zero of=container.loop bs=52428800 count=1

Mount it via loop device.

losetup /dev/loop0 container.loop 

Prepare the encryption by selecting the algorithm.

cryptsetup -c aes-cbc-essiv:sha256 -y -s 256 luksFormat /dev/loop0

WARNING!
========
This will overwrite data on /dev/loop0 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: 
Verify passphrase: 

Unlock it.

cryptsetup luksOpen /dev/loop0 verysecret 
Enter LUKS passphrase: 
key slot 0 unlocked.

Create a filesystem.

mkfs.xfs /dev/mapper/verysecret 

Mount it.

mount /dev/mapper/verysecret /mnt/crypt/

Umount it.

umount /mnt/crypt

Clear the passphrase.

cryptsetup luksClose verysecret

Add a second key (8 keys are possible).

cryptsetup luksAddKey /dev/loop0
Enter any LUKS passphrase: 
key slot 0 unlocked.
Enter new passphrase for key slot: 

Delete a key.

cryptsetup luksDelKey /dev/loop0 1

Umount the loop file.

losetup -d /dev/loop0

Handling keys

head -c 100 /dev/random | uuencode -m /dev/stdin | tail -n +2 | \
 head -c 32

Damit bekommst du 32 Bytes Zufallsdaten, die du dann als Platten-Schlüssel benutzt. Wie viele Bytes du brauchst, hängt natürlich von deinem Verschlüsselungs-Algo ab.

Auf der Festplatte legst du diese Daten in PGP-Verschlüsselt ab:

gpg --symmetric --armor

Um die Platte zu mounten macht mein selbstgeschribenes Script dann unter anderem das:

FS_KEY="$(gpg --no-options --passphrase-fd 3 --no-tty --batch \
    --no-default-keyring --keyring /tmp/pubkey.gpg \
    --secret-keyring /tmp/seckey.gpg -d ${KEYFILE} 3<<<${PASSPHRASE} \
    2>/dev/null )"

/usr/bin/sudo /bin/cryptsetup -d /dev/stdin create "${MAPPERDEV}" \
 "${DEVICE}" <<<"${FS_KEY}"

See also here .

Diskless System

We want to boot via PXE and mount everything via NFS. At first we create a basic directory structure:

export DISKLESS=vdrhd1
export DISKLESS=diskless
mkdir /usr/local/$DISKLESS/
cd !$
mkdir boot
mkdir dev
mkdir bin
mkdir sbin
mkdir lib
mkdir etc
mkdir usr
mkdir root
mkdir home
mkdir proc
mkdir tmp
chmod a+w tmp
mkdir sys
mkdir var
mkdir var/empty
mkdir var/lock
mkdir var/log
mkdir var/run
mkdir var/spool
mkdir var/lib
mkdir var/lib/dbus
mkdir var/tmp
mkdir var/cache
mkdir var/cache/hald
mknod dev/console c 5 1
mknod -m 666 dev/null c 3 1

Be sure you have the following settings in the kernel config:

#
# Networking options
#
CONFIG_PACKET=y
CONFIG_INET=y
CONFIG_IP_MULTICAST=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
#
# Network File Systems
#
CONFIG_NFS_FS=y
CONFIG_NFS_V3=y
CONFIG_NFS_V4=y
CONFIG_ROOT_NFS=y

Compile and install the kernel with:

make
make INSTALL_PATH=/usr/local/$DISKLESS/boot install
make INSTALL_MOD_PATH=/usr/local/$DISKLESS modules_install

You must copy or symlink your kernel to the tftp directory so the client can download the kernel via tftp.

Install NVIDIA Driver

Execute on the headless system:

sh NVIDIA-Linux-x86-275.09.07.run  -a

Prepare DHCPD

Put the following lines to your dhcpd.conf:

next-server 192.168.0.251;
filename "pxelinux.0";
option tftp-server-name "server.idefix.lan";

Boot the Kernel with PXE

Create a directory on your TFTP directory called pxelinux.cfg now place their the config files. I have one file called default:

DEFAULT memtest
PROMPT 1
TIMEOUT 10

LABEL memtest
  MENU HIDE
  MENU LABEL memtest
  KERNEL memtest86+.bin

LABEL local
  LOCALBOOT 0

And one file with the MAC address 00-de and so on:

PROMPT 1
DEFAULT vdr
TIMEOUT 10

LABEL vdr
  MENU HIDE
  MENU LABEL ^VDR
  KERNEL vmlinuz-2.6.22-gentoo-r5-diskless
  APPEND ip=dhcp root=/dev/nfs nfsroot=192.168.0.149:/usr/local/diskless

LABEL memtest
  MENU HIDE
  MENU LABEL ^memtest86+
  KERNEL memtest.bin

Synchronize folders

rsync -az --delete --ignore-errors --numeric-ids --stats --progress /bin /usr/local/$DISKLESS/
rsync -az --exclude "*$DISKLESS*" --delete --ignore-errors --numeric-ids --stats --progress /lib /usr/local/$DISKLESS/
rsync -az --delete --ignore-errors --numeric-ids --stats --progress /sbin /usr/local/$DISKLESS/
rsync -az --exclude "/var/lib*" --exclude "/var/cache*" --exclude "/var/log*" --exclude "/var/tmp" --exclude "/var/db*" \
--exclude "/var/www" --delete --ignore-errors --numeric-ids --stats --progress /var /usr/local/$DISKLESS/
rsync -az --delete --ignore-errors --numeric-ids --stats --progress /etc /usr/local/$DISKLESS/

Kernel Programming

Link a Library to a Kernel Modul

We have the structure:

|
|-Makefile
|-hello.c
|-hello_lib.c
|-hello_lib.h

hello_lib.h:

int printHello(int);

hello_lib.c

int printHello(int count)
{
   int i;
   
   for(i=0;i<=count;i++)
   {
      printk("Hello World\n");
   }
   
   return 0;
}

hello.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include "hello_lib.h"

MODULE_LICENSE("GPL");

int init_module(void)
{
   printk("call function\n");
   printHello(5);
   return 0;
}

void cleanup_module(void)
{
   printk(KERN_INFO "remove module\n");
   return;
}

Makefile:

KDIR    := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

obj-m += test.o
test-y := hello.o libhello_lib.a

all:
	gcc -I/usr/include -c -o hello_lib.o hello_lib.c
	rm -f libhello_lib.a
	ar cru libhello_lib.a hello_lib.o
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules KBUILD_VERBOSE=1

clean:
	rm -f *.o
	rm -f *.ko
	rm -fr .tmp_versions
	rm -f Modules.symvers
	rm -f *.a
	rm -f *.mod.c
	rm -f .*.cmd

Test it with:

insmod ./test.ko

Remove the module with:

rmmod test

Maybe you want this here:

insmod ./test.ko && rmmod test

Mounting

Image via loop-back

Create a directory where to mount the image:

mkdir /mnt/image

Mount the image with:

mount /home/images/ppc-2006-01-11.iso /mnt/image -o loop=/dev/loop3
or
mount /tmp/fdimage /mnt -t msdos -o loop=/dev/loop3,blocksize=1024

Warmboot kernel

To directly reboot into a new kernel the tool kexec is necessary:

emerge sys-apps/kexec-tools

The new kernel can be loaded with:

kexec -l --command-line="root=/dev/hdb3 udev video=vesafb:mtrr,ywrap,1024x786-32@85 ro" /boot/vmlinuz
kexec -e

Wine

Original instance of package unmerged safely.

* ~/.wine/config is now deprecated.  For configuration either use
* winecfg or regedit HKCU\Software\Wine