LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   How to add non-US keyboard layout to initrd (cryptsetup)? (http://www.linuxquestions.org/questions/slackware-14/how-to-add-non-us-keyboard-layout-to-initrd-cryptsetup-632641/)

malo_umoran 04-03-2008 03:18 AM

How to add non-US keyboard layout to initrd (cryptsetup)?
 
Hi,

I was trying to optimize my system yesterday, to remove unneeded packages, configs, make it faster etc.

I am using initrd for boot, because my / partition is encrypted. When cryptsetup asks for the password I have to be really careful, because I have german keyboard. But the initrd is using US keyboard layout.

Any ideas how to change this?

I also thought about copying keymap file from /usr/share/kbd/keymaps/ (with all dependencies) and loading it. But maybe you have a more simple solution.


I found for debian or ubuntu solutions like "add this line to xxxx.conf" and I thought about dismantling ubuntu's initrd and check everything line by line.

Thanks.

Alien Bob 04-03-2008 08:00 AM

Hm, yes this should be nice to add to mkinitrd. It is not even hard.
But taking into account that Slackware 12.1 release candidate 1 was made available today, I guess that only the serious bugs are going to be solved at this time. Your feature request would be added to the next Slackware development release at the earliest.

In the meantime what you can try is this:

You should already have a directory /boot/initrd-tree which is created when you run the 'mkinitrd' command. It contains the full content of the initrd image that gets zipped into /boot/initrd.gz
  • Download the file http://www.slackware.com/~alien/tools/keymaps.tar.gz and copy it to /boot/initrd-tree/etc/. This file is part of the Slackware installer, you will not find it anywhere in the Slackware source tree but I extracted it for you from the /isolinux/initrd.img file.
  • Create a file /boot/initrd-tree/keymap in which you write the name of your language for the keyboard (like nl for the dutch keyboard or de-latin1-nodeadkeys for one of the german keyboards which are available in the keymaps.tar.gz)
  • In the /boot/initrd-tree/init script, add this line in the beginning:
    Code:

    KEYMAP=`cat /keymap`
    further down add the following lines to actually load the keyboard map - make sure the commands are added before the point where cryptsetup runs and asks for a passphrase:
    Code:

    # Load a custom keyboard mapping:
    if [ -n "$KEYMAP" ]; then
      echo "${INITRD}:  Loading '$KEYMAP' keyboard mapping:"
      tar xzOf /etc/keymaps.tar.gz ${KEYMAP}.bmap | loadkmap
    fi


All this advice is untested, I just made it up. But it should work, and I will test this by creating a modified mkinitrd package as soon as I have the time.
If this worked for you please let me know ASAP!

Eric

malo_umoran 04-03-2008 09:05 AM

I hoped that you will come out with solution like this :). Really nice.

I did it other way, but I did not test it. I copied /usr/bin/loadkeys in /boot/initrd-tree/bin and I put de.map in a new folder /boot/initrd-tree/share/kbd folder, chrooted in /boot/initrd-tree and tried to load it with

Code:

/bin/loadkeys /share/kbd/de.map
It complained about missing include euro2.map and a few other files. I copied all of these files in the same folder and it does not complain any more in the chrooted environment. It just says that keymap is loaded.I will reboot when I come home.

Your solution is much more universal and cleaner and I will test it today. I will let you know does it work.

Thanks Eric.

M.

malo_umoran 04-04-2008 03:02 PM

Hi Eric

I tested your code a few minutes ago. It works in principle, but I had to make a few changes for initrd image, because it did not work "out of the box":

1. I had to download/recompile busybox, because applets like tar or loadkmap are not available in Slackware's busybox.

I also added some other commands to handle better cryptsetup errors like poweroff and reboot. If user enters wrong password three times, init shows an error message and runs /bin/poweroff instead of kernel panic error. I did not test it, but it could look something like this:

Code:

    /bin/clear
    /sbin/cryptsetup luksOpen ${LUKSDEV} $ROOTDEV </dev/systty >/dev/systty 2>&1
    ROOTDEV="/dev/mapper/${ROOTDEV}"

    if [ ! -e $ROOTDEV ]; then
        echo
        echo "Three times wrong password, you loser? Bye bye..."
        echo
        echo -n "Press Enter/Return to reboot or wait 5 seconds for system to shutdown."

        read -t 5 SHUTDOWN
        if [ -z $SHUTDOWN ]; then
            echo "Running poweroff..."
            /bin/poweroff
        else
            echo "Rebooting..."
            /bin/reboot
        fi
    fi


2. loadkmap did not want to run, because /dev/tty0 was missing.

Is there a reason why tty0 is not included in initrd-tree.tar.gz?

There are /dev/tty1, 2, 3 and 4, but tty0 is missing. I was not able to tell loadkmap to use /dev/tty1 so I just made a symlink to tty1.

Code:

# Load a custom keyboard mapping:
if [ -n "$KEYMAP" ]; then
    echo "${INITRD}:  Loading '$KEYMAP' keyboard mapping:"
    ln -s /dev/tty1 /dev/tty0
    tar xzOf /etc/keymaps.tar.gz ${KEYMAP}.bmap | loadkmap
fi

It is working just great. Other more simpler and cleaner solution would be to make /boot/initrd-tree/dev/tty0 before running mkinitrd or to tell sh somehow to use tty1 instead of tty0. But you know that probably much better than me.

