Integrate qbee-agent

Buildroot is an open-source and highly customizable framework designed for creating embedded Linux systems. It is a set of tools and scripts that facilitate the process of building a complete and minimalistic Linux distribution tailored for embedded and IoT (Internet of Things) devices. Buildroot allows developers to compile all the necessary components, including the kernel, bootloader, libraries, and applications, into a single, integrated image that can be flashed onto the target hardware.

This example shows how to integrate the qbee-agent with the buildroot framework in order to achieve system management and automation capabilities.

  1. Set up the buildroot environment (this example use Ubuntu 22.04 has host)
    sudo apt-get update
    sudo apt-get install -y gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential \
        chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping \
        python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev xterm python3-subunit mesa-common-dev \
        libncurses-dev qemu-system pylint vim file rsync bc
    wget https://git.busybox.net/buildroot/snapshot/buildroot-2023.08.1.tar.bz2
    tar xjf buildroot-2023.08.1.tar.bz2
    
  2. Get the qbee-agent definitions for buildroot
    git clone https://github.com/qbee-io/qbee-agent-buildroot.git
    
  3. Configure the buildroot framework for qbee-agent

    Link to the qbee-agent buildroot definition

    cd buildroot-2023.08.1/package
    ln -s ../../qbee-agent-buildroot/qbee-agent
    

    Edit Config.in to include the qbee-agent buildroot definition:

    vim Config.in
    
    [...]
        source "package/pwgen/Config.in"
        source "package/qbee-agent/Config.in"
        source "package/quota/Config.in"
    [...]
    

    Example uses qemu for emulation of a device, so we set some default settings for this target

    cd ../
    make qemu_x86_64_defconfig
    

    Configure the linux kernel to enable the tun module for remote access

    make linux-menuconfig
    
    Select tun module Location for this setting is "Device Drivers -> Network device support -> Network core driver support -> Universal TUN/TAP device driver support"

    Configure the target image. This example uses systemd as init system.

    make menuconfig
    

    Select systemd as init system

    Location for this setting is "System configuration -> Init system"

    Select qbee-agent

    Location for this setting is "Target packages -> System tools"

    We are using systemd which uses different interface names than default. So we need to change the interface setting which gets configured over DHCP.

    Select DHCP interface

    Location for this setting is "System configuration -> Network interface to configure through DHCP"

    We also want to include openssh so that we can use the web based UI in qbee.io for terminal access

    Select openSSH

    Location for this setting is "Target packages -> Networking applications"

    Root filesystem size

    You might need to increase the root file system size for the resulting image to work. This example has increased the default 60M rootfs size to 100M. This is done under "Filesystem images -> exact size". Set rootfs size

  4. Build the image

    Start off by clearing out any state in the for the target. Some intermediate builds performed in earlier steps might have put binaries and results in the target directories, and we want to start from scratch. We do not want to run make clean as this will also remove binary builds, we are only interested in cleaning out the target.

    rm -rf output/target
    find output/ -name ".stamp_target_installed" -delete
    rm -f output/build/host-gcc-final-*/.stamp_host_installed
    

    Then build the final image

    make
    
  5. Test the new image using qemu

    qemu-system-x86_64 -kernel ./output/images/bzImage -hda ./output/images/rootfs.ext2 \
        -append "root=/dev/sda rw console=ttyS0" -nographic -net nic,model=virtio -net user
    
    Buildroot boot screen

    Now we can log in and do a regular qbee-agent bootstrap.

    qbee-agent bootstrap -k <bootstrap_key>
    

    Now the buildroot based device will show up in the qbee.io web UI.

    Buildroot bootstrapped device