I am writing a common code in a driver to get the distros name and host name. host name i am taking from struct utsname{nodename[]}, but how do I get the distro name?

  • 1
    It really doesn't make sense to talk about distro inside the kernel. In userland you can call lsb_release -i though.
    – o11c
    Commented Oct 15, 2014 at 5:17
  • Need to add a sysfs entry for my driver. That is why I am trying to get it inside kernel. @o11c Commented Oct 15, 2014 at 5:29

3 Answers 3


Most programs and scripts I've seen parse the usual files in /etc, AFAIK there's no other way:

On Redhat, look for /etc/redhat-release
On Debian, look for /etc/debian_version
Mandriva has /etc/version
and Slackware has /etc/slackware-version

You could also use uname to get the ARCH or, probably the most sane way, use lsb_release.

  • thanks for your response. I need this info. in kernel space. It would be helpful if some can help me to get distro name in kernel space. Commented Oct 16, 2014 at 3:25
  • What you're looking for does not exist.
    – Jan
    Commented Oct 16, 2014 at 6:32

You can take a look at how facter does it here.

As Jan said, lsb_release is probably the best way to go, but it cannot be your only way. For example, lsb_release is not present by default on any of my RHEL servers:

[damaya@damaya-sandbox script]$ lsb_release
-bash: lsb_release: command not found
[damaya@damaya-sandbox script]$ yum provides "*/lsb_release"
redhat-lsb-core-4.0-7.el6.centos.i686 : LSB base libraries support for CentOS
Repo        : base
Matched from:
Filename    : /usr/bin/lsb_release

So, if lsb_release is not present on the system, then your next step is to get the information from the /etc/*-release file. However, if that is also not present on the system then you are out of luck. Unfortunately, there does not exist a 100% reliable way to get this information.


The Scope for getting distro name is not in kernel development scope. So no specific method is present currently. I am asking for module param in my driver for this. you can also ask for a ENV variable while compiling.

Thanks, for your help...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .