Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

Small Computer System Interface (SCSI) is a standard that allows a computer to communicate with physical devices like hard disk drives.

Often, we have multiple drives connected to a single SCSI bus. To differentiate these devices, the Linux kernel assigns SCSI Identifications (IDs) to each.

In this tutorial, we’ll learn how to find SCSI device IDs using Linux commands.

First, we’ll see how the kernel defines SCSI devices. Then, we’ll look at how to find the device IDs in the /sys directory. Finally, we’ll learn the command to get a list with all SCSI device IDs.

2. How SCSI Devices Are Named

Once we plug a SCSI device into the PC, the kernel provides an ID to be able to recognize it later.

The SCSI ID consists of four numbers separated by columns. For example, this is an SCSI ID:

2:0:0:0

Here, the first element is the host number, the second element is the controller number, the third one is the target number, and the final element is the logical unit number.

Now, let’s learn the commands to get the SCSI IDs.

3. Find SCSI Devices in /sys

We can list all SCSI device IDs in the /sys/bus/scsi/devices directory using the ls command:

$ ls /sys/bus/scsi/devices
0:0:0:0 2:0:0:0

As can be seen, there are two SCSI devices with the IDs 0:0:0:0 and 2:0:0:0.

4. Using lsscsi Command

Another way of getting the device IDs is by using the lsscsi command.

We may need to install it using the apt command if it’s not already present in our system:

$ sudo apt install lsscsi

Once installed, we can get the list of connected SCSI devices. For that, we use the –scsi_id option:

$ lsscsi --scsi_id
[0:0:0:0]    disk    ATA      KINGSTON SM2280S 01.W  /dev/sda   -
[2:0:0:0]    disk    ATA      TOSHIBA DT01ACA1 A750  /dev/sdb   -

Let’s look at the output in more detail:

  • The first column represents the SCSI device ID sequence
  • The disk is the device type
  • ATA is the controller type
  • Then, the disk name is shown
  • The final column shows the connected partition

As we can see, the output shows information about two connected SCSI devices with their device IDs.

5. Conclusion

In this article, we learned how to find SCSI device IDs.

First, we looked at how the SCSI ID is defined. Then, we use the /sys directory to find the device IDs. Finally, we learned the lsscspi command to get the list of SCSI devices.