Wednesday, November 27, 2013

Your own official Linux distro in a SD card (for ARM)

Currently for us, owners of ARM devices of the Rockchip family (though this post applies to any ARM CPU), when wanting to boot Linux we have to do two things:

1) Flash a Linux kernel, usually to recovery, in order to be able to boot to Linux
2) Copy a Linux Root File System (RFS) into a MicroSD card for the OS to boot from

This post is about Step 2.

Why can't we use official distributions?

Basically because most distros are [easily] available for x86 CPUs (x86, amd64, ...), not ARM CPUs (armel, armhf). And then, when you find it compiled for ARM, there are some little extras to be done, like copying your kernel's modules into it, and throwing it all into a MicroSD card.

Hence, we are currently forced to choose among static RFS that fellow developers have made available and can update only on their free time, which isn't much. These are:

- Picuntu, from Alok Sinha
- Ubuntu 12.10 RFS, from linuxium
-, from JustinTime4Tea

These RFS are all just the Ubuntu distribution, sometimes with a different name (Xubuntu in the case of Picuntu, Ubuntu in the case of, though they usually include extras like:

- The modules (drivers) for many devices (needed for many, but not all, USB gadgets)
- The Flash video ARM support solution I posted here

However let's face it, you are forced to use Ubuntu, and then you depend on the maintainer's free time to grab the latest version of Ubuntu, add the above extras and publish it so you can use it.

Your own Linux distribution's RFS

Here I am going to show how to create your own RFS by grabbing whatever version of Ubuntu (and with few changes any other distro, like Arch Linux, OpenSUSE, CentOS, just click on the link to be taken to the specific distro's instructions), and create a RFS to use on a MicroSD card to boot Linux your ARM stick/box. Or to flash the same RFS into your device's Nand Flash chip and avoid the SD card altogether.

Getting an up-to-date official distribution, for ARM

The first thing is getting the Linux distribution (all the programs that make up your booted up Linux: from the "ls" commandline, to the GNOME desktop and the LibreOffice suite) already compiled for ARM devices, instead of the usual x86 for PCs.

This is not difficult since, actually, Linaro is doing just that!
If you want a desktop environment (XFCE, Gnome, KDE, etc.) you have two options:

Option 1) Easy way: (Older version but everything done) Head over to:
Look for "Ubuntu Desktop" in the "Developers and Community Builds" section and click on any of the boards that support it on the right (Origen, Panda, etc. doesn't matter). At the time of writing (Nov 2013) this will redirect you to this page:
So the latest version with the desktop already installed is Ubuntu 12.11, you'll have to install this one in your SD and upgrade to the latest version after booting. Download the biggest .tar.gz file, in my case 473 MB of:
Option 2) Manual way (Newer version, but starts with a commandline Linux): You can get the cutting edge latest version of Ubuntu, it will be small and fast but you'll have to type a few more commands, after booting it, in order to install a desktop. Go here:
And click in the folder link of the latest version number ("13.11" for me). A new page appears where you have to select "ubuntu", in the next page select the link that ends in "-images" (prefix depends on Ubuntu's version name, in this case it's "raring-images"), and finally select the version link that you want (nano / developer / server) to get its .tar.gz file.

All three are the same Linux but each one with different sets of packages already installed. They are:

- nano (around 50 MB) gives you a command-line with very very few things (not even a vi/vim/nano editor!), with this version you'll need a network connection (care for /etc/network/interfaces and such) soon enough, to start cranking "apt-get install" for all the little apps.

- developer (around 140 MB) a usable command-line with most things you'll need to comfortably start working and changing whatever configuration. However, IMHO, it includes many packages for software development, while lacking some others more typical of a generic user system.

- server (around 130 MB) a usable command-line with all you need for a quick setup of a desktop environment resembling a PC with Ubuntu. Even if you are a developer you can later install all the packages you need. This is the one I recommend.

N.B.: Compare the *.packages files to get a glimpse for yourself of what's inside each version.

So, following the recommendation we would download this file for the latest Ubuntu 13.11 (Nov 2013, or else go into the page above and get yourself the latest and very best.

Getting the RFS into the MicroSD card (or flash)

First of all introduce the MicroSD card into your PC to partition it in the way that the kernel expects it (please don't use partition utilities, they won't do it!).

Let's say that the MicroSD appears at the folder "/mnt/whatever_folder", then type the following command to know the device name:
df -h | grep whatever_folder
You should see a line somewhat like this:
/dev/sdg1   7,3G   612M  6,4G   9% /mnt/whatever_folder
Now that we know the MicroSD is in "/dev/sdg" (remove the number!!) unmount the MicroSD:
sudo umount /mnt/whatever_folder
And the most important step to avoid later problems: partition & format in this one step:
mkfs.ext4 -F -L linuxroot /dev/sdg
Which labels it "linuxroot" and at "/dev/mmcblk0", where the kernel expects it (CMDLINE), instead of where a partition tool would place it (at "/dev/mmcblk0p1").

If you want your RFS to be in your device's Flash chip, and 1) have flashed the right parms, 2) have a kernel with the right CMDLINE for those parms, 3) the kernel has an initramfs.cpio with rknand...ko, then the you have to format it with this command: "mkfs.ext4 /dev/mtdblock0" (mtdblock number is that of your [big] partition).

It may take a couple minutes and when finished you should mount it and start following these steps:

1) Become root (necessary to keep file permissions in the RFS!)
sudo su -
2) Go to the folder where the SD card (or flash) is mounted:
cd /mnt/whatever_folder
3) Extract the downloaded ARM RFS in it:
tar xvfz /home/username/Downloads/linaro-raring-server-20131124-562.tar.gz
4) Since the Linaro .tar.gz contains the RFS inside a folder named "binary", we have to move its contents to the real root of the SD card and then remove the, now empty, "binary" folder:
mv binary/* .
rmdir binary
5) If you are doing this process on a PC, you have to uncompress the modules+firmware file (that came with the kernel you flashed into your stick) into the "/mnt/whatever_folder/lib/" folder.

Or, if you are on an ARM stick, you can just copy your own modules (drivers) and firmware to the new RFS so you have everything from the beginning:
mkdir ./lib/modules
cp -R /lib/modules/* ./lib/modules
cp -R /lib/firmware/* ./lib/firmware
And it won't hurt to copy the library for playing Adobe Flash videos (think YouTube) in ARM (and all the Flash ads and websites, of course):
cp /usr/lib/ ./usr/lib/
If you didn't have it, follow this quick post.

6) You may also want to "touch" certain files to make sure networking works out of the box. For example, if you have an Ethernet connection in your ARM device, then modify the /mnt/whatever_folder/etc/network/interfaces file to add these lines:
auto eth0
iface eth0 inet dhcp
7) It's always a good idea to end operations with this command (to finish all write operations):

You can unmount that MicroSD, because it's ready to boot. If you installed the desktop version the easy way, that's it.
However, if you installed a trimmed commandline version the manual way, you should continue reading the following section.

Getting a desktop environment

Once you boot your device with the created MicroSD card, your first task is to check the network connection. For example type:
apt-get update
If the software repositories start updating, you're good to go. If there is no connectivity: Internet is full of Q&A about networking in Linux :)

Now, with Internet on, in order to install a desktop environment, in my case XFCE (the one used in Xubuntu), I would just type this:
apt-get install xubuntu-desktop
And when asked, say Yes to downloading >400 MB of packages that will use up >1 GB of space when installed, but will land me on the very latest desktop environment for an ARM PC, whatever your CPU (Rockchip, Allwinner, Samsung, ...).

Sorry if it took too long to explain something that is actually simple, but everybody is welcome!
The more users discover that a tiny and cheap stick/TV-box is actually a full-fledged low to mid-end PC (without the noise, size, and the Watts!), the better for all!


  1. Great article . Thanks a lot ..
    It will be great if you give us some basics of kernel and other things required to make a mini pc.

  2. Great!

    However, I am using your 3.0.36+ kernel, which does not support the Realtek 8188CUS adapter. I have been running in circles trying to get the correct firmware and modules for it. I have the drivers from Realtek, but cannot compile due to missing dependancies, which I cannot update cuz the MK808B is not on the internet!

    Please advise,

  3. Thanks Galland, for a very lucid description. I have already used it to prepare an RFS for a new MK908 that I ordered recently. I plan to use your "unofficial" 3.0.36+ kernel (24May13) unless you can recommend a better one. Thanks again.

    1. Thanks :) though the May-post kernel is for rk3066 devices.
      In the case of the MK908 (rk3188 with HDMI output at LCDC0) you can download this recovery image (no wifi):

      For other rk3188 sticks (that have the HDMI output at LCDC1 cpu pins) it's ok to use the recovery from the Linux on Radxa blog-post from Oct.

      Sorry about the missing Wifi, it's a total PITA to get it up and running, and every stick/box has a different one, so I always use an external USB wifi or ethernet.

    2. modules and firmware:

    3. I was unsuccessful with the above Linux kernel for MK908. My stick is an MK908 V5.0 with Finless 1.7 installed and operating fine, installed by use of ROM_Flash_Tool_137.exe. I flashed the Linux kernel using the same tool to direct the recovery.img to address 0x00012000. From the Finless 1.7 Android, when I execute "reboot recovery" the video signal disappears, permanently until a reboot.

    4. hmmm bizarre, my mk908 is v3, maybe yours has the hdmi in the other lcdc. Can you test the recovery kernel in the October post named: "Booting Linux on Radxa Rock"?

    5. Yes. Tried that with the same result so I decided to reassign the MK908 as a Christmas gift. I'll pursue my Picuntu installation goals using an MK808 that I had originally intended to be the Christmas gift. Many thanks for your response and tireless work!

    6. Installation to MK808 was successful and I installed xubuntu-desktop but when I tried "startx" the command was not found. How does one start the GUI?

  4. Great help - could do it on my mk808 without problem - thanks thanks thanks

  5. Great Explication! Thanks a lot for it :)


  6. This comment has been removed by the author.

  7. I have a Picuntu RC3 on a UG802 I update trough "dist upgrade" to Ubuntu 13.10 without problems but the kernel remain the original from Picuntu. I try to flash your 3.0.36+ kernel but the device wont start.
    Thanks for all. Gracias amigo. Picuntu on my blog

  8. I prepared an ArchLinuxARM rootfs which can be downloaded from here:

    It works fine with the RK3188 kernel from Galland - on a Radxa Rock - but there are the following issues:

    1. The console (not the one under X/KDE) keeps popping out messages about DWG-OTG which are quite annoying.
    2. The display on my HDMI TV is way too 'zoomed' in.

    Do you have any proposals for these issues?

    1. 1. That is related to ArchLinux console configuration, you'll have to tweak that somewhere, since for other RFS those messages go to the kernel log, and not to the console.

      2. I'd say that's related to your TV. Or, if you're using the 720p kernel, you may be better off with the 1080p one.

    2. Thanks for the answers.

      Another question: does your current Linux3188 tree support building Mali drivers (Kernel, UMP and DRI) for Radxa Rock? I've enabled them to build their modules and they compile fine but kernel reboots right after loading.

    3. That's unfinished work, you should leave them out of your .config, sorry.

  9. Thanks Galland. It is really a good article.

    I have MK808B device with me.
    I followed this and prepared linaro RFS 12.04 desktop-precise. I flashed the kernel follwing your previous post Also copied modules on the linaro RFS.

    Basically i want to build v4l2loopback ( support on MK808B.

    Isuue that i am facing right now is of display and graphics the desktop does not appears properly on the TV screen. It only covers half of the screen with distorted colors.

    Would really appreciate your suggestions

    1. Yes, I have this exact same problem, with the 1080 kernel

  10. I tried to prepare an RFS the Option 1) Easy way but, after I extracted from the compressed tar file (using tar xfvz) the RFS was not contained in the binary folder. Instead, the binary folder contained a boot folder which contained a filesystem.dir folder which contained what seemed to be an RFS but I was not able to use it.

  11. Hi Galland, "modules and firmware:" - will this work for Radxa Rock as well, or where to get Radxa Rock Modules&Firmware ?

  12. They're at the bottom of the "Booting Linux on Radxa Rock" post

  13. I have done everything but my mk908 V5 starts with android and not ubuntu.
    You wrote "4) Since the Linaro .tar.gz contains the RFS inside a folder named "binary", we have to move its contents to the real root of the SD card and then remove the, now empty, "binary" folder:"
    ok done, in binary there is a folder "boot" (now moved to sdcart root) and inside it, filesystem.dir folder. Is it ok or i nead to move content of this folder on sdcard root?

  14. I am a bit confused about instruction for inserting modules and firmware.

    Or, if you are on an ARM stick, you can just copy your own modules (drivers) and firmware to the new RFS so you have everything from the beginning:
    mkdir ./lib/modules
    cp -R /lib/modules/* ./lib/modules
    cp -R /lib/firmware/* ./lib/firmware

    I have kernel in device ROM. Then when I start ARM device the boot process start Linux system from SD. Did you mean that “firmware and modules” from kernel were copied into /lib/ subfolders on the SD card during system startup?

  15. you have to copy the appropriate mod+fw for your specific kernel into your rfs before booting it

  16. Thank you for a glimpse of hope. Since so far I worked mostly on XP I am not familiar with Linux. At the begging the dot (.) was meaningless and after copping the files to appropriately formatted card the system never started. The same happened with tar. I had to use it with sudo and change the direction of parameters to xzfv otherwise it did not work well. Those two steps took me few days to understand but I am making progress. The system starts without firmware and modules anyway since some are perhaps placed in kernel. For peripherals like wifi I have plans to follow Jan Morrison instructions. Unfortunately the main problem (random freeze and restart) is present even when I am using server without GUI although much less frequently. May be the problems is in kernel although it worked for others with MK802IV (kernel is from Jan Morrison). JP

  17. Hi all
    using aloks kernel x.x.36+ on MK808 device, i try working with linaro-raring-server-20131124-562 and previous sd-card images. In kernel-mode (mc, nano etc.) display is full hd @60Hz full screen and clear. Installing any! graphical desktop ends up in a split and distorted screen. xrandr shows vertical refresh of 69.9Hz. Way off for my flatscreen. Where is this dafault set? and can i edit in workig values?
    Gtf, xrandr and xorg.conf will not change anything. putting in values in xx/lxsession/xx/autostart neither. So i am at an dead end here, hoping for your assitance.
    Best regards

  18. Sorry for bothering you!
    Didnt install mali400 drivers...
    Getting old, I guess...

  19. Nice guide, but how to make a flashable system.img?!

  20. WOW! Thank you so much for all your time and hard work! I can't wait to give this all a try tomorrow! This is exactly what I've been looking for. My only question is can you link me to where I can just get a bit more information about this part (or a link is fine):

    "If you want your RFS to be in your device's Flash chip, and 1) have flashed the right parms, 2) have a kernel with the right CMDLINE for those parms, 3) the kernel has an initramfs.cpio with rknand...ko, then the you have to format it with this command: "mkfs.ext4 /dev/mtdblock0" (mtdblock number is that of your [big] partition)."

  21. Sorry for my bad english. I have a Minix X5 and after follow the instructions i don´t get boot. Anybody has tried the installation in this stb?

    1. I don't think the problem is in using a new distro as described in this post. You should first get a Linux kernel that works for the X5 (RK3066) and then get on to this post.

    2. Thanks Galland. May be that i must change the bootloader and for this thing the minix don't boot?

      Many thanks in advanced. (sorry for my horrible english ; ) )

  22. I know this is very old, but Im trying to put linux on my RK3168 tablet, but afeter flashing the kernel into the recovery partition and rebooting I just get a black screen. I guess the rk3066 or rk3068 kernels are not compayible with the rk3168 cpu?

    I have the kernel sources of my device, can you guide me for compiling this kernel for linux?