Skip to content

Instantly share code, notes, and snippets.

@natefoo
Last active June 14, 2025 11:01
Show Gist options
  • Save natefoo/814c5bf936922dad97ff to your computer and use it in GitHub Desktop.
Save natefoo/814c5bf936922dad97ff to your computer and use it in GitHub Desktop.
Linux Distribution Detection

Distribution Detection

I am working on adding support for building and distributing (via PyPI) Python Wheels with C Extensions to the Python wheel and pip packages. The discussion on Distutils-SIG continues, but I believe it is fairly certain that some effort to correctly identify Linux distributions will need to be made. I've begun efforts to add this support to wheel.

How you can help

If you have a Linux distribution or version of a listed distribution not in this gist, I could use the following:

  • The contents of /etc/os-release, if it exists
  • Whether or not the lsb_release program is installed, and whether it's part of a "default" install
  • The output of lsb_release -a if installed
  • The contents of /etc/lsb-release, if it exists
  • The contents of any other /etc/*-release files
  • Any other reliable way to determine the flavor and version of your Linux distribution, especially if none of the above exist

And finally, you can test the platform detection on your platform by downloading and installing (e.g. in a virtualenv) my changes to wheel and running:

% python -c 'import wheel.pep425tags; print wheel.pep425tags.get_platforms()'

e.g.:

% pip install -e 'hg+https://bitbucket.org/natefoo/wheel#egg=wheel'
% python -c 'import wheel.pep425tags; print wheel.pep425tags.get_platforms()'
['linux_x86_64_ubuntu_14_04', 'linux_x86_64', 'any']

If lsb_release is optional on your system and especially if /etc/os-release does not exist, it'd be even more helpful to run the above prior to installing lsb_release, and again afterward.

Debian

Debian stretch

/etc/os-release

Doesn't include a version or version_id, so this results in reading the distro name from /etc/os-release but version detection falls through to the "legacy" method of reading from /etc/debian_version.

PRETTY_NAME="Debian GNU/Linux stretch/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support/"
BUG_REPORT_URL="https://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux testing (stretch)
Release:	testing
Codename:	stretch

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

stretch/sid

get_platforms()

['linux_x86_64_debian_stretch_sid', 'linux_x86_64', 'any']

Debian 8 (jessie)

/etc/os-release

PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="https://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 8.1 (jessie)
Release:	8.1
Codename:	jessie

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

8.1

get_platforms()

['linux_x86_64_debian_8', 'linux_x86_64', 'any']

Debian 7 (wheezy)

/etc/os-release

PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 7.8 (wheezy)
Release:	7.8
Codename:	wheezy

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

7.8

get_platforms()

['linux_x86_64_debian_7', 'linux_x86_64', 'any']

Debian 6 (squeeze)

/etc/os-release

Does not exist

lsb-release -a

lsb_release is not installed as part of a base system, and is included in the lsb-release package.

Distributor ID:	Debian
Description:	Debian GNU/Linux 6.0.10 (squeeze)
Release:	6.0.10
Codename:	squeeze

/etc/lsb-release

Does not exist

Distro-specific files

/etc/debian_version:

6.0.10

get_platforms()

With lsb_release installed:

['linux_x86_64_debian_6_0_10', 'linux_x86_64_debian_6', 'linux_x86_64', 'any']

Without:

['linux_x86_64_debian_6_0_10', 'linux_x86_64_debian_6', 'linux_x86_64', 'any']
@ColdGrub1384
Copy link

thanks, just what I need

@Wuodan
Copy link

Wuodan commented Jun 15, 2018

Thanks. I forked and added data for Gentoo:
https://gist.github.com/Wuodan/52d9761a77331ca3b8d044a50b910f52

Had a syntax error running your script ... and unless I'm wrong your fork of wheel is way behind upstreams - which moved to github.

@ajaguilarbravo-ent
Copy link

Awesome!!! What i was looking for.

@joelbarker2011
Copy link

MX Linux

  • The contents of /etc/os-release, if it exists
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • Whether or not the lsb_release program is installed, and whether it's part of a "default" install
    Default install.

  • The output of lsb_release -a if installed

No LSB modules are available.
Distributor ID:	MX
Description:	MX 18.3 Continuum
Release:	18.3
Codename:	Continuum
  • The contents of /etc/lsb-release, if it exists
PRETTY_NAME="MX 18.3 Continuum"
DISTRIB_ID=MX
DISTRIB_RELEASE=18.3
DISTRIB_CODENAME=Continuum
DISTRIB_DESCRIPTION="MX 18.3 Continuum"
  • The contents of any other /etc/*-release files
### /etc/initrd-release ###
NAME="MX"
VERSION="18.3 (Continuum)"
ID="mx"
VERSION_ID="18.3"
PRETTY_NAME="MX 18.3 (Continuum)"
ANSI_COLOR="0;34"
HOME_URL="https://mxlinux.org"
BUG_REPORT_URL="https://mxlinux.org"

Any other reliable way to determine the flavor and version of your Linux distribution, especially if none of the above exist

### /etc/antix-version ###
MX-18.3_x64 Continuum May 26, 2019

### /etc/mx-version ###
MX-18.3_x64 Continuum May 26, 2019

### /etc/live/version/antiX ###
Distro name:MX
Version:18.3
antiX flavour:mx
Kernel:4.19.0-5-amd64
Code name:Continuum
Release date:May 26, 2019
Made by:build-iso version 1.00.08 (Mon Oct 23 10:16:23 MDT 2017)

### /etc/live/version/linuxfs.ver ###
=== 3c5cf14ffb909be6178a936578904031

title: Original MX 18.3 x64
creation date: 25 May 2019 19:15:39 EDT
kernel: 4.19.0-5-amd64
inxi version: MX-18.3_x64 Continuum May 26, 2019
  • And finally, you can test the platform detection on your platform by downloading and installing (e.g. in a virtualenv) lionshead and running:
$ python3 -c 'import lionshead; print(lionshead.get_specific_platform())'
['linux_x86_64_debian_9', 'linux_x86_64', 'any']

@aayla-secura
Copy link

aayla-secura commented Oct 25, 2019

Kali

Rolling, 2019.2

  • The contents of /etc/os-release, if it exists
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2019.2"
VERSION_ID="2019.2"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.kali.org/"
SUPPORT_URL="https://forums.kali.org/"
BUG_REPORT_URL="https://bugs.kali.org/"
  • Whether or not the lsb_release program is installed, and whether it's part of a "default" install
    It is installed by default
  • The output of lsb_release -a if installed
Distributor ID:	Kali
Description:	Kali GNU/Linux Rolling
Release:	2019.2
Codename:	n/a
  • The contents of /etc/lsb-release, if it exists
DISTRIB_ID=Kali
DISTRIB_RELEASE=kali-rolling
DISTRIB_CODENAME=kali-rolling
DISTRIB_DESCRIPTION="Kali GNU/Linux Rolling"
  • The contents of any other /etc/*-release files
    No other such files

@tpanj
Copy link

tpanj commented Oct 27, 2019

Mageia

Mageia 7

/etc/os-release

NAME="Mageia"
VERSION="7"
ID=mageia
VERSION_ID=7
ID_LIKE="mandriva fedora"
PRETTY_NAME="Mageia 7"
ANSI_COLOR="1;36"
HOME_URL="http://www.mageia.org/"
SUPPORT_URL="http://www.mageia.org/support/"
BUG_REPORT_URL="https://bugs.mageia.org/"
PRIVACY_POLICY_URL="https://wiki.mageia.org/en/Privacy_policy"

lsb-release -a

LSB Version:    *
Distributor ID: Mageia
Description:    Mageia 7
Release:        7
Codename:       mga7

/etc/lsb-release

LSB_VERSION=
DISTRIB_ID="Mageia"
DISTRIB_RELEASE=7
DISTRIB_CODENAME=mga7
DISTRIB_DESCRIPTION="Mageia 7"

Distro-specific files

/etc/mageia-release:

Its existence indicates that the distro is Mageia.

get_platforms()

Untested, should be:

['linux_x86_64_mageia_rolling', 'linux_x86_64', 'any']

@tpanj
Copy link

tpanj commented Oct 27, 2019

I want to help!

Hello!
I started to build small but strong foundation for helping everyday living in bash - maybe suitable for this gist.
Please let me know if there is something I can include or
improve at https://github.com/tpanj/bash4all

Best Regards,
Tadej

@bwolfbarn
Copy link

bwolfbarn commented Nov 29, 2020

Debian buster on WSL2

The contents of /etc/os-release, if it exists

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Whether or not the lsb_release program is installed, and whether it's part of a "default" install

The output of lsb_release -a if installed

-bash: lsb_release: command not found

The contents of /etc/lsb-release, if it exists

cat: /etc/lsb-release: No such file or directory

The contents of any other /etc/*-release files

$ ls /etc/*-release
... /etc/os-release -> ../usr/lib/os-release

@bwolfbarn
Copy link

Raspberry OS (Debian) on Raspberry Pi

The contents of /etc/os-release, if it exists

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Whether or not the lsb_release program is installed, and whether it's part of a "default" install

yes, default

The output of lsb_release -a if installed

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

The contents of /etc/lsb-release, if it exists

cat: /etc/lsb-release: No such file or directory

The contents of any other /etc/*-release files

ls /etc/*-release -l
... /etc/os-release -> ../usr/lib/os-release

@Galacticai
Copy link

Very useful thanks

@mikefaille
Copy link

mikefaille commented Mar 15, 2022

Oracle Linux 6.8

NAME="Oracle Linux Server" 
VERSION="6.8" 
ID="ol" 
VERSION_ID="6.8" 
PRETTY_NAME="Oracle Linux Server 6.8" 
ANSI_COLOR="0;31" 
CPE_NAME="cpe:/o:oracle:linux:6:8:server"
HOME_URL="https://linux.oracle.com/" 
BUG_REPORT_URL="https://bugzilla.oracle.com/" 

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 6" 
ORACLE_BUGZILLA_PRODUCT_VERSION=6.8 
ORACLE_SUPPORT_PRODUCT="Oracle Linux" 
ORACLE_SUPPORT_PRODUCT_VERSION=6.8

Oracle Linux 7.1

NAME="Oracle Linux Server"
VERSION="7.1"
ID="ol"
VERSION_ID="7.1"
PRETTY_NAME="Oracle Linux Server 7.1"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:7:1"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://bugzilla.oracle.com/"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 7"
ORACLE_BUGZILLA_PRODUCT_VERSION=7.1
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=7.1

@duzhuoshanwai
Copy link

Debian bookworm /etc/os-release

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

@saizai
Copy link

saizai commented Nov 7, 2023

Synology DSM

Synology doesn't have /etc/*-release or lsb_release.

info

It's a custom GNU/Linux kernel. See:

detection

Detectable by lots of /etc/syno*, /usr/syno/*, /proc/syno*, etc. files.

On a Synology 1621+ NAS device, which has V1000 CPU architecture, if it's running DSM version 7.0-41890 (which has a modified Linux kernel 4.4.180), you get this (custom name and serial redacted with identical format):

/usr/bin/uname -a

Linux CustomNASNameHere 4.4.180+ #41890 SMP Thu Jul 15 03:42:45 CST 2021 x86_64 GNU/Linux synology_v1000_1621+

Relevant extracts of files:

/etc/synoinfo.conf

upnpdevicetype="Synology NAS"
upnpfriendlyname="Synology NAS Device"
upnpmodeldescription="Synology NAS UPnP Device"
upnpmodelname="DS1621+"
company="synology"
product="Synology NAS"
synobios="v1000"
unique="synology_v1000_1621+"

/etc/avahi/services/dsminfo.service

<txt-record>vendor=Synology</txt-record>
<txt-record>model=DS1621+</txt-record>
<txt-record>serial=1234A5BCDEFGH</txt-record>
<txt-record>version_major=7</txt-record>
<txt-record>version_minor=0</txt-record>
<txt-record>version_build=41890</txt-record>

/etc/VERSION

majorversion="7"
minorversion="0"
major="7"
minor="0"
micro="0"
productversion="7.0"
buildphase="GM"
buildnumber="41890"
smallfixnumber="0"
nano="0"
base="41890"
builddate="2021/07/15"
buildtime="18:42:50

/proc/cpuinfo

vendor_id       : AuthenticAMD
cpu family      : 23
model           : 17
model name      : AMD Ryzen Embedded V1500B

/proc/syno_cpu_arch

AMD, Ryzen, V1500B, 4

/proc/syno_platform

V1000

/proc/version

Linux version 4.4.180+ (root@build17) (gcc version 7.5.0 (GCC) ) #41890 SMP Thu Jul 15 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment