I was suggested to check out LXD for a centos7 container with systemd for running ansys/starccm+ on any distro

Hello everyone!

So I will try to get as descriptive as possible. Not so long ago I was really getting into scientific/engineering simulation software. Along with OpenFOAM I got into using Ansys, StarCCM+, Xflow, Converge, Comsol etc. They all have linux versions but only support CentOS7/RHEL 7. I started using CentOS 7 as a daily and it worked well if I was willing to build newer packages from source, but that hit a wall. Fortunately someone on reddit suggested docker and I attempted this using Fedora as host. It worked well but I then realized I needed Systemd to get these software’s license services working in container. And then I officially found a way to get systemd enabled and the rest was history.

I even moved over to Podman and tried the container and it worked. I launch the docker using my own script called centos-systemd (originally it was called Centos7-base2 when i was testing it, but I digress). However openfoam and paraview stopped working in fedora and I had to move to another distro. Here is where it all fell part. My container would not run on anything other then fedora and using cgroup1. I concluded that in order to get a systemd centos container to work, the host needs to be in the same family.

And now to the point, In one my post in r/podman subreddit a user suggested I should use a LXD container as that way I can have a systemd enabled centos container in any host without “docker mounting hackery”. So my question is, is it possible and should I be expecting any issues?

All I am looking for is a container (I don’t want to do a VM because I prefer the bare metal performance and these software are very cpu and memory intensive) that can:

1). Run well on an Ubuntu or PopOS

2). Has no issues with cgroups

3). Can use systemd for my software license services and other systemd services if needed

4). Can mount to host filesystem (like can access host /run directory for sd cards/usb/iso, and can also easily share host /opt and /home directory for easy file I/O)

5). Can use host gpu for acceleration and host display to use applications

If so how do I go about it? Do I need specific settings when I lxd init? I want full read/write access to host home and opt directory too. Also don’t want to limit size of container

Is this possible?

Hi!

With LXD you get system containers, which are similar to virtual machines but more lightweight.

  1. You can run LXD on Ubuntu and other Linux distributions.
  2. Uses cgroups.
  3. You can configure systemd as required in the container.
  4. You can share storage between the host and the container. You may assign a USB device to be used exclusively in a container.
  5. You can run GUI+OpenGL applications in the container and get the output on the host’s X server. See, for example, https://blog.simos.info/running-x11-software-in-lxd-containers/

In LXD, if you use Ubuntu, setup the storage pool to use ZFS. It can be either a loop file (allocate, let’s say, 60GB from the host), or use a partition with ZFS. The latter is recommended for a bit better performance. By default, the container will take as much space as required, and as much is available in the storage pool.

You can mount a directory from the host to the container using a line like the following.

lxc config device add CONTAINER DEVICE disk path=/container/path source=/host/path shift=true
1 Like

Right, at its most basic, try:

  • snap install lxd
  • lxd init --auto
  • lxc launch images:centos/7 centos
  • lxc exec centos bash

That will get you the most basic configuration with a CentOS 7 container using systemd and get you a root shell inside it.

Then you can add disk and gpu devices to it to pass host paths and access the gpu, you can also set some cpu/memory limits on it if you want, …

The cgroup story is currently not going to be a problem as Ubuntu still uses cgroup1 so CentOS 7 will be happy with it. When Ubuntu eventually transitions to cgroup2 (planned for 21.10 I believe), then older distros that don’t support both cgroup1 and cgroup2 in their systemd (like centos7) will start failing inside LXD. That shouldn’t affect too many distros and hopefully some will backport the needed bits to make systemd not crash on startup, but there will also still be the option to just force your host system back into cgroup1 mode so not a huge issue and we don’t plan on dropping support for cgroup1 in LXD any time soon.

1 Like

Thank you for the response, so does not using a loop file for storage mean the container can grow as much as it needs for storage? Also I assume it’s that lightweight it would have a 1:1 performance ratio to bare metal right?

Right, using a dedicated disk or using the dir backend will avoid any performance overhead from using a loop drive for storage. At that point, your container is really just another bunch of processes and unless you’re applying resource limits, should see performance identical to running straight on the host.

1 Like

I see, I assume id setup the shared directory and gpu passthrough once ? I would not want to limit any resources as the software i am running needs all the cpu, gpu and ram as possible (looking for 1:1 performance versus bare metal).

Also yes one of the issues I had with docker was cgroup miss match, won’t be a issue in LXD like you said.

Hello again, so I followed the link in your 5th point and read through it. I am currently trying to test this in a vm using Ubuntu 20.10 (KDE so Kubuntu), the gpu right now per say is a vmware virtual gpu, will that cause an issue? Also I assume that profile I create for LXC will activate “GPU” acceleration inside the container? If it works well in the VM, when do a bare metal install I would want to be able to use CUDA inside as well.

In terms of systemd, will it autostart or do I need to do extra steps?

I followed this: https://linuxcontainers.org/lxd/docs/master/faq

However inside the container I get

[root@centos ~]# systemctl status
Failed to get D-Bus connection: Operation not permitted