Linux get cpu serial number

How to get CPU serial under Linux without root permissions

How can I get CPU serial number under Linux (Ubuntu) without root permissions? I tried cpuid command, it works without root permissions, but appears to return all zeros (I believe because something needs to be changed in BIOS). Can you please suggest me another way to retrieve CPU serial from a program without root permissions and without having to modify BIOS?

7 Answers 7

Root permissions required. The answer is dmidecode.
If you need CPU ID:

dmidecode | grep -w ID | sed "s/^.ID\: //g" 

This will get CPU ID, remove ‘ID: ‘ from output
If you need to receive a computer ID:

dmidecode | grep -w UUID | sed "s/^.UUID\: //g" 

If you wish to get kernel uuid without root permissions, then:

dmesg | grep UUID | grep "Kernel" | sed "s/.*UUID=//g" | sed "s/\ ro\ quiet.*//g" 

It’s because of recent comment. Happened long time ago, so can’t explain now why these ID were taken as machine identifier. Got actual Processor ID fromn Processor Information section. Extracted on Debian OS.

pr=0; dmidecode | while read line; do [ "$line" == "Processor Information" ] && pr=1; [ $pr -eq 0 ] && continue; [ -n "$(echo $line | grep '^ID')" ] && echo $line | awk -F"ID: " '' && break; done 

All of those are incorrect. «dmidecode» returns info about most devices in the system, so there will be a lot of noise — for example, my PC has a PCI express card with ID of «1». But I can guess that the first command was intentded to return «CPUID» — identical value for all processors of same type. Second command will return motherboard UUID — while some motherboards do put unique value there, many leave at all zeros, or re-use same UUID. Finally, the last part is not «kernel UUID» (whatever it is) but rather UUID of your system disk, and changes every time you format it.

Processor serial numbers were basically only in Pentium III processors. Intel removed it from later models due to the privacy concerns that were raised. As such, unless you’re on a PIII AND your BIOS settings let you read the serial number, all you’ll get are 0’s.

Yes but then how other OSes are able to get them? For example WMI on Windows? There must be some workaround for Linux too

@Alexey I hate to revive this ancient thread but it shows up on google, and I just wanted to add that the reason you can get to this information on Windows without admin rights, is because Windows uses a kernel driver to expose this information in userland. You could do the same on Linux in many ways, E.g by putting in the Sudo config that dmidecode can be executed without root rights under a specific account, or by writing a system service that exposes this information through an API in userland. Windows also accesses ‘privileged’ ring 0 information when you request this through WMI.

Читайте также:  Настройка 3proxy для linux

@Alex: CPU serial number quotes Intel as saying the feature isn’t implemented at all: there is no serial number to retrieve. Not just that it requires kernel access. Unless there’s some later CPU feature that reintroduced it in another form, like an MSR. Apparently dmidecode is able to get something, but I don’t know where from. Do we know for sure it’s not just from the motherboard?

@Alex: If the serial number is real and actually stored in the CPU, it would likely be programmed by burning «fuses» in some storage space intended for that. (Like PROM: write once, only by external programming). The same place that gets programmed after a die is tested for its frequency/voltage limits to make it an i7-6700k vs. an i5-6600 or whatever, including programming the model string like Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz . (Intel can also fuse off the high half of the SIMD units to make it a Celeron or Pentium, making it usable even if there was a short-circuit defect there.)

Источник

Getting CPU or motherboard serial number?

I’m trying to get the CPU serial or motherboard serial using C or Python for licensing purposes. Is it possible? I’m using Linux .

Keep in mind the Intel «Processor Serial Number» feature was only ever implemented in the Pentium 3, and some Transmeta CPUs. It was never implemented in any AMD CPUs, or the Pentium 4 or later models.

5 Answers 5

Under Linux, you could use «lshw -quiet -xml» and parse its output. You’ll find plenty of system information here: cpuid, motherboard id and much more.

+1 for this, just for the information of ronakin , call this using subprocess and you can then parse the output.

You need to use the CPUID instruction.

Most C compilers have some support for inline assembly, but you will need to know what you are doing.

You can get the CPUID. Maybe linux command ‘dmidecode’ can help you. You can exec this command,or load the source code of «dmidecode». Next is the output of «dmidecode -t processor»:

>dmidecode -t processor # dmidecode 2.7 SMBIOS 2.2 present. Handle 0x0004, DMI type 4, 32 bytes. Processor Information Socket Designation: Socket 478 Type: Central Processor Family: Pentium 4 Manufacturer: Intel ID: 27 0F 00 00 FF FB EB BF Signature: Type 0, Family 15, Model 2, Stepping 7 Flags: FPU (Floating-point unit on-chip) VME (Virtual mode extension) DE (Debugging extension) PSE (Page size extension) TSC (Time stamp counter) MSR (Model specific registers) PAE (Physical address extension) MCE (Machine check exception) CX8 (CMPXCHG8 instruction supported) APIC (On-chip APIC hardware supported) SEP (Fast system call) MTRR (Memory type range registers) PGE (Page global enable) MCA (Machine check architecture) CMOV (Conditional move instruction supported) PAT (Page attribute table) PSE-36 (36-bit page size extension) CLFSH (CLFLUSH instruction supported) DS (Debug store) ACPI (ACPI supported) MMX (MMX technology supported) FXSR (Fast floating-point save and restore) SSE (Streaming SIMD extensions) SSE2 (Streaming SIMD extensions 2) SS (Self-snoop) HTT (Hyper-threading technology) TM (Thermal monitor supported) PBE (Pending break enabled) Version: Intel(R) Pentium(R) 4 CPU Voltage: 1.5 V External Clock: 133 MHz Max Speed: 3066 MHz Current Speed: 2800 MHz Status: Populated, Enabled Upgrade: ZIF Socket L1 Cache Handle: 0x0008 L2 Cache Handle: 0x0009 L3 Cache Handle: No L3 Cache 

