Get disk serial number of "/" from the command line

joegood used Ask the Experts™
hdparm -i /dev/hda seems to work but only if I am root.  Is there a way to get this as a non-root user?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Not unless you want to expose your entire system.  Even if you give execute access to a specific group to run /sbin/hdparm, HD the device is restricted. /dev/hda

so unless you want to give access to /dev/hda, NOT A GOOD IDEA, you must be root

install, configure and use "sudo"
Here is a newsgroup posting with c source code for getting the serial number, not sure if a non-root user can use it?

From: Gary Desrosiers (
Subject: Re: c code that can retrieve "Drive Serial Number" from the Harddisk firmware.
View this article only
Newsgroups: comp.os.linux.development.apps, comp.os.linux.development.system, it.comp.os.linux.development
Date: 2003-06-28 05:48:46 PST

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
#include <fcntl.h>
#include <errno.h>

int main(int argc, char *argv[])
struct hd_driveid id;
int fd = open("/dev/hda", O_RDONLY|O_NONBLOCK);
if (fd < 0)
if(!ioctl(fd, HDIO_GET_IDENTITY, &id))
    printf("Serial Number=%s\n",id.serial_no);
     //printf("Model Number=%s\n",id.model);
     //printf("Firmware Revision=%.8s\n",id.fw_rev);
} return EXIT_SUCCESS;

From what I found, you cannot get the serial number from /proc unless you want to decode /proc/ide/ide0/hda.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial