Setting up the Linux distribution root file system

From Orange Pi
Jump to: navigation, search
Note: these instructions are for a Linux computer, not the O-Pi!! 

From "1. Building u-boot, script.bin and linux kernel" and "2. Setting up the bootable SD card" pages in the previous two sections, you already have a bootable SD card, but with no root file system. So this page describes how to set this up. This depends in fact on what distribution you want to install.

It is assumed that you have a bootable SD card with 2 partitions. Throughout this document, ${card} and ${card}${p}1 mean /dev/sdX and /dev/sdX1 on a USB connected SD card, and /dev/mmcblk0, /dev/mmcblk0p1 on an mmc controller connected device, as described previously in the aforementioned Section 2.



Using an existing rootfs tarball

From the internet, you can find many OS tarballs such as Ubuntu, Fedora, Archlinux, and so on. Just download a tarball, and then extract it to the second partition of the SD card. (As mentioned above in the opening paragraph, it is assumed that you have already created two partitions, the first is for the boot partition, while the second is for the rootfs partition). For example, you might have just downloaded a tarball called "my-chosen-rootfs.tar.bz":

sudo mount ${card}${p}2 /mnt
sudo tar -C /mnt/ -zxvf my-chosen-rootfs.tgz
umount /mnt



Linaro rootfs

Linaro offers a set of different root file systems. You can download any pre-built images or rootfs from

http://www.linaro.org/downloads/#dev-builds

and then copy the root file system onto the SD card.


Using debootstrap

debootstrap is a tool which will install a Debian/Ubuntu based system into a sub-directory of another and already installed system. It doesn't require an installation CD, just access to a Debian/Ubuntu repository.

Changing to root here is necessary, since we are going to be doing a lot of things that require superuser access:

su



Install the required packages

To install Debian into a directory, we need debootstrap. For chrooting (child rooting) into the ARM environment, we also need qemu to be present within that environment. Install the required packages by using the command:

apt-get install qemu-user-static binfmt-support



Install Debian/Ubuntu using debootstrap

Mount the second SD card partition and execute debootstrap:

mount ${card}${p}2 /mnt
debootstrap --arch=armhf --foreign $distro /mnt


Replace the phrase $distro with an appropriate Ubuntu or Debian version, such as 'saucy' for Ubuntu or 'wheezy' for Debian.


We are now just a few steps away from chrooting into your Debian/Ubuntu environment, but before we can proceed we need to copy two files from our host system:

cp /usr/bin/qemu-arm-static /mnt/usr/bin/
cp /etc/resolv.conf /mnt/etc
chroot /mnt
export LANG=C


We can now continue with the debootstrap process using:

/debootstrap/debootstrap --second-stage


# for Ubuntu
cat <<EOT > etc/apt/sources.list
deb http://ports.ubuntu.com/ $distro main universe
deb-src http://ports.ubuntu.com/ $distro main universe
deb http://ports.ubuntu.com/ $distro-security main universe
deb-src http://ports.ubuntu.com/ $distro-security main universe
deb http://ports.ubuntu.com/ $distro-updates main universe
deb-src http://ports.ubuntu.com/ $distro-updates main universe
EOT#


# for Debian
cat <<EOT > etc/apt/sources.list
deb http://http.debian.net/debian $distro main contrib non-free
deb-src http://http.debian.net/debian $distro main contrib non-free
deb http://http.debian.net/debian $distro-updates main contrib non-free
deb-src http://http.debian.net/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



For the next step, we can set up apt:

cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOT


Update to the latest database from the servers:

apt-get update


And you should set your locales (Debian) with dpkg scripts or they tend to complain otherwise:

apt-get install locales
dpkg-reconfigure locales


Choose en_US.UTF-8 or whatever you want:

export LANG=en_US.UTF-8


Install some useful packages inside the chroot:

apt-get install openssh-server


Set a root password so you can log in:

passwd


Set the hostname:

echo orangepi > /etc/hostname


Exit the chroot session:

/etc/init.d/ssh stop
exit


Clean up the support files

rm /mnt/usr/bin/qemu-arm-static /mnt/etc/resolv.conf
umount /mnt




Install the kernel modules

When you have copied rootfs to your SD card, don’t be in a hurry to pull out the SD card. You might also need to copy the corresponding kernel modules as well, otherwise the system might have a problem. Go into the top level directory of the newly created rootfs and run:

mount ${card}${p}2 /mnt
mkdir -p /mnt/lib/modules
rm -rf /mnt/lib/modules/
cp -r ${lib_dir}/lib /mnt/
umount /mnt


Replace the phrase ${lib_dir} with the directory into which you output the built kernel modules file. The lib directory includes modules packages and some lib*.so files


Boot!

Now you should be able to unmount your SD card's file systems, and insert it to your Orange Pi, then power on the board to boot the new system you have just created.


References

1. http://sunxi.org/Bootable_SD_card#Cleaning




(With thanks to native speaker “roses” for checking and upgrading this document)