Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Running in a Debian nspawn container (or chroot)

Running in a Debian nspawn container (or chroot)

A while ago, I tried to package OpenModelica for Arch Linux and failed to get anything running.  Now, I've finally managed to run OM on Arch by actually running it in Debian.  If you're not familiar, a chroot (or the modernized equivalent, systemd-nspawn) lets you run a separate userspace (ie: OS) atop your already-running kernel.  It's like a step shy of full virtualization.  Here's how I got it to work.

Setting up goes something like this:

Code:

# Install debootstrap, the tool for creating Debian root images.

yaourt -S debootstrap
# Create a minimal Debian root.
mkdir ~/debian-root
sudo debootstrap --arch=amd64 --variant=minbase sid ~/debian-root # This will take a while.
cd ~/debian-root
# Download the OpenModelica Debian repository key for later.
sudo wget http://build.openmodelica.org/apt/openmodelica.asc
# Activate the container.
# This can also be done with the "chroot" command, but needs more pre-setup.  Much information is already on the internet.
sudo systemd-nspawn

# You are now root in a Debian environment, but it needs to be configured.
# Add the OpenModelica package repository and key.
echo "deb http://build.openmodelica.org/apt nightly contrib" > /etc/apt/sources.list.d/openmodelica.list
apt-key add /openmodelica.asc && rm /openmodelica.asc
# Update all package lists.
apt-get update
# Install OpenModelica and xauth.
apt-get install openmodelica xauth # This will also take a while.
# Create a user account (omc refuses to run as root).
useradd a

Now that the Debian container is ready, the OpenModelica applications can be run inside it.  But it takes some tricks to make them properly connect to your graphical (X) session.  This does the trick for me, but it might be possible to improve it:

Code:

# Open your X session to the container.

xhost +
# Enter the container as user "a".
sudo systemd-nspawn -D ~/debian-root -u a

# Now inside the container, authenticate with the outside X session.
xauth generate :0 .
# And launch the OpenModelica connection editor.
DISPLAY=:0 OMEdit

I've wrapped up the launching code in a single script, OM, that allows me to launch any OpenModelica application as eg. "OM Edit" or "OM Plot".  It requires you to enter your sudo password, but that can be worked around by editing sudoers (which is beyond the scope of this post).

Code:

#!/bin/sh

xhost +
sudo systemd-nspawn -D ~/debian-root -u a sh -c "/usr/bin/xauth generate $DISPLAY .; DISPLAY=$DISPLAY /usr/bin/OM$1"
xhost -

I hope that's helpful to someone.  If there are any additions or corrections you have, let me know.

Edited by: randy.heydon - Nov-26-12 17:22:58
There are 0 guests and 0 other users also viewing this topic
You are here: