Lakka is a distribution for running retro arcade games in a Kiosk-like manner and mainly geared towards arcade cabinets that have been rewired to use a Raspberry Pi instead of a Pandora Box. Lakka is based on a read-only squashfs image and meant to be tamper-proof such that, as advertised, not even having root access could do much damage. Unfortunately, this approach has its strength but also its weaknesses.
The following notes are meant to enhance or possibly speed up Raspberry Pi machines by making some changes or adding software to Lakka. The notes assume that Lakka is run on at least a Raspberry Pi Zero such that all other designs should be compatible - Lakka bundles RetroArch and the most common Raspberry Pi, at the time of writing, is the Raspberry Pi 3 with ongoing support for the Rapsberry Pi 4.
Depending on the Raspberry Pi model and the available RAM, the splitting of shared RAM between the CPU and the GPU can be adjusted. Notably, the Raspberry Pi 4 can reach up to 4GiB
and, out of the box, Lakka seems to allocate 256MiB
to the GPU. This can be verified by issuing the command:
# vcgencmd get_mem gpu
which should output:
gpu=256M
The allocation can be increased by re-mounting the Lakka /flash
filesystem in writable mode:
mount -o remount,rw /flash
commenting out all the automatic split:
# Configure GPU memory based on SDRAM size - overrides above setting # gpu_mem_256=112 # gpu_mem_512=160 # gpu_mem_1024=256
and setting:
gpu_mem=512
As per the Raspberry Pi documentation, values over 512
do nothing and should not be used such that 512
is the maximum possible. In fact, setting gpu_mem
to anything above 512
seems to boot Lakka without RetroArch being able to start.
On the Raspberry Pi 4, a quick inspection of the boot messages indicate that the Raspberry Pi is running out of entropy:
random: crng init done random: 7 urandom warning(s) missed due to ratelimiting
Indeed, a closer look at the available entropy indicates a very low value:
# cat /proc/sys/kernel/random/entropy_avail 45
which tends to slowly increase.
This seems to be a common issue to all Raspberry Pi devices under Raspbian even though most Raspberry Pi models do benefit from a hardware random number generator.
To enable the hardware random number generator on Lakka, download a statically compiled version of rng-tools, extract the contents, and place the files from the archive to match the following structure:
/storage + | + .local/ + | + sbin | + | | | + rngd | + bin + | + rngtest
Then, edit or create /storage/.config/autostart.sh
to include the following line:
/storage/.local/sbin/rngd -o /dev/random -r /dev/hwrng
and reboot the Raspberry.
If all goes well, and the rngd
daemon was started, then issuing dmesg
to show the kernel messages should not contain a line complaining about urandom
. Furthermore, checking the available entropy should show a much larger value:
# cat /proc/sys/kernel/random/entropy_avail 1904
right from the start.
When a program needs random numbers, and is using a hardware source, if there is little or no available entropy, the program will have to stall till enough entropy builds up. All programs and perhaps, particularly games, need a good source of entropy to pull random numbers such that this addition can only be beneficial.
Preload is a program written by Behdad Esfahbod and uses Markov chains to keep track of program utilization in order to load frequently used programs into RAM for faster access times and lower disk usage.
A statically compiled preload daemon can be downloaded and added to Lakka. With the zip extracted, the files should be placed using the following filesystem arrangement:
/storage + | + .local/ | + | | | + usr/ | + | | | + sbin/ | + | | | + preload | + .config + | + etc/ + | + preload.conf
All the other files in the zip archive are not required.
Finally, add or create /storage/.config/autostart.sh
in order to include the line:
/storage/.local/usr/sbin/preload -c /storage/.config/preload.conf -s /storage/.local/var/lib/preload/preload.state -l /dev/null
such that the preload
daemon will be started on boot.