Translate

Archives

Determining Linux Distribution Name and Release

One of the most annoying things about Linux is the inability to easily determine the name and release number of a Linux distribution from with an application. No, contrary to what a lot of people think, uname does not provide either of these bits of information.

The best place to find this information is in the /etc/distribution-release file where distribution is replaced by the name of the distribution. This file should contain a single line in the format:

Distribution release x.x (Codename)


where distribution can be a single word like CentOS or a few words like Red Hat Enterprise Linux. To complicate things, many non-Red Hat RPM-based distributions that derive from Red Hat also include a /etc/redhat-release for compatibility. For example, CentOS 6 includes both.

# cat /etc/redhat-release
CentOS Linux release 6.0 (Final)
 cat /etc/centos-release
CentOS Linux release 6.0 (Final)


Linux System Base-compliant systems should have a file called /etc/lsb_release, which may be in addition to a distribution-specific file, containing at a minimum a field called LSB_VERSION. The value of this field should be a colon separated list of supported module versions indicating the LSB specification modules to which the installation is compliant. If the installation is not compliant, the above field should not be present. Optional fields are DISTRIB_ID, DISTRIB_RELEASE, DISTRIB_CODENAME, DISTRIB_DESCRIPTION and these can be used to override information which is parsed from the /etc/distrib-release file. If a /etc/lsb-release.d directory exists, it is searched for filenames which are taken as additional module-version strings to add to LSB_VERSION. If your distribution is LSB-compliant, it should include the lsb-release utility.

$ lsb_release -irc
Distributor ID: Ubuntu
Release:        9.04
Codename:       jaunty


Unfortunately, not many Linux distributions comply with this requirement out of the box.

SUSE Linux is the most messed up of all the distributions that I have come across as far a /etc/distribution-release is concerned.

$ cat /etc/SuSE-release
SUSE Linux Enterprise Desktop 11 (i586)
VERSION = 11
PATCHLEVEL = 0

$ cat /etc/lsb-release
LSB_VERSION="core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-ia32:core-3.2-ia32:core-4.0-ia32"


It also has /etc/novell-release which is a symbolic link to /etc/SUSE-release.

It is about time that the various Linux distributions tidied up this mess. This is not rocket science; it just requires the developers to the right thing. It should not take 100+ lines of C source code to programmatically determine the name and release of a particular Linux distribution because developers are too lazy or ignorant to comply with a de facto specification.

Comments are closed.