Getting serial number linux

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.

@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?

Читайте также:  Linux заархивировать всю систему

@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.)

Источник

Extract the Linux serial number without sudo

It is possible to extract the Linux serial number without using sudo? I know it is possible to do in Windows: wmic bios get serialnumber and in macOS: system_profiler | grep «r (system)» . Both of them do not require root privileges. In Linux this can be used: sudo dmidecode -s system-serial-number , but it needs sudo. Is there another way?

3 Answers 3

dmidecode reads this information from physical memory, using /dev/mem , which requires root.

The same information is also provided by the Linux kernel via sysfs in a virtual directory, /sys/devices/virtual/dmi/id .

Unfortunately, someone decided that all information in that virtual directory is open to anyone for reading, just not the serial numbers:

$ ls -l /sys/devices/virtual/dmi/id -r--r--r-- 1 root root 4096 Nov 25 17:12 bios_date -r--r--r-- 1 root root 4096 Nov 14 14:59 bios_vendor -r--r--r-- 1 root root 4096 Nov 25 17:12 bios_version -r--r--r-- 1 root root 4096 Nov 25 17:12 board_asset_tag -r--r--r-- 1 root root 4096 Nov 25 17:12 board_name -r-------- 1 root root 4096 Nov 25 17:12 board_serial -r--r--r-- 1 root root 4096 Nov 14 14:59 board_vendor -r--r--r-- 1 root root 4096 Nov 25 17:12 board_version -r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_asset_tag -r-------- 1 root root 4096 Nov 25 17:12 chassis_serial -r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_type -r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_vendor -r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_version -r--r--r-- 1 root root 4096 Nov 25 17:12 modalias drwxr-xr-x 2 root root 0 Nov 25 17:12 power -r--r--r-- 1 root root 4096 Nov 14 14:59 product_name -r-------- 1 root root 4096 Nov 25 17:12 product_serial -r-------- 1 root root 4096 Nov 14 14:59 product_uuid -r--r--r-- 1 root root 4096 Nov 14 14:59 product_version lrwxrwxrwx 1 root root 0 Nov 14 14:59 subsystem -> ../../../../class/dmi -r--r--r-- 1 root root 4096 Nov 14 14:59 sys_vendor -rw-r--r-- 1 root root 4096 Nov 14 14:59 uevent 

If you can install package hal (not installed by default on recent Ubuntu versions), this command will work for you as non-root:

 lshal | grep system.hardware.serial system.hardware.serial = '' (string) 

This works because package hal installs the hald daemon, which runs as root and collects this data, making it possible for lshal to read it as non-root.

Читайте также:  Linux shared library linking

Источник

Harddisk serial number from terminal?

I have multiple hard disks which get connected to my server and I’m not sure which one is what in the view of sdXY. If I could see the serial numbers of my hard disks from terminal, I could easily identify them. Is there any way I can get the serial numbers from the terminal?

10 Answers 10

Another solution which does not require root privileges:

udevadm info --query=all --name=/dev/sda | grep ID_SERIAL 

This is actually the library that lsblk , mentioned by don_crissti, leverages, but my version of lsblk does not include the option for printing the serial number.

grep ID_SCSI_SERIAL may be what actually gives the serial number of the drive, as opposed to the world wide name (wwn) reported under ID_SERIAL .

only reference is my first hand experience with WD, Seagate, HGST hard drives comparing values at the terminal to what is written on the label. Hard drives are primarily enterprise/data center grade versus consumer desktop.

@ron Just tested this again. My version of udevadm (systemd 229) reports an ID_WWN field. For the drives in my system, there is also no ID_SCSI_SERIAL nor anything analogous (no ID_ATA_SERIAL ): E: ID_SERIAL=TOSHIBA-TR150_23SC51E8J2BI . E: ID_SERIAL_SHORT=23SC51E8J2BI . E: ID_WWN=0x5e83a97200463ff3 . E: ID_WWN_WITH_EXTENSION=0x5e83a97200463ff3

# hdparm -I /dev/sd? | grep 'Serial\ Number' 

EDIT: You can also use lshw or smartctl

If you are missing those tools, just install following packages

# apt-get install hdparm # apt-get install smartmontools # apt-get install lshw 

Thanks for the answer I have tested it. But its not giving the dev/sdXX . Please try to fix it. unless its good

Does not work if your hard disk has died completely and you’re looking for the serial number of the faulty unit. Use @Johann’s method instead.

Use hdparm -I /dev/sd? | grep —before-context=4 ‘Serial\ Number’ to correlate the serial number with the device. It looks like the original question requests that result.

Device 1 name and corresponding serial number:

lsblk --nodeps -o name,serial 
NAME SERIAL sda 0000000012400917BA30 sdb 0000000012400917BA96 

add -n if you don’t want to print the header line:

lsblk --nodeps -no name,serial 
sda 0000000012400917BA30 sdb 0000000012400917BA96 

Pass device as argument to get only the serial number of a specific device:

lsblk --nodeps -no serial /dev/sda 

Keep in mind lsblk lists information about all available (or the specified) block devices. Now, for those who do not know what that last term means:
In general, block devices are devices that store or hold data. Diskette drives, hard drives and CD-ROM drives are all block devices. But that’s not a problem when using lsblk as you can simply add more columns e.g type (device type) and/or tran (device transport type) etc:

lsblk --nodeps -no name,serial,type,tran
sda 0000000012400917BA30 disk sata sdb 0000000012400917BA96 disk sata sr0 4B583242334C453233353320 rom usb 

Note that this appears to require lsblk from util-linux version 2.24 or higher: github.com/karelzak/util-linux/commit/…

How to retrieve hard disk serial when I use a VM ubuntu? The above commands return nothing on this situation

By using hdparm you can see your Harddisk serial number from terminal.

Open your terminal and type as

 hdparm -I /dev/sd?|grep -E "Number|/dev" 

Well, but you need to be superuser to use the -I option in hdparm . I would not want that either and prefer a way how to read out the ser # without root permissions. This is why I’ve upvoted don_crissti’s solution only. – syntaxerror 57 secs ago

This will show you the serial number against the familiar disk name.

This is a clever approach but doesn’t work on my virtual box. It looks like the contents of the by-id dir are just symlinks, so ls -al /dev/disk/by-id/ will show you what you need anyway.

This also worked for me on a debian live boot system, while all the other tools are not available from scratch, without setting up internet and apt-getting them.

even this fails on my system as mentioned above, then using the basic, as @Wildcard mentioned you can see my SCSI card may just be having a bad day.. $ ls -al /dev/disk/by-id | grep sdh lrwxrwxrwx. 1 root root 9 Nov 14 22:21 scsi-350000c0f01e63ff0 -> ../../sdh lrwxrwxrwx. 1 root root 10 Nov 14 22:21 scsi-350000c0f01e63ff0-part1 -> ../../sdh1 lrwxrwxrwx. 1 root root 10 Nov 14 22:21 scsi-350000c0f01e63ff0-part9 -> ../../sdh9 lrwxrwxrwx. 1 root root 9 Nov 14 22:21 wwn-0x50000c0f01e63ff0 -> ../../sdh .

Easiest way I know (does not require root):

That outputs all disks, their serials, and any extra info. -p adds partitions. -l adds labels. -u adds UUID for the partitions.

Plus it’s a lot easier to remember, heh.

inxi -Dxx Drives: HDD Total Size: 810.2GB (42.9% used) ID-1: /dev/sdc model: ST3160827AS size: 160.0GB serial: 5MT2HMH6 ID-2: /dev/sdb model: WDC_WD3200JD size: 320.1GB serial: WD-WCAMR1302926 ID-3: /dev/sda model: ST380817AS size: 80.0GB serial: 4MR2EWBE ID-4: /dev/sdd model: ST3250824AS size: 250.1GB serial: 9ND08GKX 

Note that this filters out optical drives. To see optical data:

inxi -Dxxd Drives: HDD Total Size: 810.2GB (42.9% used) ID-1: /dev/sdc model: ST3160827AS size: 160.0GB serial: 5MT2HMH6 ID-2: /dev/sdb model: WDC_WD3200JD size: 320.1GB serial: WD-WCAMR1302926 ID-3: /dev/sda model: ST380817AS size: 80.0GB serial: 4MR2EWBE ID-4: /dev/sdd model: ST3250824AS size: 250.1GB serial: 9ND08GKX Optical-1: /dev/sr0 model: LITE-ON DVDRW SOHW-1693S rev: KS09 dev-links: dvd,dvdrw Features: speed: 48x multisession: yes audio: yes dvd: yes rw: cd-r,cd-rw,dvd-r state: running Optical-2: /dev/sr1 model: LITE-ON LTR-52327S rev: QS0C dev-links: cdrom,cdrw Features: speed: 52x multisession: yes audio: yes dvd: no rw: cd-r,cd-rw state: running 

Note that on my Debian system, lsblk does not show anything for serials, whether as root or user. Which is why inxi uses a much more reliable method to get that data.

lsblk --nodeps -o name,serial NAME SERIAL fd0 sda sdb sdc sdd sr0 sr1 lsblk --version lsblk from util-linux 2.25.2 

As you can see, to lsblk, it thinks that an optical drive and floppy drive are also disks, which in a sense they are, though not really, since they don’t become disks until a disk is inserted. And it shows nothing for serial, it also by the way shows nothing for other values, like label. Definitely a bug since this data is available to the system, that’s where inxi gets it, direct.

Источник

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