Build Ubuntu Rootfs via Ubuntu Base(FIXME: TBD)


Before starting

Confirm again you have created the working directories:

$ install -d ~/project/khadas/ubuntu/{linux,rootfs,archives/{ubuntu-base,debs,hwpacks},images,scripts}
$ cd ~/project/khadas/ubuntu/

Download the latest Ubuntu-base tarball from official Ubuntu website:

$ wget -P archives/ubuntu-base -c

Install the qemu so you can run chroot to arm64:

$ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap

It would be better for you to understand the qemu on ARM64 first.

Build the basic file system

In this instruction, I will tend to:

Replace the below value seek=384 upto the approach you take:

Using dd to create a blank image file named as rootfs.img:

$ dd if=/dev/zero of=images/rootfs.img bs=1M count=0 seek=384

Create linux filesystem on the newly created image:

$ sudo mkfs.ext4 -F -L ROOTFS images/rootfs.img 

Note: the value of argument -L(here is ROOTFS) should match the Linux kernel's cmdline parameters: root=LABEL=ROOTFS.

Create a temporary folder and ensure that it is empty:

$ rm -rf rootfs && install -d rootfs

Loop mount the the image file created aboved:

$ sudo mount -o loop images/rootfs.img rootfs

Remove the unnecessary files:

$ sudo rm -rf rootfs/lost+found

Extract the ubuntu-base tarball into the mounted folder:

$ sudo tar -xzf archives/ubuntu-base/ubuntu-base-16.04.1-base-arm64.tar.gz -C rootfs/

Ubuntu-base is a minimal rootfs and formerly named as Ubuntu-core.

And now you have already completed the basic rootfs, check it:

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

Install linux kernel modules

$ sudo make -C linux -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=../rootfs/

Or run following instead:

$ cd linux/
$ sudo make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=../rootfs/
$ cd -

Check it:

$ ls rootfs/lib/modules
$ ls rootfs/lib/modules/3.14.29/
build              modules.builtin      modules.devname  modules.symbols.bin
kernel             modules.builtin.bin  modules.order    source
modules.alias      modules.dep          modules.softdep
modules.alias.bin  modules.dep.bin      modules.symbols

Add the hwpacks

Chroot and setup

Setup the Chroot environment:

$ sudo cp -a /usr/bin/qemu-aarch64-static rootfs/usr/bin/



Enter the arm64 Chroot:

$ sudo chroot rootfs/

Note: Now you are in the target emulator.

The first thing must be setup a password for the root user:

# passwd root

Follow the prompts to complete the setup.

You might also want to create an administrator user with 'sudo' permission [Optional]:

# useradd -G sudo -m -s /bin/bash khadas
# echo khadas:khadas | chpasswd

Tips: The format input line of chpasswd is: 'user_name:password'. Run man chpasswd for further info.

Setup a hostname for your target device [Optional]:

# echo Khadas > /etc/hostname
# echo "    localhost.localdomain localhost" > /etc/hosts
# echo "    Khadas" >> /etc/hosts

Setup DNS resolver:

# echo "nameserver" > /etc/resolv.conf

Setup a serial console to login:

# ln -s /lib/systemd/system/serial-getty\@.service /etc/systemd/system/ 

Fetch the latest package lists from server:

# apt-get update

Upgrade [Optional]:

# apt-get upgrade

Install the network packages:

# apt-get install ifupdown net-tools

Install udev device manager:

# apt-get install udev

Tips: ttyS0 timed out

Install packages to suit your taste [Optional]:

# apt-get install vim sudo ssh

Install initramfs-tools package:

# apt-get install initramfs-tools

Build the ramdisk:

# mkinitramfs -o /boot/initrd.img 3.14.29

Install fbset package for FIXME:

# apt-get install fbset

HDMI Setup

When everything you want to setup has been done, exit the Chroot:

# exit


Remember to synchronize cached writes to persistent storage first:

$ sudo sync


$ sudo umount rootfs/

After this, images/rootfs.img will be updated according to the modified contents aboved.

Burnning the images

kvim# usb_update logo logo.img
kvim# usb_update boot boot.img
kvim# usb_update rootfs rootfs.img

Initial setup

Once booted:

Resize the rootfs partition:

# resize2fs /dev/rootfs

Install ubuntu-desktop

Here we install ubuntu-mate, with Gnome desktop environments

Adding the Universe and Multiverse Repositories to support ubuntu-mate desktop:


Known issues

A start job is running for dev-ttys0.device
[ TIME ] Timed out waiting for device dev-ttyS0.device.
[DEPEND] Dependency failed for Serial Getty on ttyS0.