Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to programmatically detect if Linux is running on a ThinkPad.

A shell script would be ideal but I can programmatically generate any binary by downloading some source and compiling it on the machine if only a custom program will be able to reliably do that.

Focus is: reliability/accuracy. If in doubt, I prefer not to run the script.

I have a hunch this may be cleverly done using text parsing of things like dmesg or lshw, but which method is the most reliable?

Restriction: run as a normal user, as part of a login script, no possibility of temporarily elevating privileges just to detect the machine model.

Permission: take as long as needed, speed is not a factor.

Environment: Ubuntu, but Linux generality is nice to have. Availability of developer-level build tools (GCC can be assumed to "just work"). The login script is run by bash so a code snippet in that syntax would be more directly usable.

share|improve this question
As far as I can understand, you want to make sure you are on Linux using a shell script. I guess uname -o # --operating-system may help. I'm on Ubuntu 13.4 latest, and it reports GNU/Linux. –  user27225 Apr 10 '13 at 11:06
@gkya He doesn't: he wants to make sure he's on Linux running on a ThinkPad machine. –  Renan Apr 10 '13 at 14:00
You might be able to do dmesg or lspci -v and then grep (IBM|Lenovo) on their output. –  Renan Apr 10 '13 at 14:14

2 Answers 2

The following works on my Lenovo ThinkPad (Running FC17):

cat /sys/devices/virtual/dmi/id/chassis_vendor



The following directory can be checked for /proc/acpi/ibm/. You could look in /proc/acpi/ibm/driver for "ThinkPad ACPI Extras".

share|improve this answer

dmidecode can provide this information. It however requires root privileges to access /dev/mem, so due to your restrictions this can not be used directly.

You have two options.

A) Log in as root and run dmidecode -t system > /var/tmp/dmidecode_system Then ensure that the file is world readable and check the contents of that file in the user's login script.

The problem is that the information will only be updated "manually". You could however simply update it from an init script.

B) A more "live" option is to create a little tool which provides the required information to non-priviledged processes.

First create an interface, eg mkfifo /var/tmp/dmidecode_read

Then spawn a process which will write the information every time someone requests it, eg

while true; do dmidecide -t system > /var/tmp/dmidecode_read; done

In this case this will work, because you can not replace a motherboard while the system is running. But for completeness' sake I mention that this information could still theoretically become stale. Each time a a user reads from the pipe, the current buffer is emptied, the sleeping "supplier" exists, a and then after the reader received the existing buffer, a new "supplier" will be spawned and it will put fresh information into the buffer ready for the next reader, whenever that will be.

share|improve this answer
It's probably easier to make dmidecode setuid –  Michael Mrozek Apr 10 '13 at 14:13
That would violate the "do not temporarily increase privileges" requirement. –  Johan Apr 11 '13 at 6:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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