Install ROS in IMG image of Ubuntu for single-board computer

Inleiding

Recently, while working on my thesis, I faced the need to create an Ubuntu image for a single-board computer with ROS already installed (Robot Operating System – the operating system for robots). In short, my thesis is about managing a group of robots. The robots are equipped with two wheels and three rangefinders. Everything is managed through ROS, which runs on the ODROID-C2 board.

Install ROS in IMG image of Ubuntu for single-board computer
Robot Ladybug. Sorry for the poor quality of the photo

There was neither time nor desire to install ROS on each robot separately, which is why I needed a system image with ROS already installed. After browsing the internet, I found several approaches to how this could be done.
In general, all the solutions found can be divided into the following groups.

  1. Programs for creating an image from a ready and configured system (Distroshare Ubuntu Imager, linux live kit, linux respin, systemback, etc.)
  2. Projects that allow you to create your own image (yocto, linux from scratch)
  3. Building the image manually (liveCD customization en a Russian equivalent, plus an article on Habr)

Using solutions from the first group seemed the easiest and most attractive option, but I couldn’t create a live system image for ODROID. The second group of solutions also did not fit due to the relatively high entry threshold. Building it manually from the available tutorials didn’t work either, as my image lacked a compressed file system.
Eventually, while coming across a video about chroot (chroot — change root, link to the video at the end of the post) and its capabilities, I decided to use it. I will describe my specific case of customizing Ubuntu for robotics developers.

Brongegevens:

  • The entire image modification process (except for writing to the SD card using balenaEtcher) was performed on the Ubuntu 18.04 operating system.
  • The operating system I modified the build of – Ubuntu 18.04.3 mate desktop version.
  • The machine on which the assembled system should run – ODROID-C2.

Preparing the image

  1. Download the Ubuntu image for ODROID from de officiële website

  2. Unpack the archive

    unxz –kv

  3. Create a directory to mount the image

    mkdir mnt

  4. Determine the partition on which the file system is located

    file

    We are looking for a partition with a file system in ext2, ext3, or ext4 format. We need the address of the beginning of the partition (highlighted in red in the screenshot):

    Install ROS in IMG image of Ubuntu for single-board computer

    Note. The location of the file system can also be checked using the utility parted.

  5. Mounting the image

    sudo mount -o loop,offset=$((264192*512))  mnt/

    The required partition starts at block 264192 (your numbers may vary), the size of one block is 512 bytes, multiply them to get the offset in bytes.

  6. We go to the directory with the mounted system and chroot into it

    cd mnt/
    sudo chroot ~/livecd/mnt/ bin/sh

    ~/livecd/mnt — full path to the directory with the mounted system
    bin/sh — shell (can also be replaced with bin/bash)
    Now we can start installing the necessary packages and applications.

Installing ROS

I installed the latest version of ROS (ROS Melodic) according to the official tutorial.

  1. Updating the package list

    sudo apt-get update

    I encountered an error here:

    Err:6 http://deb.odroid.in/c2 bionic InRelease
    The following signatures were invalid: EXPKEYSIG 5360FB9DAB19BAC9 Mauro Ribeiro (mdrjr)

    This is related to the fact that the key for signing the packages has expired. To update the keys, type:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AB19BAC9

  2. Preparing the system for ROS installation

    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

    sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

    sudo apt update

  3. Installing ROS
    Unfortunately, I could not install the desktop version of ROS, so I only installed the basic packages:

    sudo apt install ros-melodic-ros-base
    apt search ros-melodic

    Note 1. During installation, I sometimes encountered an error:

    dpkg: error: failed to write status database record about 'iputils-ping' to '/var/lib/dpkg/status': No space left on device

    This was resolved by clearing the apt utility cache:

    sudo apt-get clean; sudo apt-get autoclean

    Note 2. After installation, sourcing (source) with the command:

    source /opt/ros/melodic/setup.bash

    will not work since we didn't run bash, so there's NO need to type it in the terminal.

  4. Installing necessary dependencies

    sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

    sudo apt install python-rosdep

    sudo rosdep init
    rosdep update

  5. Configuring access rights
    Since we are chrooting and actually performing all actions as root of the constructed system, ROS will only run with superuser privileges.
    When trying to run roscore without sudo, the following error occurs:

    Traceback (meest recente aanroep laatst): Bestand "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py", regel 230, in main write_pid_file(options.pid_fn, options.core, options.port) Bestand "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py", regel 106, in write_pid_file met open(pid_fn, "w") als f: IOError: [Foutnummer 13] Toegang geweigerd: '/home/user/.ros/roscore-11311.pid'

    Om de fout te voorkomen, zullen we de machtigingen van de thuisdirectory van de ROS-gebruiker recursief wijzigen. Voer hiervoor het volgende in:

    sudo rosdep fix-permissions

  6. Installeer de pakketten rviz en rqt

    sudo apt-get install ros-melodic-rqt ros-melodic-rviz

Laatste handtekeningen

  1. Verlaat chroot:
    exit
  2. Koppel de afbeelding los
    cd ..
    sudo umount mnt/
  3. Pak de systeemafbeelding in een archief
    xz –ckv1

Klaar! Nu met behulp van balenaEtcher kun je de systeemafbeelding op de SD-kaart schrijven, deze in de ODROID-C2 steken, en dan heb je Ubuntu met geïnstalleerde ROS!

Links:

  • Dit video over hoe te chrooten in Linux en waarom dit nodig is, heeft erg geholpen:

Video afspelen


Bron: habr.com
Koop betrouwbare webhosting met bescherming tegen DDoS, VPS VDS servers 🔥 Koop betrouwbare webhosting met bescherming tegen DDoS, VPS VDS servers | ProHoster