Show actual distro info instead of "Ubuntu Core 18"?

Hi,

I made a snap for my app, and everything is working perfectly except on thing, which is:

If I run my tool locally without snap, this line will read like:

Linux distro: Ubuntu 19.10 eoan

while on snap this same line will say:

Linux distro: Ubuntu Core 18 

I understand this correct as in snap that’s the actual environment information. However, I was wondering is there any way to get it to display my host distro information?

Thanks

if you use the system-observe plug you should be able to read:

/var/lib/snapd/hostfs/etc/os-release

which has the info from the host machine …

1 Like

Perfect, exactly what I was looking for.

Thanks!

I’m about to release my snap, and I was planning to use classic confinement which I thought has unrestricted access to all system resources.

However, after building my snap and then installing it with:
snap install auto-cpufreq_1.0_amd64.snap --classic --dangerous

After I run the app, I get an error, i.e:

sudo auto-cpufreq --live

----------------------------- System information ------------------------------

Traceback (most recent call last):
  File "/snap/auto-cpufreq/x1/bin/auto-cpufreq", line 108, in <module>
    main()
  File "/snap/auto-cpufreq/x1/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/snap/auto-cpufreq/x1/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/snap/auto-cpufreq/x1/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/auto-cpufreq/x1/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/snap/auto-cpufreq/x1/bin/auto-cpufreq", line 73, in main
    sysinfo()
  File "/snap/auto-cpufreq/x1/lib/python3.6/site-packages/source/core.py", line 324, in sysinfo
    searchfile = open("/var/lib/snapd/hostfs/etc/os-release", "r")
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/snapd/hostfs/etc/os-release'

Building the snap in devmode confinement and installing it as such shows no errors. Do you know why this is the case?

classic snaps behave differently and do not use interfaces at all when you use --devmode you set a strict snap into a lose confinement mode so that you can catch any denials in your system log to fix the confinement … if you use classic confinement, all of the confinement features (including interfaces) get turned off …

that said, you should be able to just access /etc/os-release directly under classic confinement. …

Right, that’s what I thought as well. This is what my snapcraft file looks like.

Building and installing it with snap install auto-cpufreq_1.0_amd64.snap --classic --dangerous will result in error above, as /var/lib/snapd/hostfs/etc/os-release file really doesn’t exist in classic confinement.

But if I changed confinement to devmode, build and install it with snap install auto-cpufreq_1.0_amd64.snap --dangerous I won’t get any errors and file will be available.

Update

I set to use /usr/lib/os-release which is available and works on both devmode and classic confinement.

Right, the hostfs is directly accessible to classic snaps so you don’t need to use the /var/lib/snapd/hostfs prefix because you can just go direct to the file. That’s why snapd doesn’t even set the /var/lib/snapd/hostfs mount up for a classic snap at all, making your attempt to access it result in a not found error.

Okay, that’s good to know.