HDIO_GET_IDENTITY Fails On USB Hard Disks With Errno 22
Introduction
When attempting to use the sedutil-passhasher
tool with a USB caddy for an NVMe drive, users may encounter an error message indicating that the HDIO_GET_IDENTITY
ioctl fails with an "Invalid argument" error (Errno 22). This issue arises because the HDIO_GET_IDENTITY
ioctl requires the disk to be connected via IDE/ATA. In this article, we will explore alternative methods for retrieving the serial number of the disk, which is necessary for calculating the unlock hash from the raw password.
Understanding the Issue
The HDIO_GET_IDENTITY
ioctl is a Linux kernel interface that provides information about a disk's identity, including its serial number. However, this ioctl is specific to IDE/ATA disks and does not work with USB-connected disks, such as those connected via a USB caddy. This limitation is due to the way USB disks are handled by the Linux kernel, which does not provide the necessary information for the HDIO_GET_IDENTITY
ioctl to function correctly.
Alternative Methods for Serial Number Retrieval
Fortunately, there are alternative methods for retrieving the serial number of a disk, even if it is connected via USB. Here are a few options:
1. Using the lsblk
Command
One way to retrieve the serial number of a disk is by using the lsblk
command. This command provides a list of block devices on the system, including their serial numbers. To use lsblk
to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
lsblk
command with the-d
option to specify the disk device (e.g.,/dev/sda
). - Look for the
SERIAL
column in the output, which will display the serial number of the disk.
Example output:
lsblk -d /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
sda1 8:1 0 1.8T 0 part
SERIAL: 1234567890abcdef
2. Using the udevadm
Command
Another way to retrieve the serial number of a disk is by using the udevadm
command. This command provides information about device events and can be used to retrieve the serial number of a disk. To use udevadm
to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
udevadm
command with theinfo
option to specify the disk device (e.g.,/dev/sda
). - Look for the
ID_SERIAL
attribute in the output, which will display the serial number of the disk.
Example output:
udevadm info -a -p /dev/sda
P: /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0/block/sda
N: sda
S: disk
E: ID_BUS=usb
E: ID_MODEL=USB_SCSI_DISK
E: ID_REVISION=1.0
E: ID_SERIAL=1234567890abcdef
3. Using the blkid
Command
A third way to retrieve the serial number of a disk is by using the blkid
command. This command provides information about block devices on the system, including their serial numbers. To use blkid
to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
blkid
command with the-o
option to specify the disk device (e.g.,/dev/sda
). - Look for the
SERIAL
attribute in the output, which will display the serial number of the disk.
Example output:
blkid -o value -s SERIAL /dev/sda
1234567890abcdef
Conclusion
Q: What is the HDIO_GET_IDENTITY ioctl and why does it fail on USB hard disks?
A: The HDIO_GET_IDENTITY
ioctl is a Linux kernel interface that provides information about a disk's identity, including its serial number. However, this ioctl is specific to IDE/ATA disks and does not work with USB-connected disks, such as those connected via a USB caddy. This limitation is due to the way USB disks are handled by the Linux kernel, which does not provide the necessary information for the HDIO_GET_IDENTITY
ioctl to function correctly.
Q: What are the alternative methods for retrieving the serial number of a disk?
A: There are several alternative methods for retrieving the serial number of a disk, including:
- Using the
lsblk
command to list block devices on the system and retrieve the serial number of the disk. - Using the
udevadm
command to retrieve information about device events and retrieve the serial number of the disk. - Using the
blkid
command to retrieve information about block devices on the system and retrieve the serial number of the disk.
Q: How do I use the lsblk command to retrieve the serial number of a disk?
A: To use the lsblk
command to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
lsblk
command with the-d
option to specify the disk device (e.g.,/dev/sda
). - Look for the
SERIAL
column in the output, which will display the serial number of the disk.
Example output:
lsblk -d /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
sda1 8:1 0 1.8T 0 part
SERIAL: 1234567890abcdef
Q: How do I use the udevadm command to retrieve the serial number of a disk?
A: To use the udevadm
command to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
udevadm
command with theinfo
option to specify the disk device (e.g.,/dev/sda
). - Look for the
ID_SERIAL
attribute in the output, which will display the serial number of the disk.
Example output:
udevadm info -a -p /dev/sda
P: /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0/block/sda
N: sda
S: disk
E: ID_BUS=usb
E: ID_MODEL=USB_SCSI_DISK
E: ID_REVISION=1.0
E: ID_SERIAL=1234567890abcdef
Q: How do I use the blkid command to retrieve the serial number of a disk?
A: To use the blkid
command to retrieve the serial number of a disk, follow these steps:
- Connect the USB caddy to the system.
- Run the
blkid
command with the-o
option to specify the disk device (e.g.,/dev/sda
). - Look for the
SERIAL
attribute in the output, which will display the serial number of the disk.
Example output:
blkid -o value -s SERIAL /dev/sda
1234567890abcdef
Q: What is the raw password and how is it used to calculate the unlock hash?
A: The raw password is a string of characters that is used to calculate the unlock hash. The unlock hash is a cryptographic hash of the raw password, which is used to unlock the disk. The raw password is typically provided by the disk manufacturer or obtained from the disk's documentation.
Q: How do I calculate the unlock hash from the raw password?
A: To calculate the unlock hash from the raw password, you will need to use a cryptographic hash function, such as SHA-256 or AES. The specific hash function used will depend on the requirements of the disk and the system on which it is being used.
Q: What are some common issues that may occur when trying to unlock a disk?
A: Some common issues that may occur when trying to unlock a disk include:
- The raw password is incorrect or incomplete.
- The unlock hash is not calculated correctly.
- The disk is not properly connected or configured.
- The system is not properly configured to support the disk.
Q: How do I troubleshoot issues with unlocking a disk?
A: To troubleshoot issues with unlocking a disk, follow these steps:
- Verify that the raw password is correct and complete.
- Verify that the unlock hash is calculated correctly.
- Verify that the disk is properly connected and configured.
- Verify that the system is properly configured to support the disk.
- Consult the disk's documentation or manufacturer's support resources for further assistance.