Sample Header Ad - 728x90

Unique device path for generic SCSI device /dev/sgX

1 vote
1 answer
91 views
[This is on Debian 12] To fully access my DVD drive, I need to also know its SCSI generic path (/dev/sgX) in addition to its expected CDROM-/dev/srX path. The specific device is important, though, and I need to access the device even if the system re-shuffles the /dev/srXs and /dev/sgXs.
sudo lsscsi -g
[3:0:0:0]    cd/dvd  HL-DT-ST BD-RE  WH16NS60  1.05  /dev/sr0   /dev/sg3
sudo blkid /dev/sr0
/dev/sr0: UUID="035bbeef20202020" LABEL="WALDEINSAMKEIT" BLOCK_SIZE="2048" TYPE="udf"

sudo blkid /dev/sg3
/dev/sr0 is set with a /dev/disk/by-uuid/035bbeef20202020 but if /dev/sg3 doesn't actually have a UUID (I'm guessing it's not seen as a block device), I could go for the full controller/system path, per this Linus rant I found https://yarchive.net/comp/linux/scsi_ids.html
sudo udevadm info -q path -n /dev/sr0
/devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0/block/sr0

sudo udevadm info -q path -n /dev/sg3
/devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0/scsi_generic/sg3
This does not seem like a solution either, as the path includes sr0 or sg3 which will change order. /sys/devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0 seems to be a directory the device is referencing but I can't find anything more than the folders block/sr0 and scsi_generic/sg3 which again revert to the original problem of sr0 and sg3 changing if the system cables are reordered or something. How can I get a consistent identifier for /dev/sg3? I have searched hard, but I must be missing a command.
Asked by user2403531 (113 rep)
Nov 19, 2024, 10:27 PM
Last activity: Nov 20, 2024, 12:35 PM