How to get the Serial Number of a disk by corresponding file in linux?
I know that for a disk in linux, we can use commands such as hdparm
or smartctl
to get its basic information.
But for the implementation of these commands, I think all of them are implemented by reading the corresponding file of a disk in linux. For example, to get the size of a device /dev/sda, we can use cat /sys/block/sda/size
instead of using command such hdparm
or smartctl
. So the question is how to get the serial number of a disk by reading its corresponding file directly.
linux command io disk
add a comment |
I know that for a disk in linux, we can use commands such as hdparm
or smartctl
to get its basic information.
But for the implementation of these commands, I think all of them are implemented by reading the corresponding file of a disk in linux. For example, to get the size of a device /dev/sda, we can use cat /sys/block/sda/size
instead of using command such hdparm
or smartctl
. So the question is how to get the serial number of a disk by reading its corresponding file directly.
linux command io disk
1
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would beb8:0
, the secondb8:16
, the thirdb8:32
etc)
– don_crissti
Nov 30 '15 at 3:06
add a comment |
I know that for a disk in linux, we can use commands such as hdparm
or smartctl
to get its basic information.
But for the implementation of these commands, I think all of them are implemented by reading the corresponding file of a disk in linux. For example, to get the size of a device /dev/sda, we can use cat /sys/block/sda/size
instead of using command such hdparm
or smartctl
. So the question is how to get the serial number of a disk by reading its corresponding file directly.
linux command io disk
I know that for a disk in linux, we can use commands such as hdparm
or smartctl
to get its basic information.
But for the implementation of these commands, I think all of them are implemented by reading the corresponding file of a disk in linux. For example, to get the size of a device /dev/sda, we can use cat /sys/block/sda/size
instead of using command such hdparm
or smartctl
. So the question is how to get the serial number of a disk by reading its corresponding file directly.
linux command io disk
linux command io disk
asked Nov 30 '15 at 2:41
Jin CaiJin Cai
62
62
1
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would beb8:0
, the secondb8:16
, the thirdb8:32
etc)
– don_crissti
Nov 30 '15 at 3:06
add a comment |
1
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would beb8:0
, the secondb8:16
, the thirdb8:32
etc)
– don_crissti
Nov 30 '15 at 3:06
1
1
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would be b8:0
, the second b8:16
, the third b8:32
etc)– don_crissti
Nov 30 '15 at 3:06
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would be b8:0
, the second b8:16
, the third b8:32
etc)– don_crissti
Nov 30 '15 at 3:06
add a comment |
3 Answers
3
active
oldest
votes
You could also use /proc/partitions
to find that info.
That file gives you the size in number of blocks that all your partitions have, But also gives you the same information for your entire disks.
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
add a comment |
You could use strace to find how smartctl get the serial number of a disk. CMD line likes this: strace smartctl -a /dev/sda. Maybe it just get the serial by ioctl.
add a comment |
I just have a try. It do get the serial by ioctl. This is some output of strace:
open("/dev/sda", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["52[ATA WDC WD5000LPVX-0"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f246307%2fhow-to-get-the-serial-number-of-a-disk-by-corresponding-file-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could also use /proc/partitions
to find that info.
That file gives you the size in number of blocks that all your partitions have, But also gives you the same information for your entire disks.
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
add a comment |
You could also use /proc/partitions
to find that info.
That file gives you the size in number of blocks that all your partitions have, But also gives you the same information for your entire disks.
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
add a comment |
You could also use /proc/partitions
to find that info.
That file gives you the size in number of blocks that all your partitions have, But also gives you the same information for your entire disks.
You could also use /proc/partitions
to find that info.
That file gives you the size in number of blocks that all your partitions have, But also gives you the same information for your entire disks.
edited Nov 30 '15 at 5:37
Tejas
1,83621940
1,83621940
answered Nov 30 '15 at 4:56
VictorVictor
112
112
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
add a comment |
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
I don't need information of number of blocks but the serial number.
– Jin Cai
Nov 30 '15 at 5:57
add a comment |
You could use strace to find how smartctl get the serial number of a disk. CMD line likes this: strace smartctl -a /dev/sda. Maybe it just get the serial by ioctl.
add a comment |
You could use strace to find how smartctl get the serial number of a disk. CMD line likes this: strace smartctl -a /dev/sda. Maybe it just get the serial by ioctl.
add a comment |
You could use strace to find how smartctl get the serial number of a disk. CMD line likes this: strace smartctl -a /dev/sda. Maybe it just get the serial by ioctl.
You could use strace to find how smartctl get the serial number of a disk. CMD line likes this: strace smartctl -a /dev/sda. Maybe it just get the serial by ioctl.
answered Nov 30 '15 at 8:28
Zhengyuan LiuZhengyuan Liu
315
315
add a comment |
add a comment |
I just have a try. It do get the serial by ioctl. This is some output of strace:
open("/dev/sda", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["52[ATA WDC WD5000LPVX-0"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
add a comment |
I just have a try. It do get the serial by ioctl. This is some output of strace:
open("/dev/sda", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["52[ATA WDC WD5000LPVX-0"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
add a comment |
I just have a try. It do get the serial by ioctl. This is some output of strace:
open("/dev/sda", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["52[ATA WDC WD5000LPVX-0"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
I just have a try. It do get the serial by ioctl. This is some output of strace:
open("/dev/sda", O_RDONLY|O_NONBLOCK) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[6]=[12, 00, 00, 00, 24, 00], mx_sb_len=32, iovec_count=0, dxfer_len=36, timeout=20000, flags=0, data[36]=["52[ATA WDC WD5000LPVX-0"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[16]=[85, 08, 0e, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, ec, 00], mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=20000, flags=0, data[512]=["zB377?731020? W -DXW11"...], status=00, masked_status=00, sb[0]=, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
edited Nov 30 '15 at 8:35
Archemar
20.2k93773
20.2k93773
answered Nov 30 '15 at 8:33
Zhengyuan LiuZhengyuan Liu
315
315
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f246307%2fhow-to-get-the-serial-number-of-a-disk-by-corresponding-file-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
grep SERIAL_SHORT /run/udev/data/b8*
(your first drive would beb8:0
, the secondb8:16
, the thirdb8:32
etc)– don_crissti
Nov 30 '15 at 3:06