Skip to content

Compiling on Host Using chroot

Steps to Create chroot/QEMU Environment on a Linux PC

Warning

Tested on Ubuntu 20.04, 22.04, and 24.04.
Ubuntu 18.04 is not supported due to its outdated QEMU version.

Download the Archived Tarball

Visit the Kneron Developer Center and navigate to the KNEO Pi section. Download the archived tarball kneo_pi_chroot_{version}.tar.gz from the chroot environment folder for setting up the chroot environment.

Set Up a chroot environment

  • Install required packages

    sudo apt install debootstrap qemu-user-static arch-install-scripts
    
  • Prepare the chroot directory

    mkdir chroot
    cd chroot
    
  • Move the KNEO Pi Arch Linux ARM tarball to chroot directory and extract

    mv /your/path/to/kneo_pi_chroot_{version}.tar.gz .
    tar -zxvf 02_kneo_pi_ArchLinuxARM-aarch64-latest.tar.gz
    cd ..
    
  • Configure pacman cache and permissions

    Create and set permissions for the package cache

    sudo mkdir -p ./chroot/var/cache/pacman/pkg
    sudo chmod 755 ./chroot/var/cache/pacman/pkg
    sudo chown root:root ./chroot/var/cache/pacman/pkg
    

    Bind-mount the system pacman cache to avoid redundant downloads

    sudo mkdir -p /var/cache/arch-pacman/pkg
    sudo mount --bind /var/cache/arch-pacman/pkg ./chroot/var/cache/pacman/pkg
    
  • Copy the QEMU static binary into the chroot environment

    sudo cp /usr/bin/qemu-aarch64-static ./chroot/usr/bin/
    
  • Enter the chroot environment

    chroot into the prepared environment

    sudo arch-chroot chroot/
    

    Finally, chroot environment has been created

    [root@host_pc_name /]#
    
    Getting into Existing chroot Environment

    If you want to get into an created chroot environment (assume the relative path is ./chroot), only need to run

    (Run if the mount point is missing) $ sudo mount --bind /var/cache/arch-pacman/pkg ./chroot/var/cache/pacman/pkg
    
    $ sudo arch-chroot chroot/
    

Build Binaries in chroot Environment

In this guide, we use KNEO Pi examples as a demonstration of the build process.

Building the NNM examples

[root@host_pc_name /]# git clone https://github.com/kneron/kneopi-examples.git
[root@host_pc_name /]# cd kneopi-examples/ai_application/nnm
[root@host_pc_name nnm]# sh build_all.sh

Copy the built binaries to your KNEO Pi

[root@host_pc_name nnm]# scp -r bin/ alarm@[KNEO_Pi_IP]:/home/alarm/chroot_test_build

Trouble Shooting on SCP Problem

If you encounter the following problem:

Bad owner or permissions on /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
/usr/sbin/scp: Connection closed

Please run:

$ chown root:root /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf

Exiting the chroot Environment

To exit the chroot environment, simply type:

exit

If you need to remove the chroot setup, make sure to unmount any bound directories:

sudo umount chroot/var/cache/pacman/pkg