1. Introduction
While working with Linux systems, obtaining a storage drive’s (SSD, HDD) serial number can hold significant importance for identification, diagnostics, and management purposes. For instance, when replacing a faulty drive, knowing the serial number can enable a precise swap without disturbing other functioning components.
In this tutorial, we’ll discover various tools to find the serial number of a storage drive in Linux.
2. Using udevadm
udevadm is a utility in Linux used for querying and controlling the udev subsystem. Hence, it provides detailed information about devices connected to the system and enables us to manage device-related events.
Let’s retrieve the serial number via udevadm:
$ udevadm info --query=all --name=/dev/sda | grep SERIAL
E: ID_SERIAL=S1N8NSAG206958
Let’s break down the code:
- –query=all is the query type, requesting all available attributes and information about the specified device
- –name=/dev/sda specifies the device path
- | grep SERIAL filters the output to display only the lines that contain the word SERIAL
In summary, by combining these elements, the command retrieves comprehensive information about the specified device using udevadm, and then filters that information to display only lines containing the word SERIAL.
3. Using hdparm
hdparm is a command-line tool used to examine and configure storage drives in Linux, including retrieving detailed information such as the serial number, model, and firmware details of the connected drives. Hence, it helps manage and optimize drive performance through various commands and settings.
First, let’s install hdparm via apt-get and sudo:
$ sudo apt-get install hdparm
Once it’s installed, we use hdparm to find the storage drive serial number:
$ hdparm -I /dev/sda | grep 'Serial\ Number'
Serial Number: S1N8NSAG206958
In this case, we used -I to retrieve detailed information about the specified hard drive /dev/sda. Lastly, | grep ‘Serial\ Number’ looks for a specific pattern in the output generated by hdparm.
As a result, the output displays only the serial number attribute of the disk.
4. Using lshw
lshw is a command-line tool in Linux for listing detailed information about hardware components in a system. Hence, we can use it to find a storage drive serial number.
We use lshw to list detailed information about disks:
$ lshw -class disk
*-disk:0
description: ATA Disk
product: SAMSUNG MZ7PD256
physical id: 0
bus info: scsi@0:0.0.0
logical name: /dev/sda
version: 6H6Q
serial: S1N8NSAG206958
size: 238GiB (256GB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: ansiversion=5 guid=6ee8cf48-b3e2-43bf-8efc-f4bbde7ee121 logicalsectorsize=512 sectorsize=512
*-disk:1
description: ATA Disk
product: Hitachi HDS72101
vendor: Hitachi
physical id: 1
bus info: scsi@1:0.0.0
logical name: /dev/sdb
version: A41A
serial: JP2940J817EG9V
size: 931GiB (1TB)
capabilities: partitioned partitioned:dos
configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=d4fce463
...
In this case, we can see details for identifying and understanding the physical disks present in the system, including their models, sizes, logical names, and most importantly, their unique serial numbers.
5. Using smartctl
smartctl is a command-line tool in Linux to monitor and manage storage drives with SMART capability. Further, it provides detailed information about the drive’s health, performance, and crucially, its serial number, helping in drive identification and diagnostics.
First, let’s install smartmontools package:
$ sudo apt install smartmontools
Once it’s installed, we use smartctl to find the serial number:
$ smartctl -i /dev/sda
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-6.2.0-35-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Device Model: SAMSUNG MZ7PD256HCGM-000H7
Serial Number: S1N8NSAG206958
LU WWN Device Id: 5 002538 500000000
Firmware Version: DXM06H6Q
User Capacity: 256,060,514,304 bytes [256 GB]
Sector Size: 512 bytes logical/physical
Rotation Rate: Solid State Device
TRIM Command: Available, deterministic, zeroed
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c
SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Wed Dec 6 15:05:11 2023 +0330
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
In this case, the output provides detailed information about the SSD connected to the system, including its specifications, capabilities, and status.
6. Using lsblk
lsblk is a Linux command used to list block devices along with their attributes, including names, sizes, and types, providing a structured overview of storage devices connected to the system.
Let’s see how we can use lsblk to list the storage drive serial numbers:
$ lsblk --nodeps -o name,serial
NAME SERIAL
...
sda S1N8NSAG206958
sdb JP2940J817EG9V
sr0 B4ARQP1361803
In this case, we used –nodeps to ensure that the command doesn’t display any device dependencies such as partitions or other associated devices. Moreover, we used -o name,serial to specify the output columns for the command.
Of course, we can also get the serial number of a specific device:
$ lsblk --nodeps -no serial /dev/sda
S1N8NSAG206958
Here, the -no serial option enables us to specifically retrieve the serial number.
7. Using inxi
inxi is a versatile command-line tool used to gather system information in Linux. So, we can use inxi to find the serial number of a given storage drive.
First, let’s install inxi:
$ sudo apt-get install inxi
Then, we use inxi to get the serial number:
$ inxi -Dxx
Drives:
Local Storage: total: 1.14 TiB used: 17.55 GiB (1.5%)
ID-1: /dev/sda vendor: Samsung model: MZ7PD256HCGM-000H7 size: 238.47 GiB
speed: 6.0 Gb/s serial: S1N8NSAG206958
ID-2: /dev/sdb vendor: Hitachi model: HDS721010CLA632 size: 931.51 GiB
speed: 6.0 Gb/s serial: JP2940J817EG9V
The output provides a clear breakdown of the storage drives present in the system. In this case, we used the -Dxx option to display extended disk information, offering a more comprehensive view that includes specific details such as drive models, sizes, speeds, and serial numbers for the disks in the system.
8. Using GNOME Disks
GNOME Disks utility provides a graphical interface to manage and view information about storage devices connected to the system. Hence, it enables us to find the serial number of the disk.
For this, we just need to open the Disks Utility and select the disk:
Here, the serial number shows as part of the drive’s information.
9. Conclusion
In this article, we explored various powerful tools and utilities available within the Linux environment to find a storage drive (SSD, HDD) serial numbers.
From command-line utilities like udevadm, hdparm, lshw, smartctl, and lsblk, offering detailed insights into device attributes, to versatile system information tools like inxi, each tool provides a unique approach to obtain details about storage drives.