[Solved] Is there a way to more permanently create /dev/shm/looking-glass?

Hi there! Thanks for taking the time to look at my question, and thank you kind folks for making looking glass a reality. (Such a cool software)

Anyway, I have a rather ridiculous script that allows me to hot swap GPU for my GPU pass through setup, but in order to allow that to work correctly the display manager needs to be turned off so that I can unload Nvidia and allow vfio to claim ownership of my gpu.

During the process of shutting down display manager I noticed that /dev/shm gets nuked (presumably because my user is no longer logged in).

The gpu hot swapping is being initiated through libvirt/hooks (this directory /etc/libvirt/hooks/qemu.d/win10/started/begin/). However, it looks like the memory created after the virtual machine is running, does not allow looking-glass to work.

Is there a way to more permanently create /dev/shm/looking-glass ? Or is there another location that I can use between display manager being turned off / on?

Systemd tmpfiles?

So I did some reading from here:

and here:

If I’m understanding this correctly, the only way this will work well is by using /dev/shm because it’s a ramdisk (right?). I created a test systemd tmpfile but if I’m creating /dev/shm/looking-glass on boot and want to hot swap my graphics card, how does that prevent the act of /dev/shm/ getting nuked between logging back in (when the display manager is turned off) ?

I figured out a solution and I’ve documented it below:

Problem: Looking glass uses a temporary file stored in /dev/shm which is used as a place where the looking-glass-client will read from RAM to be able to see the looking-glass host. Since I employ a hot swappable GPU setup my display manager needs to be restarted upon vm start up and power down. When my display manager is shut off, it logs my user out and thus /dev/shm is nuked and my shared memory file is removed. The shared memory file needs to be created before the virtual machine starts up or looking-glass does not work.

Why is /dev/shm removed?

From Stack Overflow:

After hours of searching and reading, I found the culprit. It’s a setting for systemd . The /etc/systemd/logind.conf contains default configuration options, with each of them commented out. The RemoveIPC option is set to yes by default. That option tells systemd to clean up interprocess communication (IPC) for “user accounts” who aren’t logged in. This does not affect “system accounts”

In my case, the files and directories were being created for a user account, not a system account.

There are two possible solutions:

  1. Create the files with/for a system user – a user created with the system option ( adduser -r or adduser --system )
  2. Edit /etc/systemd/logind.conf , uncomment the line RemoveIPC=yes , change it to RemoveIPC=no , save, and reboot the system

In my case, I went with option #2 because the user was already created.

References:

Solution:

I turned RemoveIPC=no as described above, and I made a new systemd tmp file configuration which will create the shared memory I need at machine boot up.

peter@zenbox3800:/usr/lib/tmpfiles.d$ cat /usr/lib/tmpfiles.d/looking-glass.conf

f /dev/shm/looking-glass 777 peter peter -

Edit: I also had to add this to the end of my release/end libvirt hook script:

systemd-tmpfiles --remove --create /usr/lib/tmpfiles.d/looking-glass.conf

Sources:

https://www.putorius.net/systemd-tmpfiles.html

1 Like