This series of blog posts contains the following parts:
3. Debian Root File System (This part)
Part 3: Debian
So in this part we´ll create a debian file system completely from scratch.
You´re asking why you should do this, since there are downloadable images?
Well the reason I prefer this method is the following:
You can download a prebuilt image. But this image is most likely absolutely minimal.
There is nothing installed but the rare minimum so debian can start and work.
If you then use this image on the RIoTBoard you have to install everything directly on the board.
And depending on what you want to install, this can take a really long time.
If you´re installing a bigger desktop for example, this can take several hours.
But this method uses an emulator (qemu) to emulate an arm system on your x86 or x64 machine.
With this you can install everything you need right before even putting the image on the RIoTBoard.
And that´s a lot faster than to do this directly on the board.
For those who want a minimal image.
You can skip this step and just download one from http://www.armhf.com/
If needed they also have Ubuntu images there.
(Look in the download section for "Root File System")
Everyone else can follow these steps.
(Please note that this most likely won´t work on a virtual root server, since the kernels of these don´t provide proper chroot functionality. At least mine didn´t.)
Now let´s start.
Make sure you´re in the folder where you will save everything like in the previous parts of this series.
In my case:
Get the needed packages.
apt-get install qemu-user-static debootstrap binfmt-support
Set some environment variables for the folder and the distro we want. Then create the directory and download the basic Debian system files.
At this point we only download the package files into the folder we defined.
(The distro used here is Debian "wheezy". In theory you can also use Debian "jessie". But I haven´t tested that at this point.)
export targetdir=rootfs export distro=jessie mkdir $targetdir debootstrap --arch=armhf --foreign $distro $targetdir
Copy the qemu-arm-static-binary and the resolv.conf from your host into the created system folder.
This is needed so qemu can be startet within that folder.
The resolv.conf is needed, so we know which DNS Server to use because we need an internet connection inside the new system.
Normally it is created over DHCP. But since we haven´t done any network configuration yet, we have to use the same one as the one from the host.
cp /usr/bin/qemu-arm-static $targetdir/usr/bin/ cp /etc/resolv.conf $targetdir/etc
Now step into the new created system, and start configuring it from the inside.
That´s easily done by just chrooting into the folder.
In the new rootfs system we need to set some variables again.
export distro=jessie export LANG=C
By now we only downloaded the packages. But for installing them we need an ARM cpu.
Since the host is at x86 or x64 that wouldn´t work.
Luckily debootstrap has a function for that called second stage.
At this point we basically have a fresh fully installed debian system, that can be booted.
But only botting it won´t do much.
We have to configure some more stuff, so we also can use it.
We want to install stuff inside the new system over apt.
So we need a sources.list and some other settings
Change the locale in the URLs in the following script to the locale you want.
cat <<EOT > /etc/apt/sources.list deb http://ftp.de.debian.org/debian $distro main contrib non-free deb-src http://ftp.de.debian.org/debian $distro main contrib non-free deb http://ftp.de.debian.org/debian $distro-updates main contrib non-free deb-src http://ftp.de.debian.org/debian $distro-updates main contrib non-free deb http://security.debian.org/debian-security $distro/updates main contrib non-free deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free EOT cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends APT::Install-Recommends "0"; APT::Install-Suggests "0"; EOT
Update apt now.
(You´ll get some ignored lines because we didn´t setup the locales by now.)
Setup the missing locales and update again.
When the dialog comes up, select the locale you want.
I´m using "de_DE.UTF8". (Obviously)
apt-get install locales dialog dpkg-reconfigure locales apt-get update
Set the root password.
Don´t miss this step. Or your image will be useless since you can´t even login.
We need a network connection of course.
At this point you can also define wireless connections.
For other configurations, like a fixed IP, just google the how to do that in Linux.
There are a lot of explanations to find on this.
But in my example I only configure DHCP on eth0.
echo <<EOT >> /etc/network/interfaces allow-hotplug eth0 iface eth0 inet dhcp EOT
We need a hostname. (The name the board is reached in the network)
Just change "riotboard" to what you want.
echo riotboard > /etc/hostname
Step 13. (Obsolete in Debian 8 with Systemd)
Skip this step with Debian Jessie!
We want to access the riotboard over the serial port. (UART connection on J18)
The place to do this is the file "/etc/inittab".
Looking into that file, we find some examples on how to do that.
# Example how to put a getty on a serial line (for a terminal)
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
The serial port is accessed through "ttymxc1" and the standard baudrate is 115200.
So we execute this command to insert a line at the end of inittab.
echo T0:2345:respawn:/sbin/getty -L ttymxc1 115200 vt100 >> /etc/inittab
We now have a fully running minimal image of debian.
At this point you can install everything you want over apt.
And I always advise to install some usefull stuff like this.
apt-get install openssh-server ntpdate
Now after installing everything here is a little tip to reduce the size of the system.
This only removes the downloaded packages for installing everything.
We don´t need them anymore since everything is already installed.
In this case here this reduces the size from around 150 MB to about 89 MB.
Now that we configured everything inside the system, we can quit the chroot shell and get back into our hosts shell.
Because we don´t need to emulate ARM in an ARM system, we remove qemu as well as the resolv.conf we copied earlier into the new system.
rm $targetdir/usr/bin/qemu-arm-static rm $targetdir/etc/resolv.conf
Everything we now need to do is just put all the files into a tarball.
So get into the folder and pack everything in a package.
By the way:
Notice the parameter p in the tar command. This means the permissions stay like they are on all files and folders inside the new tarball.
This is very important! If you miss that you will have a lot of problems with false set permissions on all system files.
cd $targetdir tar cvzpf oneiric.tgz *
Now we have a file called oneiric.tgz.
Copy this file into our output folder where our other stuff is lying, so we find it again.
cp oneiric.tgz /home/riotboard/linux/output/oneiric.tgz
This file we now can use to flash our system on the board.
And that´s it for this part.
In the next part we will be putting everything together to get it running on the board with Windows and MFGTool.