Menu

ROS 2 on any distribution ARCHLINUX

The story behind

I was and am using Archlinux as my daily driver and never struggled with any software. When I started using ROS, everything from development to compilation was done on the dev board (NVIDIA Jetson). The problem started when I wanted to do simulations on my personal computer. ROS for Archlinux installation was all over the place as There was no official support and the AUR repository was hit or miss.

This did not stop me as I really love to see a robot moving in real life and in a simulation. So, I used Docker with nonvc and it worked with some caveats (low performance) This is a link to help you set it up if you are interested in running ROS 2 in a docker with a graphical environment :
ROS 2 with Docker


The enlightenment:

So to me finding a better solution was a journey and a fruitful one in fact. Long story short, I found a way to run ROS 2 on any distrubution

and it was creating another root file system (rootfs) and chroot to it. Don't worry if you didn't understand any word from what I just said, This Article will be thorough for me and you as I will explain everything and put steps to follow in the future.

Required tools :

  • A Linux Machine with any niche distro( Steps done using Arch )
  • debootstrap installed (I'll show you how to do it)
  • chroot (Probably installed but I'll provide the steps, as this is noob friendly article)
  • A working brain


Steps :

Creating a directory:

mkdir -p myubuntu

Install debootstrap (you can use pacman -S if you are on arch, apt install if you are on debian/ubuntu systems, dnf install if you are on fedora/centos or google your own package manager)

sudo pacman -Sy debootstrap

Use it to install base ubuntu 22.0.4 into the directory we made (we can install other version of ubuntu example: ubuntu20.0.4 we put focal instead of jammy)

sudo debootstrap --arch amd64 jammy myubuntu http://archive.ubuntu.com/ubuntu

we want to chroot into our new system and do the required configurations, we must chroot and mount certain important directories. Thanks to Tobias Schmidl****

we have this script to chroot int the new system environment and mount everything for us. Try to use the gist link below:

Create a new empty file and name it tschroot.sh and copy the shell script into it save.

#! /bin/sh
[ ! -d "$1" ] && echo "$1 is not a valid directory." && exit 1;
trap "umount \"${1}\"/tmp \"${1}\"/dev/null \"${1}\"/dev/pts \"${1}\"/dev/random \"${1}\"/dev/shm \"${1}\"/dev/urandom \"${1}\"/proc" EXIT INT TERM HUP PIPE &&
    mount --bind /tmp "${1}/tmp" && \
    mount --bind /dev/null "${1}/dev/null" && \
    mount --bind /dev/pts "${1}/dev/pts" && \
    mount --bind /dev/random "${1}/dev/random" && \
    mount --bind /dev/shm "${1}/dev/shm" && \
    mount --bind /dev/urandom "${1}/dev/urandom" && \
    mount --bind /proc "${1}/proc" && \
    chroot "$@";
    

script link: https://gist.github.com/schtobia/ea1b786d915415f86099
You can now test test the script

sudo tschroot.sh myubunutu

You will get a new shell inside a ubuntu envirnoment. (now everytime I say chroot into ubuntu system you are going to use the script like we did above)
chroot into ubuntu Now it is time to setup our locale (time, timezone, text encoding ...)

locale  # check for UTF-8

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

locale  # verify settings

Install Linux kernel

apt install linux-image-generic

There is a group package called ubuntu-desktop-minimal it contain so many useful packages so instead of installing each manually we do install the group package

apt update && apt install ubuntu-desktop-minimal bash-completion

Now we need to create a user with sudo privileges

/sbin/useradd -s /bin/bash -g sudo -m -k /dev/null **username_here**

Change the password

passwd username_here 

after creating the new user and setting the new password we may want to add the .bashrc file to the home directory of the new user just because our environment don't have it and a lot of things won't work out of the box. we need to cd into myubuntu/home/username

cd myubuntu/home/**username**

we add the file here after downloading it, this is the link for a default .basshrc file:

https://gist.github.com/marioBonales/1637696

after adding the file we need to add source list for the apt to work: cd myubuntu/etc/apt/

open the sources.list with your favorite text editor and paste the text from this link there https://gist.github.com/hakerdefo/9c99e140f543b5089e32176fe8721f5f

now we use the script to get back into the environment:

sudo tschroot myubuntu

Switch to your user :

su username_here
Installing ROS 2:

Installing ROS 2 has been explained on the official website. You can check there if you need further instructions.

in your local machine terminal run

 xhost local:

Then; chroot into the ubuntu system

sudo apt install software-properties-common
sudo add-apt-repository universe

We install the curl package then we add the gpg keys to our system

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

We add the mirror links to our sourcelist

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

We update to sync the packages then upgrade to install them

sudo apt update && sudo apt upgrade

Finally we install ros humble the LTS version (Long Term Support)

sudo apt install ros-humble-desktop && sudo apt install ros-humble-gazebo-*

We add some dev tools

sudo apt install ros-dev-tools

We source our environment

source /opt/ros/humble/setup.bash

Open two terminals and chroot into them using the same script and let us test our work so far

First terminal

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker

Second terminal:

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_py listener

you should get a talker sending "hello world" and a listener receiving it. Now we are done you have a ROS 2 environment on your machine feel free to do whatever and start building something.

Devil’s in the details: (Explanation)

Every term I try to explain here already has one or multiple explanations online, and that’s good if you want to search those for yourself, but why not include everything here.

What is a distribution:

What is Archlinux:

Arch Linux is an independently developed, x86-64 general-purpose Linux distribution that strives to provide the latest stable versions of most software by following a rolling-release model. The default installation is a minimal base system, configured by the user to only add what is purposely required.

AUR repository:

Arch User Repository it is just like github with super powers maybe I’ll explain in other articles

Docker:

Ever heard of virtual machines?Well virtual machines need a kernel for themselves docker don’t.

Novnc:

when we have a graphical interface in Docker we can use it to visualize it.

Rootfs:

The root filesystem is at the top of the hierarchical file tree (also known as '/').

debootstrap and chroot:

chroot as complicated as it is I'll put it simple like this: every program on Linux sees the / (the slash or root path) as the start of everything so it brings libraries from /lib or configurations from /etc , ...etc. then what chroot does it changes the perspective or the slash to the folder you give to it in our article myubuntu becomes the / . Debootstrap install a whole system on that folder by then you have a new isolated system.

What lies Beyond:

This is where ROS related ends but we keep going.  You may have an application that you want to run on an isolated environment but you don’t want to use docker or lxc containers. You want something better. you can use what we learned in the previous section to create a minimal root file system for a simple app that depends on one library.

The END :

Is it really the end or the beginning of something new? I tried to explain everything as I understood them, I explained it my way, my style.

I tried to explain everything while keeping it as minimal as possible. I am tired now,

Next time maybe I’ll discover something else and write about it. For now I am out.

blog