]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: generate system-unique storage symlinks using device path
authorRoland Hieber <rhi@pengutronix.de>
Mon, 18 Sep 2023 09:52:06 +0000 (11:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 6 Dec 2023 21:22:08 +0000 (22:22 +0100)
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 <rhi@pengutronix.de>
rules.d/60-persistent-storage.rules.in

index 67874302084d56bca7dccd2b3e013c69829a930e..96b888fdffbff2e150bdcdfac82d9ac677a7f7c5 100644 (file)
@@ -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/<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)