XHTML

Identifying the Distribution of a Linux System

I just needed to test something so I mounted the filesystem of one of my Xen domains in the Dom0 and chroot’d into it (I didn’t need the overhead of running a DomU for a quick test). Then strangely I found that my chroot environment had no apt-get and no dpkg installed.

After a small amount of thought I realised that I had accidentally mounted the filesystem for a Fedora image instead of a Debian image.

It seems to me that it might be a good idea for distributions to have shell scripts replacing the package tools for other distributions. For example dpkg on a Fedora box could be a shell script that runs echo “This system is running Fedora, you want to use rpm instead of dpkg”. Such a command would have saved me a couple of minutes of thinking.

This may sound trivial, but if you consider the number of people who make such mistakes (and the even larger number of people who don’t realise that there is even more than one package tool in existence) then wasting a few K of disk space on every system to help them seems like a good idea.

The minimum size of new hard drives that you can purchase seems to be 36G nowadays. So it’s not as if this would really cost anything.

Please leave comments to tell me if I’m being sensible or silly. If the idea is regarded as good I’ll start filing bug reports.

Unfortunately, I don’t think this is a good idea. Package management tools have other uses besides simply installing a particular package on your system. Perhaps you want to install to a chroot, or just unpack the files, or examine some metadata in the package.

Instead, I would recommend looking at some of the lsb tools. For example, on my system:

$ lsb_release -i
Distributor ID: Debian

And the -a flag gives more information. Unfortunately, these tools seem to be handled differently in Debian, Ubuntu, and Fedora. *Sigh* I thought that was the entire point. So for now, when I need to do distro checking, I end up examining /etc/issue, and checking for the presence of /etc/lsb-release, /etc/debian_version, and /etc/redhat-release.

apt-get is available for Fedora, and Yum is available for Debian. You can’t tell people which package management system they should be using. And a one-line “use rpm instead of dpkg” really doesn’t help when you don’t know how to use rpm.

On the other hand, I’m pretty sure there are scripts out there already which will detect what distro you are using by the existence of certain files – that should be enough for geeks. If you’re running X then it’s likely to tell you on the login screen – that should be enough for non-geeks.

if you consider the number of people who make such mistakes (and the even larger number of people who don’t realise that there is even more than one package tool in existence)

I would bet there are literally millions of people in this constituency. Why, just yesterday, my little sister mounted the filesystem of one of her Xen domains in the Dom0 and chrooted into it. And, erm, could remember what OS was installed on it.

And what do you do about Debian’s rpm package? Truth is, apt/dpkg/rpm/yum whatever do not determine what distro you are using. Plus, if you mounted the wrong partition, then you should be glad you didn’t mount an unrelated Debian partition.

I think that the combination of /etc/issue, /etc/issue.net, and /etc/motd should be sufficient to identify an installed operating system.

Failing that looking for programs won’t necessarily help. Consider the case of a Debian installation which has RPM installed for alien to use – you’ll type “rpm” and it will not say “Hey! I’m Debian really!”, so you’ve not gained anything.

Please don’t. I’m all in favour of making life easier for your mistakes, but I’m quite convinced there are many scripts and tools in existence that test for [ -x /usr/bin/dpkg ] and variants. I’m not saying they are considering the existence of such a binary as proof of Debianness of the system (anthough I don’t doubt some do), but they will generally assume that if there’s a /usr/bin/dpkg, then it’s going to be dpkg and not a very small shell script.

doesn’t Ubuntu have something similiar for commands that are available in not installed packages? (i.e. you type “vim” and bash says something like: ,,”vim” not found. Maybe you want to install the “vim-tiny” package that contains this program?´´)