Java Motherboard Serial Number Linux

Active8 months ago

I'm trying to make a java program which will get the serial of the hard disk thru cmd or terminal. I'm trying it on both OS (Windows, Linux). I'm having trouble with Linux, it returns a whitespace, when I type hdparm -I /dev/sda| grep Serial in the terminal It shows the serial number of the hard drive. Hey folks, I want local machine's hardware information mainly motherboard serial number. Application is running on Linux. Is there any way so that I can get main board’s serial number without Running external commands “Runtime.getRuntime().exec()”.

I have multiple harddisks which get connected to my server and I'm not sure which one is what in the view of sdXY . If I can see the serial numbers of my harddisks from terminal, I can easily identify them.

Is there any way I can see them from terminal?

slm
268k74 gold badges579 silver badges725 bronze badges
rɑːdʒɑrɑːdʒɑ
2,7647 gold badges29 silver badges54 bronze badges

8 Answers

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 serial.

JohannJohann

In terminal type:

EDIT: You can also use lshw or smartctl

  • lshw

    # lshw -class disk

  • smartctl

    # smartctl -i /dev/sda

If you are missing those tools, just install following packages

Community
Robert JonczyRobert Jonczy

Device1 name and corresponding serial number:

output:

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

output:

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

output:

Keep in mind lsblklists 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:

don_crisstidon_crissti
54.7k18 gold badges152 silver badges179 bronze badges

By using hdparmyou can see your Harddisk serial number from terminal.

Open your terminal and type as

rɑːdʒɑrɑːdʒɑ
2,7647 gold badges29 silver badges54 bronze badges

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

Ed NevilleEd Neville

Motherboard Serial Number Cmd

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.

Sample:

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

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.

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.

LizardxLizardx

I also like using ls -l /dev/disk/by-id because it'll show a disk's WWN if available. The WWN is usually printed on the disk's label, so it's easy to identify.

user208145user208145
1,4362 gold badges14 silver badges17 bronze badges

This will show the wwn-id for the disk. The awk filter may need to be adjusted depending on the OS distribution and version.I needed a scripted solution to read the wwn-id, which is needed for Pacemaker disk fencing.If partitions (/dev/sdX1 e.g.) have already been created another grep is needed to filter the output:

kemotep
3,1483 gold badges9 silver badges28 bronze badges
tschakkatschakka

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

Active1 month ago

Is there a way to find what motherboard model I have?

If yes, how, please?

Braiam
54.1k21 gold badges144 silver badges229 bronze badges
EdericoEderico
2,1628 gold badges22 silver badges23 bronze badges

6 Answers

There's also some great graphical tools that show you not just your motherboard info, but all info about your computer.

  1. Search for the hardinfo package in the Software Center or run sudo apt-get install hardinfo from the command line. The motherboard make and model can be found on the Devices >DMI page.

  2. CPU-G - Linux alternative to the popular Windows application CPU-Z. Originally created by ftsamis, it has since been picked up by Atareao Team

  3. lshw-gtk – Graphical frontend for lshw command

David Foerster
29.2k13 gold badges68 silver badges115 bronze badges
LnxSlckLnxSlckJava
10.7k1 gold badge33 silver badges49 bronze badges

This will directly show you motherboard info:

or

You can also try:

SchweinsteigerSchweinsteiger
5,1994 gold badges15 silver badges23 bronze badges

Get Serial Number Linux

Non-root user variant

I would like to suggest a variant for the unprivileged users, since it's not always possible to execute commands as root (some users simply cannot and however it is always a good practice to avoid running commands as root when it's not needed) and there the user doesn't want to or can't install new programs:

that it is a short version, shell expanded, of cat /sys/devices/virtual/dmi/id/board_vendor /sys/devices/virtual/dmi/id/board_name /sys/devices/virtual/dmi/id/board_version and gives as a spartan output respectively vendor, name and version:

Note:
Inside the path /sys/devices/virtual/dmi/id/ it's possible to find some files with information about BIOS, board (motherboard), chassis... not all are readable by an unprivileged user due to a security or privacy concerns.

Privileged user variant

Of course, e.g, a sudo cat board_serial (that usually is readable only by root, -r--------) or a sudo cat board_* can easily overcame this limit...

...but, maybe, if privileges are available it's more convenient to use dmidecode as suggested in other answers as well.

Below is the version I prefer, due to the compactness of its output:

The previous command with -A3 will show only the first 3 lines and it is the short version for
sudo dmidecode | grep -A4 '^Base Board Information'that should be better to use if in a script.

Example output:

(1) if it is protected for unprivileged users, then maybe it's better to avoid posting it :-)

Ps> The following works fine too sudo lshw | grep -A5 'Mo' (again 'Mo' is the short for 'Motherboard'), but I find it a little lazier than dmidecode to answer with its output.

HasturHastur
3,0151 gold badge19 silver badges33 bronze badges

You can also use lshw. It is usually run with sudo as that allows it to probe your devices and accurately report back information. Just run

and the first entries in the results will detail your system and the motherboard and the bios, like in the example below:

lshw will give you a lot of other information as well; if you want any particular data in future you can run, for example, sudo lshw -class video to find out about your graphics card. For a listing of the hardware classes lshw analyses, enter sudo lshw -short. For more information on the program, enter man lshw in the terminal or visit the Ubuntu manpages.

As Schweinsteiger has noted, dmidecode is also a useful tool for reporting on motherboard info.

Zanna
53k14 gold badges149 silver badges250 bronze badges
user76204

I found the quickest & easiest way to determine the motherboard model on my computer is:

which, for the Gigabyte Z68MA-D2H-B3 in my computer, yields:

Zanna
53k14 gold badges149 silver badges250 bronze badges
destensondestenson

This worked for me:

see: https://charlieharvey.org.uk/page/motherboard_model_make_serial_linux_or_debian_bash_shell

Paul WPaul W

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