1

[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 <no output> 

/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.

5
  • I don't think there are other "candidate" block devices in /devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0/block/ nor in /devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0/scsi_generic/. Can you check that there's really more than one device in there that you could mistake for the right one? Commented Nov 19, 2024 at 22:37
  • The issue with using /devices/pci0000:00/0000:00:17.0/ata4/host3/target3:0:0/3:0:0:0/scsi_generic/sg3 is more that it would change to sg2 and then wherever I have the call for sg3 would not work. As a pro, you are right it does avoid another device being accessed as /dev/sg3 inadvertently, but it doesn't provide the reliability /dev/disk/by-uuid/035bbeef20202020 does - which is what I'm hoping for. Commented Nov 20, 2024 at 1:31
  • I don't see the problem, to be quite honest – if there's only one option in that directory, you cannot go wrong. Just open the device that is in the directory. Where's the problem? Commented Nov 20, 2024 at 9:29
  • In the case of DVD drives, the "UUID" 035bbeef20202020 is not associated with the drive, but with the currently inserted disc. A DVD drive with no disc inserted has no UUID at all. Commented Nov 20, 2024 at 11:34
  • I did not test the UUID without a disc in or with another disc in so did not notice the UUID is per-disc! Almost got bamboozled big with that - thanks for the catch Commented Nov 22, 2024 at 2:29

1 Answer 1

1

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.

The "UUID" you are hoping to use is associated with the disc currently in the drive, not with the drive itself.

To really solve that problem, you'll need a pair of udev rules.

First, run udevadm info -q all -a -n /dev/sr0 | grep -e vendor -e model and make a note of the ATTRS{vendor} and ATTRS{model} strings.

Do the same with udevadm info -q all -a -n /dev/sg3 | grep -e vendor -e model.

You might see something like this in both cases:

ATTRS{model}=="BD-RE WH16NS60 " ATTRS{vendor}=="HL-DT-ST" ATTRS{subsystem_vendor}=="0x1234" ATTRS{vendor}=="0x8086" 

You should ignore any lines with ATTRS{subsystem_vendor} and the lines where ATTRS{vendor} contains only hexadecimal numbers, as they'll won't refer to the DVD drive, but the upstream controller(s) on the PCI(e) bus.

A serial number would be a better unique identifier, but unfortunately the udev attributes for the generic SCSI device will not include a readily-accessible serial number attribute.

Note that the strings may include trailing whitespace, so be sure to copy the entire strings within the double quotes exactly. For SCSI-like devices, the maximum(/standard?) length of the vendor string seems to be 8 characters, and the model string seems to be 16 characters respectively.

Once you know the vendor and model strings, you will be able to construct a pair of udev rules like this:

SUBSYSTEM=="scsi_generic", ATTRS{vendor}=="HL-DT-ST", ATTRS{model}=="BD-RE WH16NS60 ", SYMLINK+="consistent_generic" SUBSYSTEM=="block", DRIVERS=="sr", ATTRS{vendor}=="HL-DT-ST", ATTRS{model}=="BD-RE WH16NS60 ", SYMLINK+="consistent_block" 

(You can replace consistent_generic and consistent_block with any names you want.)

Place them into e.g. /etc/udev/rules.d/80-local-consistent-dvd.rules, then reboot.

Now you will have symbolic links /dev/consistent_block and /dev/consistent_generic (or however you named them), which will always point to the DVD drive that has the specified attributes.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.