Debian 9 Stretch for Linkit - sergev/linkit-cube-demo GitHub Wiki

Create a Debian 9 filesystem image for OpenWRT

Linkit Smart 7688 board can be used as a MIPS-based Linux workstation, for generic development tasks. To get access to a console port, you can use any USB-to-serial adapter.

From a user point of view, an OpenWRT environment is quite different from Linux. But it's possible to build a Debian-based environment, located on microSD card and used via chroot.

  • No modification to OpenWRT system is required
  • All additional files placed on SD card
  • Full traditional Linux environment is provided

To make a minimal root filesystem, you need a live MIPS Debian system. I had used Creator CI20 board. First you need to install a multistrap utility:

sudo apt-get install multistrap gpgv

Create a file multistrap.conf and put the following lines to it:

[General]
    arch=mipsel
    cleanup=true
    noauth=true
    unpack=true
    debootstrap=Debian
    aptsources=Debian

[Debian]
    packages=apt
    source=http://http.debian.net/debian
    keyring=debian-archive-keyring
    suite=stretch

Fetch a public key for Debian 9/stretch:

gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553
gpg -a --export 8B48AD6246925553 | sudo apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-key E0B11894F66AEC98
gpg -a --export E0B11894F66AEC98 | sudo apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-key EDA0D2388AE22BA9
gpg -a --export EDA0D2388AE22BA9 | sudo apt-key add -

Run multistrap utiltity to build a directory debian/ with a minimal set of installed packages:

sudo multistrap -a mipsel -d debian -f multistrap.conf

Add a default Google DNS resolver:

sudo bash -c "echo nameserver 8.8.8.8 > debian/etc/resolv.conf"

Fix a list of mounted filesystems:

sudo bash -c "ln -s /proc/mounts debian/etc/mtab"

Edit file debian/root/.bashrc and add the following lines to it:

export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export TERM=xterm
unset HOSTNAME SHELL LOOP_MOUNTPOINT ASEC_MOUNTPOINT
unset ANDROID_PROPERTY_WORKSPACE ANDROID_ASSETS
unset ANDROID_BOOTLOGO LD_LIBRARY_PATH BOOTCLASSPATH
unset ANDROID_DATA MKSH ANDROID_ROOT EXTERNAL_STORAGE

Check that a minimal filesystem works as expected:

sudo chroot debian /bin/bash    -- start a shell in a new root filesystem
echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen
locale-gen
apt-get update                  -- check network access to Debian repository
apt-get clean
exit                            -- exit from chroot shell

Pack the root directory into a single tarball:

(cd debian; sudo tar cvzf ../debian.tgz .)
sudo chown $USER debian.tgz

The size of resulting file will be about 78 Mbytes. A resulting image is available for download here: http://ftp.vak.ru/pub/unix/debian-stretch-mini.tgz

Create an empty Linux partition on SD card. Typically, a clean FS card contains a single partition of type FAT32. Use fdisk to change the partition type to Linux and create empty filesystem:

sudo umount /dev/mmcblk0p1
sudo sfdisk /dev/mmcblk0 << EOF
/dev/mmcblk0p2 : size=512M, type=82
/dev/mmcblk0p1 : type=83, bootable
EOF
sudo mke2fs /dev/mmcblk0p1

Install the debian package into the SD card:

sudo mount /dev/mmcblk0p1 /mnt
sudo tar xvzf debian-stretch-mini.tgz -C /mnt
sudo umount /mnt

Start Debian on Linkit Smart 7688 board

Connect your board to Wi-Fi network:

uci set wireless.sta.ssid=IMG-Staff-BYOD
uci set wireless.sta.encryption=psk2
uci set wireless.sta.key=xxxxxxxx
uci set wireless.sta.disabled=0
uci commit
wifi

To start a shell in a new Debian environment, use this script:

mkswap /dev/mmcblk0p2
swapon /dev/mmcblk0p2
mount /dev/mmcblk0p1 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
HOME=/root chroot /mnt /bin/bash

You can install any needed packages, using a standard utility apt-get:

apt-get install vim build-essential git cvs subversion openssh-client
apt-get install dialog iputils-ping autoconf automake libtool gettext
apt-get install flex bison byacc gdb locate procps

To unmount, use the script:

umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt

Enjoy!