Источник

Читайте также:  Persistent device names linux

How do I check if my Intel processor is genuine?

I recently got an assembled PC. The PC was not assembled in front of my eyes. And the seal for each component’s (the processor, the graphics card. etc) box was not removed before me. I just gave my specifications to a 3rd party computer assembling shop and got it assembled. Now I want to know if my Intel processor is genuine. So I tried getting the processor’s serial number using the terminal (I didn’t want to risk opening my PC myself). The command I used for checking the processor’s serial number:

sudo dmidecode -t system | grep Serial 

The output given by the terminal was : Serial Number: System Serial Number . Does this signify that my processor isn’t genuine (I paid for a genuine one)? Or is it just that some motherboard’s BIOS don’t retrieve this information from the processor? Or is there a better way to figure out if my processor is genuine (without disassembling the PC) ? Additional Info: command : $ lscpu Output:

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz Stepping: 9 CPU MHz: 900.000 CPU max MHz: 4200.0000 CPU min MHz: 800.0000 BogoMIPS: 7200.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 8192K NUMA node0 CPU(s): 0-7 

Источник

How to get cpu serial under linux without root permissions?

In some situations, it may be necessary to retrieve the serial number of the CPU on a Linux system without having access to root permissions. This could be for inventory tracking, security purposes, or other reasons. However, obtaining this information without root access can be challenging, as many standard methods for retrieving the serial number require elevated privileges.

Method 1: Using the dmidecode Command

The dmidecode command is a tool for retrieving hardware information from the BIOS of a computer. It can be used to get the CPU serial number under Linux without root permissions. Here are the steps:

sudo apt-get install dmidecode
dmidecode -t processor | grep -i serial

That’s it! You can now get the CPU serial number under Linux without root permissions using the dmidecode command.

Method 2: Using the lshw Command

To get the CPU serial under Linux without root permissions, you can use the lshw command. Here are the steps to do it:

    Install lshw if it is not already installed on your system. You can do this by running the following command:

lshw -class processor | grep "serial:"
sudo lshw -class processor | grep "serial:"

Here is an example code snippet that demonstrates how to get the CPU serial using lshw:

#!/bin/bash if ! command -v lshw &> /dev/null then echo "lshw could not be found. Please install it." exit fi serial=$(sudo lshw -class processor | grep "serial:" | awk '') echo "CPU serial: $serial"

This script checks if lshw is installed, gets the CPU serial using lshw with sudo, and prints the serial number to the console.

Читайте также:  Linux mint debian edition xfce

That’s it! This is how you can get the CPU serial under Linux without root permissions using the lshw command.

Method 3: Parsing /proc/cpuinfo

Here are the steps to get CPU serial under Linux without root permissions by parsing /proc/cpuinfo:

with open('/proc/cpuinfo', 'r') as f: cpuinfo = f.read()
for line in cpuinfo.split("\n"): if "Serial" in line or "serial" in line: serial = line.split(":")[1].strip() break
print("CPU serial number: <>".format(serial))

Here is the complete code:

with open('/proc/cpuinfo', 'r') as f: cpuinfo = f.read() for line in cpuinfo.split("\n"): if "Serial" in line or "serial" in line: serial = line.split(":")[1].strip() break print("CPU serial number: <>".format(serial))

This code reads the contents of /proc/cpuinfo, searches for the line containing the serial number, extracts the serial number and prints it. This method does not require root permissions.

Note: The serial number may not be present on all systems. In that case, the code will not print anything.

Method 4: Reading from the CPU MSR (Model Specific Register)

To read the CPU serial number from the Model Specific Register (MSR), we need to use the rdmsr instruction. This instruction reads the value of a MSR and stores it in a register.

Prerequisites

Before proceeding with the code, make sure that your system has the following packages installed:

Steps

#include #include #include #include #include #include #include #include  #include  #define MSR_IA32_PLATFORM_ID 0x17 #define MSR_IA32_APIC_BASE 0x1B int main(int argc, char **argv)  int fd, ret; uint64_t msr_val; fd = open("/dev/cpu/0/msr", O_RDONLY); if (fd  0)  printf("Error opening /dev/cpu/0/msr: %s\n", strerror(errno)); exit(1); > ret = pread(fd, &msr_val, sizeof(msr_val), MSR_IA32_PLATFORM_ID); if (ret != sizeof(msr_val))  printf("Error reading MSR_IA32_PLATFORM_ID: %s\n", strerror(errno)); exit(1); > uint32_t cpu_id = (msr_val >> 24) & 0xFF; printf("CPU ID: %u\n", cpu_id); ret = pread(fd, &msr_val, sizeof(msr_val), MSR_IA32_APIC_BASE); if (ret != sizeof(msr_val))  printf("Error reading MSR_IA32_APIC_BASE: %s\n", strerror(errno)); exit(1); > uint32_t apic_id = (msr_val >> 24) & 0xFF; printf("APIC ID: %u\n", apic_id); close(fd); return 0; >
gcc -o cpuserial cpuserial.c

Explanation

The code above opens the MSR device file ( /dev/cpu/0/msr ) and reads the values of two MSRs ( MSR_IA32_PLATFORM_ID and MSR_IA32_APIC_BASE ) using the pread function.

The MSR_IA32_PLATFORM_ID MSR contains the platform ID and CPU ID. We extract the CPU ID by shifting the value 24 bits to the right and masking the result with 0xFF .

The MSR_IA32_APIC_BASE MSR contains the Local APIC ID. We extract the APIC ID in the same way as the CPU ID.

Finally, we print the CPU ID and APIC ID to the console.

Источник

Оцените статью
Adblock
detector