Home Setting up Linux Installing ROS in an Ubuntu single board IMG image

Installing ROS in an Ubuntu single board IMG image

by admin

Introduction

The other day while working on my diploma the other day I had to create an Ubuntu image for a single board with ROS already installed ( Robot Operating System ).In brief, the thesis is about controlling a group of robots.The robots are equipped with two wheels and three rangefinders. The whole thing is controlled from the ROS which runs on the ODROID-C2 board.

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

I had no time or desire to install ROS on each robot individually, so I had a need for an image of the system with ROS already installed. After surfing the net I found some approaches on how this could be done.
In general all the solutions found can be categorized into the following groups.

  1. Programs that create an image from a finished 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. Build the image yourself with your own hands ( liveCD customization and Russian equivalent plus article on the hubra )

The first group seemed to be the easiest and most appealing, but I couldn’t create a live-image for ODROID. The solutions of the second group didn’t suit me either, because of the rather high threshold. The manual builds from the tutorials didn’t work either, since I didn’t have a compressed file system in my image.
At last I came across a video about chroot ( chroot – change root , link to the video at the end of the post)and its features, I decided to use it. Next I will describe my particular case of Ubuntu customization for robotics developers.

Source data :

  • The whole process of modifying the image (except writing to the SD card using balenaEtcher) was done in Ubuntu 18.04 operating system.
  • The operating system whose build I modified is Ubuntu 18.04.3 mate desktop version.
  • The machine I built the system on is ODROID-C2.

Image preparation

  1. Download Ubuntu image for ODROID from official site

  2. Unpack the archive

    unxz -kv <archive file with the image>

  3. Create a directory in which to mount the image

    mkdir mnt

  4. Define the partition where the file system is located

    file <image file>

    We are looking for a partition with an ext2, ext3 or ext4 filesystem. We need the address of the partition’s beginning (highlighted in red in the screenshot):
    Installing ROS in an Ubuntu single board IMG image
    Note. You can also view the location of the filesystem with the parted

  5. Mounting the image

    sudo mount -o loop, offset=$((264192*512)) lt;file with the image> mnt/

    The partition we need starts with block 264192 (your numbers can be different), it is 512 bytes, so multiply them to get the indentation in bytes.

  6. Go to the folder with the mounted system and scrutinize 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 by bin/bash )
    Now you can install the necessary packages and applications.

ROS installation

I put the latest version of ROS (ROS Melodic) on official tutorial

  1. Updating the list of packages

    sudo apt-get update

    I had an error here :

    Err:6 http://deb.odroid.in/c2 bionic InReleaseThe following signatures were invalid: EXPKEYSIG 5360FB9DAB19BAC9 Mauro Ribeiro (mdrjr) <mauro.ribeiro@hardkernel.com>

    It is because the key for signing 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 was not able to install the desktop version of ROS, so I only installed the basic packages :

    sudo apt install ros-melodic-ros-baseapt search ros-melodic

    Note 1. An error sometimes occurred during installation :

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

    Fixed by clearing cache with apt utility:

    sudo apt-get clean; sudo apt-get autoclean

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

    source /opt/ros/melodic/setup.bash

    will not work, since we have not run bash, so it does NOT need to be typed in the terminal.

  4. Install the necessary dependencies

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

    sudo apt install python-rosdep

    sudo rosdep initrosdep update

  5. Configure access rights
    Since we are in fact doing everything as root of the system we are building, the ROS will run only as root.
    Attempting to run roscore without sudo causes an error :

    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 this error, let’s recursively change the permissions of the ROS user’s home directory. To do this, type :

    sudo rosdep fix-permissions

  6. Finish installing rviz and rqt packages

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

The finishing touches

  1. Exit the chroot:
    exit
  2. Unmount the image
    cd ...sudo umount mnt/
  3. Pack the system image into the archive
    xz -ckv1 <image file>

That’s it! Now with the help of balenaEtcher you can write the image to an SD-card, insert it in ODROID-C2 and you have Ubuntu with ROS installed!

Links :

  • This video helps a lot with how to fiddle in linux and what it’s good for:

You may also like