12

I have a number of distros I'm playing with. I label the SD cards, but:

  1. They are in upside down
  2. I'm usually in another room from the RPi

I set up a service in init.d which lets me know via Pushover when my Pi is shutting down or starting up (using the API via curl).

I'd like this to include which distro I'm currently using.

I can see on my latest boot (playing with adafruit Raspbian):

Linux raspberrypi 3.1.9adafruit+ #8 PREEMPT Wed Aug 1 18:02:42 EDT 2012 armv6l

How can I get that information to include in my script?

I installed lsb-release, but that only gives me this:

pi@raspberrypi / $ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux testing/unstable
Release:    testing/unstable
Codename:   n/a

Which would look the same as my regular Raspbian.

In addition, I would probably like to indicate something myself about the particular instance on the SD card (since I'll probably have multiple of the same base distro). Obviously, I can just drop a file in the same place on each SD-card, but is there a convention for where to put that kind of information?

  • Wow, cool. Can you point on how did you put together that pushover/init.d thing? I'll ask a question if you'll answer it :) – Zlatko Aug 9 '12 at 7:05
  • @zladuric Sign up at pushover.net for an account. The curl API is pretty simple. I set up a simple script in init.d as a "service" and it simply sends different notifications on start/stop. Technically it's a start stop notification, so if it ever gets "start" it will send a notification. In practice, nothing starts or stops them except boot and shutdown. If you want the full code, go ahead and post a question. – Cade Roux Aug 9 '12 at 13:40
  • here is the question: raspberrypi.stackexchange.com/questions/1531/… :) – Zlatko Aug 10 '12 at 6:59
8
$ uname -a
Linux raspberrypi 3.1.9+ #174 PREEMPT Sun Jul 22 19:04:28 BST 2012 armv6l GNU/Linux
7

Try

cat /etc/*-release

On my desktop, it gives

NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"

Having checked the official Raspberry Pi images (Raspbian and Arch), /etc/os-release is available on both and contains at least the NAME and PRETTY_NAME properties.

How do I extract the distribution's name?

That's quite simple, try

$ cat /etc/os-release | perl -n -e '/^NAME=\"([a-zA-Z ]*)\"$/ && print "$1\n"'
Arch Linux

References

  1. HowTo: Find Out My Linux Distribution Name and Version
  • Looks good. Ultimately it doesn't matter if this is truly universal, as long as it works for the distros in question. And it would be easy to put one's own file on the filesystem if experimenting with one that doesn't have it by default. – Chris Stratton Aug 9 '12 at 13:06
4

As pointed out, you can use uname, but this will only show the kernel version. If you have the same kernel version on a couple of different distributions/cards (which is very likely since a couple of them are using the same foundation kernel), you will get the same result for each of them. So the best way to differentiate between distros is to use something other than the kernel. There is no universal way however. One easy way would be to use the hostname (and change it for every distro).

cat /proc/version /proc/sys/kernel/hostname

or

hostname && uname -a

  • cat /proc/version /proc/sys/kernel/hostname – Krzysztof Adamski Aug 9 '12 at 13:00
  • hostname && uname -a (assuming hostname works - pi isn't booted to check at the moment) – Chris Stratton Aug 9 '12 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.