Installing ROS in an Ubuntu IMG image for a single board

Introduction

The other day, while working on a thesis, I ran into the need to create an Ubuntu image for a single-board device with ROS already installed (Robot Operating System - the operating system of robots). In short, the diploma is about managing a group of robots. The robots are equipped with two wheels and three rangefinders. The whole thing is controlled from ROS, which is spinning on the ODROID-C2 board.

Installing ROS in an Ubuntu IMG image for a single board
Ladybug robot. Sorry for poor photo quality

There was neither time nor desire to install ROS on each robot separately, and therefore there was a need for a system image with ROS already installed. Having wandered through the expanses of the Internet, I found several approaches to how this could be done.
In general, all found solutions can be divided into the following groups.

  1. Programs that create an image from a ready and configured system (Distroshare Ubuntu Imager, linux live kit, linux respin, systemback, etc.)
  2. Projects that allow you to build your own image (yocto, Linux from scratch)
  3. Assembling the image with pens yourself (live CD customization ΠΈ Russian equivalent, a plus article on hub)

Using solutions from the first group seemed the easiest and most attractive option, but I did not succeed in creating a live system image for ODROID. The solutions of the second group also did not suit me because of the rather high entry threshold. Assembly with handles according to the available tutorials also did not fit, because. my image did not have a compressed filesystem.
As a result, I came across a video about chroot (chroot - change root, link to the video at the end of the post) and its capabilities, it was decided to use it. Next, I will describe my special case of Ubuntu customization for robotics developers.

Initial data:

  • The entire process of modifying the image (with the exception of writing to the SD card using balenaEtcher) was performed on the Ubuntu 18.04 operating system.
  • The operating system, the assembly of which was modified - Ubuntu 18.04.3 mate desktop version.
  • The machine on which the assembled system should run is ODROID-C2.

Preparing the Image

  1. Download the Ubuntu image for ODROID from the official site

  2. Unpacking the archive

    unxz –kv <Ρ„Π°ΠΉΠ» Π°Ρ€Ρ…ΠΈΠ²Π° с ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ>

  3. Create a directory in which we will 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 section (highlighted in red on the screen):

    Installing ROS in an Ubuntu IMG image for a single board

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

  5. Mounting the image

    sudo mount -o loop,offset=$((264192*512)) <Ρ„Π°ΠΉΠ» с ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ> mnt/

    The section we need starts with block 264192 (your numbers may differ), the size of one block is 512 bytes, we multiply them to get the indent in bytes.

  6. Go to the folder with the mounted system and roam in 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 you can already install the necessary packages and applications.

Installing ROS

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

  1. Update the package list

    sudo apt-get update

    Here I got an error:

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

    It is related to the fact that the package signing key has expired. To update the keys, type:

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

  2. Preparing the system for installing ROS

    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 was not able to 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 the installation process, an error sometimes occurred:

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

    Fixed by clearing the apt cache:

    sudo apt-get clean; sudo apt-get autoclean

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

    source /opt/ros/melodic/setup.bash

    will not work, because we didn't run bash, so you don't have to type it in a terminal.

  4. Installing the 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. Setting up access rights
    Since we are entangled and, in fact, we perform all actions on behalf of the root of the system being assembled, then ROS will only run with superuser rights.
    When trying to run roscore without sudo, an error occurs:

    Traceback (most recent call last): File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py", line 230, in main write_pid_file(options.pid_fn, options.core, options.port) File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/__init__.py", line 106, in write_pid_file with open(pid_fn, "w") as f: IOError: [Errno 13] Permission denied: '/home/user/.ros/roscore-11311.pid'

    To avoid the error, we recursively change the access rights to the ROS user's home directory. To do this, we type:

    sudo rosdep fix-permissions

  6. Installing rviz and rqt packages

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

Final touches

  1. Exit chroot:
    exit
  2. Unmount the image
    cd ..
    sudo umount mnt/
  3. Pack the system image into an archive
    xz –ckv1 <Ρ„Π°ΠΉΠ» ΠΎΠ±Ρ€Π°Π·Π°>

All! Now with the help balenaetcher you can write the system image to an SD card, put it in ODROID-C2, and you have Ubuntu with ROS installed!

Links:

  • With how to tinker with linux and what it is for, this video helped a lot:



Source: habr.com

Add a comment