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.
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.
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.
Create a directory in which we will mount the image
mkdir mnt
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):
Note. The location of the file system can also be viewed using the utility parted.
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.
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.
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:
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: