Thursday, March 24, 2016

Add custom keyboard layout to OpenELEC image

OpenELEC system partition on Raspberry PI is read-only filesystem (squash filesystem or squashfs).
I cannot change anything of system partition or add custom keyboard layout.

If you want to change something on this filesystem, you should unpack and repack squashfs image.

I use Ubuntu 15.10 for repack squashfs image.

First install squashfs-tools for re-create squashfs image.
$ sudo apt-get update
$ sudo apt-get install squashfs-tools

Download OpenELEC Image and extract compress file.

Backup original and copy to new image file.

$ cp OpenELEC_original.img OpenELEC_custom.img

Mount image file to loop device (/dev/loop0)
$ sudo losetup -P /dev/loop0 OpenELEC_custom.img

option -P for create a partitioned loop device (/dev/loop0p1, /dev/loop0p2)

Check partitioned loop device with fdisk.
$ sudo fdisk -l /dev/loop0
Disk /dev/loop0: 548 MiB, 574619648 bytes, 1122304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3902d568
Device       Boot   Start     End Sectors  Size Id Type
/dev/loop0p1 *       2048 1050624 1048577  512M  c W95 FAT32 (LBA)
/dev/loop0p2      1052672 1118208   65537   32M 83 Linux

It created /dev/loop0p1 and /dev/loop0p2.

Create boot and system directory
$ mkdir boot system

Mount  first loop partition (/dev/loop0p1) to boot partition.
$ mount -t vfat /dev/loop0p1 boot

Check all file on boot partition.
$ ls boot
bcm2708-rpi-b.dtb       bootcode.bin  fixup.dat   start.elf
bcm2708-rpi-b-plus.dtb  cmdline.txt   kernel.img  SYSTEM
bcm2708-rpi-cm.dtb      config.txt    overlays

It found SYSTEM file (OpenELEC system filesystem).

Mount SYSTEM file to system partition.
$ mount -t squashfs boot/SYSTEM system

Check all file on system partition.
$ ls -F system
bin/  etc/    lib/    opt/   run/   storage/  tmp/  var/
dev/  flash/  media@  proc/  sbin/  sys/      usr/

Create temporary directory for copy all file on system partition and add custom keyboard layout.
$ mkdir tmpsystem

Copy all file of system to temporary directory
$ sudo cp -Rpf system/. tmpsystem

After copy all file to temporary directory.
Unmount system filesystem.
$ sudo umount system

OK. Now you can change everything on temporary directory.

Location Kodi system data on OpenELEC: /usr/share/kodi

Kodi keyboard layout directory on OpenELEC (/usr/share/kodi/system/keyboardlayouts)
You can add custom keyboard layout or change exists keyboard layout on this directory.

Now: tmpsystem/usr/share/kodi/system/keyboardlayouts

Example. I want to add Thai keyboard layout (thai.xml) to this directory.
Copy thai.xml to tmpsystem/usr/share/kodi/system/keyboardlayouts
$ sudo cp thai.xml tmpsystem/usr/share/kodi/system/keyboardlayouts

OK. Now you finished to change temporary directory.

I will re-create system filesystem  (SYSTEM file) from temporary directory with mksquashfs.

$ sudo mksquashfs tmpsystem SYSTEM -noappend -comp gzip

Now. I have new SYSTEM file.

Delete SYSTEM file on boot partition.

$ sudo rm boot/SYSTEM

Copy new SYSTEM file to boot partition.

$ sudo cp SYSTEM boot

Unmount boot partition.

$ sudo umount boot

Deattach loop device from OpenELEC image.

$ sudo losetup -d /dev/loop0

Delete temporary directory

$ sudo rm -Rf tmpsystem

OK. Now. OpenELEC image (OpenELEC_custom.img) has changed.

Try to write image to sdcard for test it.

Goto  System -> Settings -> Appearance -> International -> Keyboard layouts
Select Thai keyboard layout.


You can add font to Kodi on system font path: /usr/share/kodi/media/Fonts.



  1. รบกวน ขอไฟล์ image คีบอร์ดภาษาไทย ที่แก้ไขแล้วได้ไหมครับ

  2. Image สำหรับ Raspberry PI หรอครับ