summaryrefslogtreecommitdiff
path: root/rules.d
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-03-06 12:55:59 +0100
committerLennart Poettering <lennart@poettering.net>2023-03-09 16:41:26 +0100
commit5ac52d1f7b7cd11cad8b5c2e9812d7ee7560a517 (patch)
tree89743dbfe6f39de867596156730f87830a565f2e /rules.d
parent6f5ef9e4c7b240d67cdefb1232c9e85e43d31586 (diff)
downloadsystemd-5ac52d1f7b7cd11cad8b5c2e9812d7ee7560a517.tar.gz
udev: add /dev/loop/ symlinks
This adds symlinks that allow accessing loopback block devices via stable names that reference their backing block devices, make the unpredictable naming of loopback devices less of an issue. Example: 1. Create a loopback block device for a file $F losetup --find $F 2. Reference the backing block device via its inode: L="$(stat -c '/dev/loop/by-inode/%Hd:%Ld-%i' $F)" fdisk $L In the above the loop device name (which might be /dev/loop47 or any other name) is not used at all.
Diffstat (limited to 'rules.d')
-rw-r--r--rules.d/60-persistent-storage.rules.in11
1 files changed, 11 insertions, 0 deletions
diff --git a/rules.d/60-persistent-storage.rules.in b/rules.d/60-persistent-storage.rules.in
index 498b24c22d..43c2060d59 100644
--- a/rules.d/60-persistent-storage.rules.in
+++ b/rules.d/60-persistent-storage.rules.in
@@ -141,4 +141,15 @@ ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/
ENV{DISKSEQ}=="?*", ENV{DEVTYPE}!="partition", ENV{ID_IGNORE_DISKSEQ}!="1", SYMLINK+="disk/by-diskseq/$env{DISKSEQ}"
ENV{DISKSEQ}=="?*", ENV{DEVTYPE}=="partition", ENV{ID_IGNORE_DISKSEQ}!="1", SYMLINK+="disk/by-diskseq/$env{DISKSEQ}-part%n"
+# Create symlinks that allow referencing loopback devices by their backing file's inode number
+ENV{DEVTYPE}!="partition", ENV{ID_LOOP_BACKING_DEVICE}!="", ENV{ID_LOOP_BACKING_INODE}!="", SYMLINK+="loop/by-inode/$env{ID_LOOP_BACKING_DEVICE}-$env{ID_LOOP_BACKING_INODE}"
+ENV{DEVTYPE}=="partition", ENV{ID_LOOP_BACKING_DEVICE}!="", ENV{ID_LOOP_BACKING_INODE}!="", SYMLINK+="loop/by-inode/$env{ID_LOOP_BACKING_DEVICE}-$env{ID_LOOP_BACKING_INODE}-part%n"
+
+# Similar, but uses the .lo_file_name field of the loopback device (note that
+# this is basically just a free-form string passed from userspace to the kernel
+# when the device is created, it is not necessarily a file system path like the
+# "loop/backing_file" sysfs attribute, which is always an absolute path)
+ENV{DEVTYPE}!="partition", ENV{ID_LOOP_BACKING_FILENAME_ENC}!="", SYMLINK+="loop/by-ref/$env{ID_LOOP_BACKING_FILENAME_ENC}"
+ENV{DEVTYPE}=="partition", ENV{ID_LOOP_BACKING_FILENAME_ENC}!="", SYMLINK+="loop/by-ref/$env{ID_LOOP_BACKING_FILENAME_ENC}-part%n"
+
LABEL="persistent_storage_end"