Tiny Core - a very small linux distribution for the Raspberry PI (piCore)

Recently, I searched for a very small linux distribution for my Raspberry PI Zero. I wanted to build a small camera project which demands a very fast boot process. I searched for that in the internet and then I came to Tiny Core, a linux distribution that promised everything I need for that. I tried it out and I was so surprised, that I wanted to write a small how-to here, that describes how easy it is to set up and get things running.

Setup

The setup procedure is comparable to e.g. a raspbian installation. First download the latest release of piCore from here.

The image can be installed on a microSD card with dd. However, since I had several problems with that, I think a more convenient way to install the image with etcher. It is a really cool tool with a graphical user interface and more important it worked for me every single time. Etcher can be downloaded here, select the image and the drive and piCore is ready to be used.

But wait! We first have to do some more setup things. So boot your new SD-card with the Raspberry PI. The shell has an auto login for user tc. There is no root user access, but sudo can be used for having root access. First we have to expand the filesystem. This is necessary because the copied image has a fixed size (which is probably not the size of the used microSD card). To make use of the whole card, we have to expand the second partition. This is the user partition, where we can store our data later. Execute fdisk with:

sudo fdisk -u /dev/mmcblk0

Press p to print the partitions. Write down the starting sector of the second partition. Delete the second partition with the d command and recreate it with the n command. It should have the same starting sector as before. As the end sector I used the default one which is the last sector available. This enlarges the partition over the whole empty space. Save the changes by typing the w command and exit fdisk. Reboot the Raspberry Pi and execute

resize2fs /dev/mmcblk0p2 

to expand the file system on the new partition. Now we are ready to go!

Tiny Core Package Manager

The package manager is comparable to other linux distributions. Packages are also called extensions. You can easily install any package with

tce-load -wi <package_name>

The first thing I do is to install a simple text editor called nano:

tce-load -wi nano

You can then execute the nano executable. A list of all available extensions can be found here.

Graphical User Interface

The piCore's graphical user interface is called TC and can be installed with:

tce-load -wi TC.tcz

After installing TC, the graphical user interface can be started as usual with the startx command.

I also like to install my favorite text editor geany and a very small tiny browser dillo for goggle something:

tce-load -wi geany
tce-load -wi dillo3

Persistence

One big difference of tinyCore to other linux distributions is that everything is loaded into ram at boot. So after installing a package with tce-load, it is loaded into ram, which slows down the boot process.

So in my case I only need the graphical user interface sometimes and I do not want it to be loaded at boot. To prevent that to happen, you can edit the onboot.lst textfile with:

sudo nano /etc/sysconfig/tcedir/onboot.lst

and comment out the corresponding packages. To run them at a later time, just call:

tce-load -i <extension_name>

However, a downside of this persistency is that all files you edit have to be also backuped to be persistent after reboot. To do this just call:

sudo filetool.sh -b

A list of files that are backed up with the command above can be seen and of course extended by adding them to another config file:

sudo nano /opt/.filetool.lst

Connect to WIFI network

To enable wifi, you first have to install wpa_supplicant with:

tce-load -wi wpa_supplicant
tce-load -wi wifi

With a call to

wpa_passphrase <ssid> <password>

you can generate a wpa_passphrase. Now you can create the file /opt/wpa_configure.conf with the following content:

network={
    ssid="<ssid>"
    proto=WPA
    key_mgmt=WPA-PSK
    pairwise=TKIP
    group=TKIP
    psk=<psk>
}

Just insert the ssid and the generated psk in here.

Add the line opt/wpa_configure.conf to /opt/.filetool.lst to add this file to the backup list. Call filetool.sh -b to save everything.

To check if the connection works, execute:

sudo wpa_supplicant -i wlan0 -c /opt/wpa_configure.conf &
sudo udhcpc -i wlan0

If that works, congratulations!

Auto-connect at boot

To connect at boot, you have to add the following lines to /opt/bootlocal.sh

wpa_supplicant -i wlan0 -c /opt/wpa_configure.conf &
udhcpc -i wlan0

Add the line opt/bootlocal.sh to /opt/.filetool.lst to back it up with filetool.sh -b. Now the connection should be established at boot. Reboot with:

sudo reboot

Check the connection at any time with ifconfig and iwconfig.

Using Python3

I like to use Python3 for programming e.g. the GPIOs of the raspberry pi. The installation of python3 is fairly simple:

tce-load -wi compiletc python3.6-dev squashfs-tools

This also installs pip with which you can install python packages. Unfortunately these installed packages are deleted after reboot, since they are installed in non-persistent places. This can be fixed by passing the installation path to the pip command with --prefix.

But first, create a directory for the packages on the second partition of the sdcard. The second partition is mounted at /mnt/mmcblk0p2/. We create a directory vol with:

mkdir /mnt/mmcblk0p2/vol

We can then install a package into that directory using pip:

pip install numpy --prefix /mnt/mmcblk0p2/vol

We can then use the python package by adding our directory to the PYTHONPATH environment variable.

export PYTHONPATH=/mnt/mmcblk0p2/vol/lib/python3.6/site-packages:$PYTHONPATH

If we install binaries we can also append the bin directory to PATH:

export PATH=/mnt/mmcblk0p2/vol/bin:$PATH

Conclusion

If you want to work with graphical user interfaces and do much coding, surfing or writing directly on the raspberry pi I would rather recommend a distribution like raspbian since it is more convenient to use. However, for small embedded projects which demands fast startup time, less space or a perfect control I can definitely recommend piCore. It definitely takes some time to get into the concepts of piCore but if you get used to it, I think it is a beautiful, little, fast, purist linux distro, which is perfectly for all kinds of projects.

comments

ohh there are no comments yet, be the first!

recent posts

2019-02-27 in off topic
Determining the total revenue of a blackmailer: Bitcoin is offering new possiblities
2019-02-21 in photography
Skyline Frankfurt
2019-02-19 in photography
Old train station Löhne
2019-02-15 in maker space
Tiny Core - a very small linux distribution for the Raspberry PI (piCore)
2019-02-13 in data science
Smith Waterman Distance for feature extraction in NLP

about me

I am a PhD-student from Frankfurt in Germany. My research topics are machine learning and human robot interaction. More precisely I work on active learning and cooperative intelligence in task completion right now.

In my free time I like to make things. Some of them are tech related, but others are not. I am also interested in programming, web-programming, robotics and drones, IoT, photography and making delicious filter coffee or espresso. Last but not least I am a big fan and collector of retro video games, especially N64 and SNES. You can take a look at my complete collection.

just me