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.
Как узнать информацию о жестких дисках (серийный номер, модель, интерфейс)
Как узнать информацию о жестких дисках (серийный номер, модель, интерфейс).
В теме «Как узнать информацию о жестких дисках (серийный номер, модель, интерфейс)» я расскажу как можно узнать серийный номер, модель или интерфейс вашего устройства на жестком диске. Существует довольно много решений, приведу несколько.
Первое что я сделаю, так это посмотрю какие у меня разделы имеются:
вывод имеющихся разделов программой lsblk
1. Первую утилиту что я могу порекомендовать Вам — это утилита hdparm.
Если вы используете RedHat/Centos/Fedora:
Если вы используете Debian/Ubuntu/Linux Mint для установки программы:
Чтобы использовать эту утилиту нужно запустить ее с опцией «-i» и добавить нужный нам раздел:
пример использования hdparm с ключем -i для раздела sdf
2. Советую так же утилиту lshw.
Эта программа показывает информацию не только о HDD, так же она выводит в удобно для вас формате (TXT-формате, HTML или XML).
Чтобы установить ее на CentOS/RedHat/Fedora, но если не стоит у вас эта программа, нужно выполнить:
Чтобы установить ее на Ubuntu/Linux Mint или Debian:
# sudo apt-get install lshw lshw-gtk
Чтобы получить нужную информацию с помощью утилиты lshw, выполните:
# lshw -class disk -class storage
пример использования lshw -class disk -class storage
Если вам нужно вывести информацию только об установленных дисках на вашей ОС, вы можете использовать:
пример использования команды lshw -short -C disk
3. Что еще за утилиту могу посоветовать для использования — так это smartctl.
При помощи программы smartctl можно выводить информацию о состоянии ваших устройств, которые поддерживают SMART. Вот пример использования команды для SATA-устройства:
# smartctl -d ata -a -i /dev/sda
Я использую просто вот так:
4. Напоследок, приведу я графическую утилиту — GNOME Disk Utility.
Чтобы установить ее для использования в Debian/Ubuntu/ Linux Mint, выполните:
# sudo apt-get install gnome-disk-utility
Если используете Fedora/CentOS или RedHat, то выполните:
# yum install gnome-disk-utility
Утилита эта удобна тем, что у нее есть графический интерфейс (GUI), после установки вы можете ее запустить через командную строку ( а можно и найти ее в меню):
Очень проста в использовании и очень простая.