UTF-8 everywhere in TinyCore Linux

TinyCore being Linux at the core, it does handle UTF-8. This encoding has been the default in most Linux distributions for years; not so for TinyCore. That’s because this distribution strives to be tiny and UTF-8 support does make the overall size grow a bit.

In my case, with a whole 16GB (woot!) flash drive, I can easily afford the comfort brought by UTF-8. Here we go…

It seemed to me that I had already explained how to set the locale… Well, it seems not, so let me repair this slight. It is quite easy: you install the getlocale extension, and use it to generate a custom “mylocale” extension, where some UTF-8 locales are enabled. Be sure to load this “mylocale” extension on boot, and change your boot-manager’s settings so that the Linux kernel is given this additional parameter (for example):

linux […] lang=fr_FR.utf8

The way I do things, this new parameter is actually defined in a variable and then the variable is used on the linux line.

But this is not enough. With just this part being done, I still have some worries, like ROX-Filer warning me that this or that file on the flash drive does not have a valid UTF-8 name and should be renamed, or the terminal displaying garbage whenever I type a non-ASCII character, or fonts limited to ISO-8859-1 symbols…

So, first, let’s make sure the xfonts-unifont extension is loaded at boot. This will cover characters for most European languages. Other fonts may have to be installed, for Japanese or Chinese for example.

Next, let’s change both the terminal and the shell. Indeed, neither TinyCore’s default terminal (aterm) nor TinyCore’s default shell (busybox sh) supports UTF-8.

For the terminal, I chose rxvt-unicode, also known as “urxvt”, because it is stable, feature-complete, and small. “st-xft” is even smaller and also an option, as well as bigger terminals like “gnome-terminal”. To enable the change, I make sure that “rxvt-unicode” is loaded at boot, and I create a symbolic link to /usr/local/bin/urxvt named aterm in the PATH so that the default terminal button in TinyCore’s wbar launches my choice of terminal instead of the real “aterm”. In my case:

tc@flash:~$ ln -s /usr/local/bin/urxvt ~/.local/bin/aterm

Of course, I also ensure that my ~/.local directory is saved by TinyCore across reboots, and that ~/.local/bin is in the PATH. In fact, I also create a similar symbolic link with the name xterm; it helps sometimes…

For the shell, I chose bash, the default shell for most Linux distributions. But I do not want to change my default shell in /etc/passwd, in case one day I have to boot without loading extensions; then “bash” wouldn’t be available and I risk not being able to login at all! So instead I simply create an executable file in /home/tc/.X.d/ with this content:

export SHELL=/usr/local/bin/bash

Last but not least, the hardest part in fact, I want partitions (FAT in particular) to be mounted with the UTF-8 charset, not ISO-8859-1. To achieve that, it is necessary to alter TinyCore’s core.gz file. That’s because the change has to apply right from the start of the boot process, before the partition with the extensions on it is mounted. To this end, I have to run these commands (adapt core.gz’ path to your situation):

mkdir core; cd core
gzip -dc /mnt/FLASH/.boot/corelnx/core.gz | sudo cpio -i
sudo sed -i 's#\(ntfs\|msdos\|fat\))#\0 grep -qi "lang=[^ ]*utf8" /proc/cmdline \&\& OPTIONS="${OPTIONS},iocharset=utf8"; #' usr/sbin/rebuildfstab
find . | sudo cpio -H newc -o | gzip -9 >../core.gz
cd ..; rm -rf core
tce-load -il advcomp
advdef -z4 core.gz

The truth is I actually just merge the above one-long-line “sed” command [1] with my already-existing script, just below the “sed” command that makes NTFS-3G the default NTFS handler. But that does not change a thing. There only remains to rename the former core.gz file, and put the new one in its place, then boot from it.

If, however, you boot TinyCore Linux from a partition where the charset is not an issue (a dedicated /boot partition, or an Ext2 partition…), then all you have to do is add these lines to /opt/bootlocal.sh (much simpler, isn’t it?):

sed -i 's#\(ntfs\|msdos\|fat\))#\0 grep -qi "lang=[^ ]*utf8" /proc/cmdline \&\& OPTIONS="${OPTIONS},iocharset=utf8"; #' /usr/sbin/rebuildfstab

So far, all those changes seem to be enough to enjoy UTF-8 without problems arising. See also this post about bash, though.

[1] I changed the command to be more specific to Microsoft filesystems, as the previous command did not work well with other filesystems.

Commentaires

1. Le samedi 13 juillet 2013, 17:18 par Je ne fais que passer…

Thank You Yeti for this blog it helped me to improve my Tiny Core installation.
There is one problem with xfonts-unifont it gives an error message on the boot "xfonts-unifont.tcz: OK
./fonts.dir: fopen(w): Read-only file system".
Probably unifont can not be written to /usr/lib/X11/fonts/misc/fonts.dir which is symlinked, so practical unifonts stay invisible on the system.
Could you please help us fix this problem.

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

La discussion continue ailleurs

URL de rétrolien : http://yalis.fr/cms/index.php/trackback/15

Fil des commentaires de ce billet