Thanks a lot.


Two partly off-topic but still initrd questions:
1. is there some kind of bootsplash which could be used to have at least some kind of GUI for entering password? This is my girlfriend's official request :). I tried Ubuntu's usplash, but I was not able to make it work on Slackware (screen just becomes black).

2. I totally stripped down kernel image in modules to load fastes by using just unnecessary features in kernel and to make it come faster to cryptsetup's "Enter password". Still most of the time takes disk detection (6 disks). Do you know is it somehow possible to tell ata/sata_nv module(s) just to check /dev/sda or sdb and ignore other? Some kind of modprobe /insmod param like insmod /lib/.../sata_nv onlydetect=/dev/sda ? I do not believe that there is something like that because this detection "creates" sd[abcdef], but I still wanted to ask :)


Thanks.

M.

Alien Bob 04-04-2008 05:24 PM

Quote:

Originally Posted by malo_umoran (Post 3110942)
Hi Eric

I tested your code a few minutes ago. It works in principle, but I had to make a few changes for initrd image, because it did not work "out of the box":

1. I had to download/recompile busybox, because applets like tar or loadkmap are not available in Slackware's busybox.

My HOWTO was targeted at Slackware's development version (-current) where the busybox is already compiled with the functionality needed. But you did well by recompiling your Slackware's busybox.

Quote:

I also added some other commands to handle better cryptsetup errors like poweroff and reboot. If user enters wrong password three times, init shows an error message and runs /bin/poweroff instead of kernel panic error. I did not test it, but it could look something like this:
Well... someone who enters the LUKS password incorrectly three times is a loser. Your poweroff solution is userfriendly but Slackware's initrd will remain as it is ;-) It'll teach you not to enter three incorrect passwords.

Quote:

2. loadkmap did not want to run, because /dev/tty0 was missing.

Is there a reason why tty0 is not included in initrd-tree.tar.gz?
In Slackware 12.1 (soon to be released) initrd-tree there is a /dev/tty0 , so that solves your problem.

Quote:

Two partly off-topic but still initrd questions:
1. is there some kind of bootsplash which could be used to have at least some kind of GUI for entering password? This is my girlfriend's official request :). I tried Ubuntu's usplash, but I was not able to make it work on Slackware (screen just becomes black).
No bootsplash in Slackware... and that will remain so.

Quote:

2. I totally stripped down kernel image in modules to load fastes by using just unnecessary features in kernel and to make it come faster to cryptsetup's "Enter password". Still most of the time takes disk detection (6 disks). Do you know is it somehow possible to tell ata/sata_nv module(s) just to check /dev/sda or sdb and ignore other? Some kind of modprobe /insmod param like insmod /lib/.../sata_nv onlydetect=/dev/sda ? I do not believe that there is something like that because this detection "creates" sd[abcdef], but I still wanted to ask :)
If you have six disks, I assume you want to use them don't you? Anyway, the disk probing should not take long. And you can take those disks out and buy a single big disk as replacement.

Eric

PS: The mkinitrd of slackware-current was just enhanced today with the parameter "-l <language>" to add support for a non-US keyboard in the initrd... which adds exactly the functionality we are talking about in this thread ;-) You can take the mkinitrd sources out of Slackware-current and run the mkinitrd.SlackBuild, it will create a package for your Slackware that you can use instead of what you have now.

malo_umoran 04-04-2008 05:44 PM

Thanks for the help and including -l in mkinitrd.

Quote:

Originally Posted by Alien Bob (Post 3111082)
No bootsplash in Slackware... and that will remain so.

:) I absolutely agree with you and I do not need it for the boot process.
But She (me too in the meanwhile :) ) would like to have some kind of shiny gui until password is typed in.

And I also remember finding yesterday splashy or some other sort of bootsplash package on your repository and it was made by you (no no ;) ) and I thought that you have an idea which bootsplash application supports user input.

titopoquito 04-05-2008 08:44 AM

Quote:

Originally Posted by Alien Bob (Post 3111082)
PS: The mkinitrd of slackware-current was just enhanced today with the parameter "-l <language>" to add support for a non-US keyboard in the initrd... which adds exactly the functionality we are talking about in this thread ;-)

Hi Eric, since it's you who has done this, may I suggest a little and not in any way critical patch to you, regarding the mkinitrd man page? [EDIT: "cosmetical change", I think that's the term I was looking for :) ] BTW, many thanks for your work, it's very convenient to have the keymap option IMHO.

Code:

--- mkinitrd.8.old  2008-04-05 15:30:22.008347000 +0200
+++ mkinitrd.8  2008-04-05 15:32:23.236344761 +0200
@@ -7,7 +7,7 @@
 .ie \\n(.$=0:((0\\$1)*2u>(\\n(.lu-\\n(.iu)) .TP
 .el .TP "\\$1"
 ..
-.TH MKINITRD 8 "04 March 2008" "Slackware Version 12.1"
+.TH MKINITRD 8 "05 March 2008" "Slackware Version 12.1"
 .SH NAME
 mkinitrd \- create or rebuilt an initrd (initial ramdisk) using initramfs (simple cpio+gzip).
 .SH SYNOPSIS
@@ -28,6 +28,9 @@
 .B \-k kernel_version
 ]
 [
+.B \-l keymap
+]
+[
 .B \-m module1:module2:module3...
 ]
 [



All times are GMT -5. The time now is 01:54 PM.