Step 1: Partition and Formatting the SD Card

There are many different ways you can go about partitioning your SD Card. Here I will show you the easiest I found.

Insert your SD Card into the SD Card reader.

Press the Home key, type in Disks and open the application.

Find your SD Card on the list and make a note where the device is mounted (Eg. Device /dev/mmcblk0) , you will need this later.

Open Terminal (Ctrl + Alt + T)

# fdisk /dev/sdX

Check if there are any existing partitions on the card by typing in

Command (m for help): p

Optional: Delete all partitions on the SD Card by entering "d" to delete the partition.

Command (m for help): d

Enter "1" for the first partition on the SD Card.

Selected partition 1
Partition 1 is deleted

Do this for each partition.

Create the first partition, starting from 2048.

Enter "n" for New Partition.

Command (m for help): n

Enter "p" for Primary.

Command action
   l   logical (5 or over)
   p   primary partition (1-4)

Enter 2048 or simply {Press Enter}.

First sector (...-..., default 2048): {Press Enter}
Using default value 2048

This partition needs to be 16M from the start of the SD Card.
Enter "+16M".

Last sector, +sectors or +size(K,M,G) : +16M

Now, do the same thing but create a second partition filling the remainder of the SD Card.

Enter "n" for New Partition.

Command (m for help): n

Enter "p" for Primary.

Command action
   l   logical (5 or over)
   p   primary partition (1-4)

{Press Enter} for default.

First sector (...-..., default 2048): {Press Enter}
Using default value 2048

{Press Enter} for default.

Last sector, +sectors or +size(K,M,G) : {Press Enter}

Now check your partition structure to make sure it is correct.

Command (m for help): p

If everything went accordingly, you should see something similar like:

Disk /dev/sdg: 3980 MB, 3980394496 bytes
123 heads, 62 sectors/track, 1019 cylinders, total 7774208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdg1 2048 34815 16384 83 Linux
/dev/sdg2 34816 7774207 3869696 83 Linux

Write the changes to the SD Card by typing "w" and {Press Enter}

Command (m for help): w

The partitions are made, now we need to format the partitions to the correct format.

The first partition must be vfat. where X is the device and 1 is the partition number.

# mkfs.vfat /dev/sdX1

The second partition should be Linux EXT3 FS.

# mkfs.ext3 /dev/sdX2

Step 2: Write the Uboot, u-boot-sunxi-with-spl.bin, to the SD Card.

If you downloaded Robert's kernel extract the archive's contents get the path to the sunxi bin file.

Using dd, we can write uBoot to the SD Card.

# dd if=/boot/u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

This file must be written to the device and not a partition. (not sdX1 or sdX2)

Now copy the Kernel uImage from the boot directory of the files you extracted to the first partition of the card.

# cp /boot/uImage /mnt/sdX1

Step 3: Write the script.bin and sun7i-a20-cubietruck.dtb files to the first partition. (Convert the fex file from the github with fex2bin. Link found in Prerequisites.)

# fex2bin cubietruck.fex > script.bin
# cp script.bin /mnt/sdX1
# cp /boot/sun7i-a20-cubietruck.dtb /mnt/sdX1

Step 4: We must make a boot.scr file. We can do this with mkImage.

Open a blank document by entering the following.

# nano boot.cmd

in nano, add the following to the file.

fatload mmc 0 0x46000000 uImage
fatload mmc 0 0x49000000 sun7i-a20-cubietruck.dtb
setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait panic=10 ${extra}
setenv video-mode sunxi:1024x768-24@60,monitor=hdmi,edid=1
bootm 0x46000000 - 0x49000000

Now press {Ctrl + O} {Press Enter} {Ctrl + X}

We have to use mkimage to create the scr file from our raw cmd file.

# mkimage -C none -A arm -T script -d boot.cmd boot.scr

Copy this file also to the first partition of the SD Card.

# cp boot.scr /mnt/sdX1

On the first partition, the files listed should be:

boot.scr script.bin sun7i-a20-cubietruck.dtb uImage

Step 5: Now on to the Ubuntu rootfs.

Extract the contents of the ubuntu-base-16.04.2-base-armhf.tar.gz file to get to the rootfs.

After extracting, you should have basically the same folders as listed.

bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var

Now copy the rootfs folders to the second partition of your SD Card.

# cp -a /ubuntu/. /mnt/sdX2/

Delete the modules folder on the SD Card and copy the modules from the kernel archive to the SD Card.

# rm -rf /mnt/sdX2/lib/modules/4.x.xx/
# cp -rfv /kernel-linux/lib/modules/4.x.xx/ /mnt/sdX2/lib/modules/

Now replace the firmware folder on the SD Card with the firmware folder in the kernel archive.

# rm -rf /mnt/sdX2/lib/firmware/
# cp -rfv /kernel-linux/lib/firmware/ /mnt/sdX2/lib/
# sync

We now have the Ubuntu Core on our SD Card and will boot with Cubietruck. However, this is only the lightest weight Ubuntu without a user, packages, software.

In the next article, I will show you how to make Das U-Boot from source instead of using the prepared one in the kernel archive.