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.

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.
- Programs for creating an image from a ready and configured system (, , , systemback, etc.)
- Projects that allow you to create your own image (, )
- Building the image manually ( en , plus )
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
Download the Ubuntu image for ODROID from
Unpack the archive
unxz –kvCreate a directory to mount the image
mkdir mntDetermine the partition on which the file system is located
fileWe 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):

Note. The location of the file system can also be checked using the utility parted.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.
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 .
Updating the package list
sudo apt-get updateI 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 AB19BAC9Preparing 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 C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654sudo apt updateInstalling 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-melodicNote 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 deviceThis was resolved by clearing the apt utility cache:
sudo apt-get clean; sudo apt-get autocleanNote 2. After installation, sourcing (source) with the command:
source /opt/ros/melodic/setup.bashwill not work since we didn't run bash, so there's NO need to type it in the terminal.
Installing necessary dependencies
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essentialsudo apt install python-rosdepsudo rosdep init rosdep updateConfiguring 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-permissionsInstalleer de pakketten rviz en rqt
sudo apt-get install ros-melodic-rqt ros-melodic-rviz
Laatste handtekeningen
- Verlaat chroot:
exit - Koppel de afbeelding los
cd .. sudo umount mnt/ - Pak de systeemafbeelding in een archief
xz –ckv1
Klaar! Nu met behulp van 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:

Bron: habr.com

