github gitlab mastodon email
DragonFlyBSD - french keyboard in initrd

I did install DragonFlyBSD on my laptop using a Hammer2 filesystem on top of a dm-crypt device, following the instruction of the official documentation. The only problem is that I use an azerty keyboard and the uncrypting dialog when booting offers a qwerty layout. That can be a little annoying for people having special characters in their passwords.

This is how I managed to have an azerty layout to type my decrypting password at boot time. Commands are done as root.

cp /usr/src/share/syscons/keymaps/fr.iso.kbd /usr/src/initrd/etc/
echo << EOF > /usr/src/initrd/etc/rc.kbdfr

echo "Setting the keyboard to french layout"
/bin/rescue kbdcontrol -l /etc/fr.iso.kbd

We have added new files that we want to be dealt with by the initrd building process, so now we need to modify it in order to do so. Modify /usr/src/initrd/etc/Makefile with the following additions.

ETC_SCRIPTS=   rc rc.lvm2 rc.kbdfr fr.iso.kbd rcmount_crypt rcmount_tcplay

# in usr.sbin section
        fstyp           \
+       kbdcontrol      \
        pw              \

# Add missing library required for kbdcontrol compilation
+CRUNCH_LIBS+= -ll # kbdcontrol

Once that this is done, we are able to build the new initrd.

cd /usr/src/initrd
make install

Before rebooting, we can check that the tools are in the initrd image. First let’s mount the initrd image on /mnt in order to list its content.

cp /boot/kernel/initrd.img.gz ~
gunzip initrd.img.gz
vnconfig vn0 initrd.img
mount /dev/vn0 /mnt
ls -l /mnt/etc/
total 216
-r-xr-xr-x  1 root  wheel   7752 Dec 15 11:36 fr.iso.kbd
-r--r--r--  1 root  wheel    540 Dec 15 11:36 group
-rw-------  1 root  wheel   1520 Dec 15 11:36 master.passwd
-r--r--r--  1 root  wheel    412 Dec 15 11:36 motd
-r--r--r--  1 root  wheel   6256 Dec 15 11:36 protocols
-rw-r--r--  1 root  wheel  40960 Dec 15 11:36 pwd.db
-r-xr-xr-x  1 root  wheel   1574 Dec 15 11:36 rc
-r-xr-xr-x  1 root  wheel     92 Dec 15 11:36 rc.kbdfr
-r-xr-xr-x  1 root  wheel    565 Dec 15 11:36 rc.lvm2
-r-xr-xr-x  1 root  wheel    237 Dec 15 11:36 rcmount_crypt
-r-xr-xr-x  1 root  wheel    189 Dec 15 11:36 rcmount_tcplay
-r--r--r--  1 root  wheel  53714 Dec 15 11:36 regdomain.xml
-rw-------  1 root  wheel  40960 Dec 15 11:36 spwd.db
-r--r--r--  1 root  wheel  50648 Dec 15 11:36 wpa_supplicant.conf

So we can check that the image contains our additional files : rc.kbdfr and fr.iso.kbd. We can also check that /mnt/bin/rescue kbdcontrol exists. Last test is to run /mnt/bin/rescue kbdcontrol, that should give the same output as running the regular kbdcontrol command.

Last, here are the step to unmount the initrd.

sudo umount /mnt
sudo vnconfig -u vn0

The last step is to reboot and check that the prompt is using the keyboard layout.