From 3af66c089b930b7191c1964f2ea30448fe9688de Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Mon, 18 Sep 2023 11:52:06 +0200 Subject: [PATCH] udev: generate system-unique storage symlinks using device path When the same disk image is written to multiple storage units, for example an external SD card and an internal eMMC, the symlinks in /dev/disk/by-{label,uuid,partlabel,partuuid}/ are no longer unique, and will point to the device that is probed last. Adressing partitions via labels and UUIDs is nice to work with, and depending on the use case, it might also be more robust than using the symlinks in /dev/disk/by-path/ containing the partition number. Combine the two approaches to create unique symlinks containing both the device path as well as the respective UUIDs or labels, and throw in a symlink using the devpath and the partition number for the sake of completeness. For an exemplary GPT-partitioned disk at "platform-2198000.mmc" with a partition containing an ext4 file system, this might create symlinks of the following form: /dev/disk/by-path/platform-2198000.mmc-part/by-partnum/1 /dev/disk/by-path/platform-2198000.mmc-part/by-partuuid/e5a75233-3b90-4aec-8075-b4dd7132b48d /dev/disk/by-path/platform-2198000.mmc-part/by-partlabel/rootfs /dev/disk/by-path/platform-2198000.mmc-part/by-uuid/b2c92f24-8215-4680-b931-f423aae5f1c9 /dev/disk/by-path/platform-2198000.mmc-part/by-label/rootfs Signed-off-by: Roland Hieber --- rules.d/60-persistent-storage.rules.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rules.d/60-persistent-storage.rules.in b/rules.d/60-persistent-storage.rules.in index 6787430208..96b888fdff 100644 --- a/rules.d/60-persistent-storage.rules.in +++ b/rules.d/60-persistent-storage.rules.in @@ -145,6 +145,19 @@ ENV{ID_WWN_WITH_EXTENSION}=="?*", SYMLINK+="disk/by-id/wwn-$env{ID_WWN_WITH_EXTE ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}" ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}" +# by-path//by-* links (path + partition/filesystem metadata) +ENV{ID_PATH}=="", GOTO="persistent_storage_by-path_parts_end" +ENV{DEVTYPE}!="partition", GOTO="persistent_storage_by-path_parts_end" + +SYMLINK+="disk/by-path/$env{ID_PATH}-part/by-partnum/%n" +ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part/by-partuuid/$env{ID_PART_ENTRY_UUID}" +ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part/by-partlabel/$env{ID_PART_ENTRY_NAME}" + +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part/by-uuid/$env{ID_FS_UUID_ENC}" +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part/by-label/$env{ID_FS_LABEL_ENC}" + +LABEL="persistent_storage_by-path_parts_end" + # by-diskseq link (if an app is told to open a path like this, they may parse # the diskseq number from the path, then issue BLKGETDISKSEQ to verify they really got # the right device, to access specific disks in a race-free fashion)