One of our customers asked us how to install the VirtualHub on the Tiny Core Linux distribution. To be honest, we had never heard of this distribution, but we discovered that this distribution made interesting technical choices. Thus, we are going to show you how to install the VirtualHub, or your own application, on Tiny Core Linux.
The Tiny Core Linux distribution is very different from classic distributions such as Ubuntu or Debian. First, this distribution is extremely compact. A standard installation contains only about ten megabytes. Second, Tiny Core doesn't use the machine's hard disk (or the SD card) directly, but a RAM drive.
A RAM drive is a virtual disk which uses part of the RAM to work. When booting, this virtual disk is initialized with the data of the physical drive, but then the physical drive is not used anymore. The advantage of this system is that the RAM memory is much faster than a hard disk. This allows for a very quick installation.
This choice has important consequences, because the RAM memory is not persistent. Therefore, all the modifications performed on the files of this RAM drive are lost at each reboot! For an office computer, this mechanism doesn't make any sense. Indeed, what would be the use of a computer which loses all of its documents each time it is turned off ...
However, in some scenarios, this limitation can become a true advantage, for example for interactive terminals or dedicated applications. This guarantees that the system starts correctly whatever happens. An application crashes, a virus is installed, the user corrupted files? Simply reboot.
The other advantage is that it allows you to avoid issues of corrupted hard disks in the event of a power failure. Indeed, as there is no implicit write access on the hard disk, the latter doesn't risk to find itself only half written. This latter advantage is particularly interesting when you work with a Raspberry Pi which is powered from a battery.
We are going to see how to install the VirtualHub on a Raspberry Pi with the Tiny Core Linux distribution.
The first step is naturally to install Tiny Core Linux on the Raspberry Pi. The process is documented on the web site, but broadly speaking, it boils down to the following steps:
- Download the image from the web site
- Write the .img file on an SD card with the dd tool or an equivalent
- Boot the Raspberry Pi
- Save the SSH configuration with the command filetool.sh -b
- Possibly adapt the size of the partition of the SD card
To install the VirtualHub on Tiny Core, or any other application, we can't use the usual process. If you download the VirtualHub and if you install it directly in the /usr/sbin directory, it will work correctly at first, but it's going to disappear when you next reboot because it is not installed on the hard disk but on the RAM drive.
To permanently install an application on Tiny Core, you must create a tcz package and register it in the list of packages which are added to the RAM drive when booting.
Creating the VirtualHub package
Creating the package is rather simple. You must download the VirtualHub from our web site and unzip the archive on your Tiny Core system.
tc@box:~$ wget http://www.yoctopuce.com/FR/downloads/VirtualHub.linux.38634.zip Connecting to www.yoctopuce.com (126.96.36.199:80) VirtualHub.linux.386 100% |*********************************************************************| 4492k 0:00:00 ETA tc@box:~$ unzip VirtualHub.linux.38634.zip Archive: VirtualHub.linux.38634.zip inflating: mips/VirtualHub inflating: LISEZMOI.txt inflating: README.txt inflating: armel/VirtualHub inflating: RELEASE.txt inflating: FILES.txt inflating: aarch64/VirtualHub inflating: startup_script/yVirtualHub inflating: startup_script/yvirtualhub.service inflating: startup_script/yvirtualhub.openwrt inflating: udev_conf/51-yoctopuce_all.rules inflating: udev_conf/51-yoctopuce_group.rules inflating: 32bits/VirtualHub inflating: 64bits/VirtualHub inflating: armhf/VirtualHub inflating: mipsel/VirtualHub tc@box:~$
A tcz package is in fact a file image to be copied in the RAM drive.
To create this image, you must create a virtualhub directory and then copy inside the files that you want to install.
Beware, you can't copy the files at the root of this directory, you must copy them in a subdirectory equivalent to the location where the files must be installed. In our example, we want the VirtualHub executable file to be installed in the /usr/sbin directory, so we must create a virtualhub/usr/sbin subdirectory and copy the executable file in this directory.
Here are the commands to create the subdirectories and to copy the armhf version of the VirtualHub and the Udev rule authorizing all the users to access Yoctopuce modules.
mkdir virtualhub mkdir -p virtualhub/usr/sbin mkdir -p virtualhub/etc/udev/rules.d cp armhf/VirtualHub virtualhub/usr/sbin/ chmod +x virtualhub/usr/sbin/VirtualHub cp udev_conf/51-yoctopuce_all.rules virtualhub/etc/udev/rules.d/
Now that the virtualhub directory contains the VirtualHub executable and the Udev rule, you must create the virtualhub.tcz file with the following command:
mksquashfs virtualhub virtualhub.tcz -b 4k -no-xattrs
Installing the VirtualHub package
When the virtualhub.tcz file has been created, you must render it persistent. Indeed, this files is currently still stored on the RAM drive and therefore lost if the machine restarts. To install it definitively, you must copy it on the hard disk and add it on the list of packages loaded when the OS starts.
To do so, you must copy the package in the /etc/sysconfig/tcedir/optional/ subdirectory and add a line with the name of the package in the /etc/sysconfig/tcedir/onboot.lst file.
cp virtualhub.tcz /etc/sysconfig/tcedir/optional/ echo virtualhub.tcz >> /etc/sysconfig/tcedir/onboot.lst
The package is now stored permanently on the hard drive (the SD card in the present instance) as the /sysconfig/tcedir directory is mapped on the hard disk.
You can now restart your machine and check that you can run the VirtualHub.
When the package is installed, the VirtualHub is available
Saving the configuration
The interest of this distribution is that the modifications are not written on the hard disk. This enables the system to come back to a stable and known state by restarting the machine.
There are however situations in which you want to save these modifications. For example, if you have configured an HTTP callback with the VirtualHub, you wouldn't want this modification to disappear at the next reboot.
It's the job of the backup command, enabling you to save changes performed in the /home and /opt directories.
So, if you change the configuration of the VirtualHub with the web interface, don't forget to log in on the machine and to run the backup command to make these changes permanent.
The backup command enables you to save the changes
A few comments
Some Tiny Core images don't contain by default the libUSB library. If, when you launch the VirtualHub, you obtain the error: "VirtualHub: error while loading shared libraries: libusb-1.0.so.0", then you must install this library with the following command:
tce-load -iw libusb
To automatically start the VirtualHub when booting the system, don't use the startup scripts provided with the VirtualHub. Indeed, Tiny Core simplified startup scripts and our systemd and System V scripts do not work.
The solution is to simply add the "VirtualHub -d" line at the end of the /opt/bootlocal.sh file. Then you must call the backup command to save this change on the hard disk.
echo "VirtualHub -d" >>/opt/bootlocal.sh backup
Tiny Core Linux is a very specific distribution which adds its share of complexity but which in return enables you to have a very robust system which starts very very fast.
In this post, we showed you how to install the VirtualHub on Tiny Core, but if you consider to use it, we recommend that you read the documentation which explains in details how this very particular distribution works.