The lsb_release program and the /etc/os-release file

September 26, 2022

Every so often I want to know what Ubuntu release a particular machine is running, and when I do I've become accustomed to using 'lsb_release -r'' to get this information. Sometimes I also want to remember which version of Fedora I'm currently running on my desktops (it changes much more often); depending on my memory at the moment I look at /etc/fedora-release, or /etc/redhat-release, or remember that I actually installed lsb_release on my Fedora machines and use it. Today, I found myself wondering if there was a central file that lsb_release consulted on everything so I could use it and cut out the middleman. The answer turns out to be no and yes, in the traditional Linux way.

(Fedora also has /etc/system-release.)

The 'no' part is that the implementation of lsb_release isn't standardized; in fact, Fedora and Ubuntu have two entirely different versions. Fedora's version is a shell script originally from the 'Free Standards Group' that has been made to check /etc/redhat-release first. Ubuntu's version is a Python program that seems to ultimately wind up reading /usr/lib/os-release, supplemented by interesting information that's found in /usr/share/distro-info. The Ubuntu lsb_release seems to have originally been written for Debian, but I don't know its history beyond that. While the arguments and behavior of lsb_release may be standardized, that's the limit.

As part of this, I also wondered where the Prometheus host agent got its information on OS versions from. The answer turns out to be /usr/lib/os-release (or /etc/os-release, which is a symlink to the /usr/lib version). The os-release file itself is a systemd innovation (cf) which was created to unify the morass of different implementations that Linux distributions used here prior to it. Of course, Linux distributions such as Fedora have carried on supporting their existing files too, because there's probably still code and people out there who look at them. At least Ubuntu's lsb_release now uses os-release and so in theory you could use its code on more or less any systemd-using Linux distribution.

Unfortunately, /etc/os-release is a bit too large and verbose to just dump out, so I expect I'll just keep using 'lsb_release -r' for casual situations. If I have programs that need to know, though, they can read it directly if they want to. However, in shell scripts I think that using lsb_release is probably simpler (and it's also what our scripts currently do in the rare case when they need to know the Ubuntu version they're running on).

Written on 26 September 2022.
« What can a compromised TLS Certificate Transparency Log do?
Reaching past our firewalls with WireGuard (some thoughts) »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Sep 26 22:59:18 2022
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.