Build Ubuntu Rfs
Update time:2018-03-13 Views:3672
1 Use miniroot to Create and Load System
Homepage of miniroot is: http://androtab.info/miniroot/
miniroot is a tiny shell environment, used to create and load root file system, such as Ubuntu, Gentoo and Arch Linux, etc. These systems can be reside in root or sub directories on any supported storage device. This means that we can install multiple OS in eMMC Flash, TF card or USB disk, and boot from one of them. Very handy to switch OS, no need to modify and flash parameter file (parameter file is used to specify the important partition info of flash storage).
miniroot needs serial line to debug, please see [Serial Debug]. Additionally, we need ethernet to download system image when install. Of course, it can also be downloaded first on host PC, then copied to the removable storage deivce for later use.
1.1 Before You Start
Important! Please backup data first, whether in the development board or removable storage devices, in case of any data lost due to mistaken operations or unforeseen accidents.
First, make sure the board is already flashed with working images. Then download following image files:
If Android or dual system is installed, then flash linux-boot-miniroot.img to recovery partition, misc.img to misc misc partition respectively.
If pure Linux is installed, flash linux-boot-miniroot.img to boot partition.
miniroot will drop you to a shell, after first boot up. You can see the prompt in the serial terminal:
miniroot#
Then start to configure the network. If it is DHCP:
miniroot# udhcpc
Otherwise, you need to specify network parameters manually. (Replace 192.168.1.* with the address actually used):
miniroot# ip addr add 192.168.1.2/24 broadcast + dev eth0 miniroot# ip link set dev eth0 up miniroot# ip route add default via 192.168.1.1 miniroot# echo nameserver 192.168.1.1 > /etc/resolv.conf
Miniroot supports booting from sub directory. You can have the OS installed in the favorite location, and boot from it. Multiple OS boot support is therefore just a piece of cake.
Below, we'll use the first parition of TF card to install the OS. Create ext4 filesystem and then mount it to /mnt, then extract Ubuntu files:
miniroot# mkfs.ext4 -E nodiscard /dev/mmcblk0p1 miniroot# mount /dev/mmcblk0p1 /mnt
Please make sure the partition has sufficient free space (4G
and above).
1.2 Download and Extract ubuntu-core
ubuntu-core is the minimum root file system. You can setup desktop or server environment later after install.
Download and extract to /mnt:
miniroot# cd /mnt miniroot# wget -P /mnt http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/ubuntu-core-14.04-core-armhf.tar.gzminiroot# mkdir /mnt/ubuntu miniroot# tar -xpzf /mnt/ubuntu-core-14.04-core-armhf.tar.gz -C /mnt/ubuntu
1.3 Boot Ubuntu
Set host name
miniroot# echo firefly > /mnt/ubuntu/etc/hostname miniroot# sed -e 's/miniroot/firefly/' < /etc/hosts > /mnt/ubuntu/etc/hosts
Setup serial console, and auto login with root:
miniroot# sed -e 's/tty1/ttyS2/g' -e '/^exec/c exec /sbin/getty -a root -L 115200 ttyS2 vt100' \ < /mnt/ubuntu/etc/init/tty1.conf > /mnt/ubuntu/etc/init/ttyS2.conf
Or serial console is not convenient, you can create new user account (account and password are both "ubuntu" in this case):
miniroot# chroot /mnt/ubuntu useradd -G sudo -m -s /bin/bash ubuntu miniroot# echo ubuntu:ubuntu | chroot /mnt/ubuntu chpasswd
Boot Ubuntu
miniroot# boot /mnt:/ubuntu
Tips: If root device is not mounted, you can replace the mount directory before the colon with the root device. Miniroot will mount the root device automatically:
miniroot# boot /dev/mmcblk0p1:/ubuntu
1.4 Initial Configuration
Setup Netowrk (DHCP)
root@ubuntu:~# echo auto eth0 > /etc/network/interfaces.d/eth0 root@ubuntu:~# echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0 root@ubuntu:~# ln -fs ../run/resolvconf/resolv.conf /etc/resolv.conf root@ubuntu:~# ifup eth0
Upgrade packages
root@ubuntu:~# apt-get update root@ubuntu:~# apt-get dist-upgrade
Reboot
root@ubuntu:~# reboot
Enter miniroot, edit the environment variables, and set the boot parameters of Ubuntu:
miniroot# editenv boot=/dev/mmcblk0p1:/ubuntu init=/sbin/init autoboot=1
Save the environment variables and reboot
miniroot# saveenv miniroot# reboot -f
1.5 Install Packages
Install Lubuntu (LXDE):
root@ubuntu:~# apt-get install lubuntu-desktop
1.6 Make the RFS
Plug the TF card of, and plug it to the host, mount it to /mnt.
Check the space needed for the rfs:
sudo du -hs /mnt/ubuntu
Clean /mnt/ubuntu, especially logging and temporary files and directories.
Create empty disk image file. For example, create 1GB rfs empty image:
cd /new/firmware/work/dir/ dd if=/dev/zero of=linuxroot.img bs=1M count=1024 # format to ext4 filesystem, labeled as linuxroot mkfs.ext4 -F -L linuxroot linuxroot.img
Mount, transfer data, then unmount:
mount -o loop linuxroot.img /opt cp -a /mnt/ubuntu/ /opt/ umount /opt
The final root filesystem linuxroot.img is ready to serve.
1.7 FAQ
1.7.1 How to go back to normal boot
If you flash misc.img to the misc partition, the board will boot the system in recovery partition. To revert to normal boot, there are two ways:
Download misc_zero.img, and flash to misc partition.
Under a Linux shell in the board, run:
sudo dd if=/dev/zero of=/dev/block/mtd/by-name/misc bs=16K count=3 sudo sync sudo reboot