60-persistent-storage.txt 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Purpose of rules file:
  2. This rules file provides nonvolatile, unique names (in the form of symlinks)
  3. for various types of storage devices -- both IDE/ATA and SCSI.
  4. Description of rules:
  5. First, similar to the 60-persistent-input.rules file, we skip the entire file
  6. for uevents that this rules file should not apply to, as an optimization. The
  7. file does not apply to removal uevents or non-block devices. It does not apply
  8. to ramdisks, loopback-mount devices, floppy disks, netblock devices, or device-
  9. mapper devices. It also should not apply to removable devices (that is, non-
  10. partition devices with attributes named "removable" with the value "1", or
  11. partition devices whose parents have "removable" set to "1" -- partition
  12. kobjects don't have the "removable" attribute, only whole-disk kobjects do).
  13. For partition devices, we use the IMPORT{parent} option to pull in all the
  14. environment variables that get set for the parent device. (The parent of a
  15. partition device is the containing whole-disk device.) The IMPORT{parent}
  16. option is documented in the udev(7) manpage, but basically the value that we
  17. assign is used as a filter of environment variable names to import.
  18. Now, we start with rules to create by-ID symlinks (similar to the by-ID links
  19. created for input devices). For hd* whole-disk devices (they're IDE/ATA, since
  20. they start with hd), we run the ata_id program in --export mode. The ata_id
  21. program requires a device node to be passed, so we also use the $tempnode Udev
  22. variable -- this causes Udev to create a temporary device node somewhere and
  23. substitute its name where $tempnode appears in the program command line.
  24. The ata_id program, in --export mode, prints several ID_* values. If we're
  25. looking at a whole-disk device, and if ID_SERIAL is among those, we add a
  26. symlink containing the device's ID_MODEL and ID_SERIAL values. If we're
  27. looking at a partition device, we create an ID_MODEL- and ID_SERIAL-based
  28. symlink also, but we add -partX to the end of the link name (where X is the
  29. partition number).
  30. For SCSI devices, we first make some modifications to the environment. If the
  31. device's kobject has a parent with a non-empty "ieee1394_id" attribute, then
  32. the device is Firewire, so we set the ID_SERIAL environment variable to the
  33. value of that attribute, and we set ID_BUS to "ieee1394". Now, if ID_SERIAL is
  34. not set, we run usb_id, which (if this is a USB storage device) will print
  35. various values. If ID_SERIAL is still unset, we run scsi_id with a set of
  36. parameters designed to get an ID_SERIAL by querying the device itself. If that
  37. still fails, we try running scsi_id in a mode that prints the information even
  38. if the disk doesn't support so-called "vital product data" pages. If the
  39. uevent is for a DASD device, we run dasd_id.
  40. If one of these *_id programs gave us an ID_SERIAL, then for whole-disk devices
  41. we create a by-ID symlink using the ID_BUS and ID_SERIAL. For partition
  42. devices, we create a by-ID symlink that has the same form except we add -partX
  43. to the end (just like for IDE/ATA devices).
  44. Now we have some rules to create by-path persistent symlinks. We start by
  45. running the path_id program on the DEVPATH (%p) value. For whole-disk devices
  46. and SCSI ROM type devices, we create a symlink directly, using the environment
  47. variable ID_PATH, under the /dev/disk/by-path directory. But for SCSI tape
  48. devices, we create a by-path symlink in the /dev/tape/by-path directory (we
  49. base the symlink on the same information, though: the ID_PATH value printed by
  50. path_id). Now, for both SCSI ROM and SCSI tape devices, we skip everything
  51. that's left in the rules file (this is another optimization: neither SCSI ROM
  52. nor SCSI tape devices have UUIDs, labels, or EDD information).
  53. For partition devices, we now create a by-path symlink of the same form as the
  54. other partition device persistent symlinks (that is, with the same name as the
  55. parent device, but with -partX added). We know that ID_PATH is set whenever it
  56. applies, because we ran the path_id program on the parent device, and we did an
  57. IMPORT{parent} on ID_* earlier in the rules file.
  58. Now we create by-label and by-uuid symlinks. These use properties of various
  59. filesystems to generate a persistent name for a partition. For instance, if
  60. you use the ext2 filesystem, you can use e2label to assign a label, and mke2fs
  61. assigns a UUID when the filesystem is created. MS-DOS compatible filesystems
  62. also assign a "UUID" (actually it's just a serial number, created based on the
  63. date and time the partition was formatted, so it is not unique), which these
  64. rules will also use. But for removable partitions, we skip the rules (for the
  65. same reason as we skipped them above for removable disks).
  66. We run the vol_id program to get ID_FS_USAGE, ID_FS_UUID, and ID_FS_LABEL_SAFE
  67. values. (vol_id supports other values as well, but we do not use them here.)
  68. ID_FS_USAGE corresponds to the way the filesystem is supposed to be used; if it
  69. gets set to "filesystem", "other", or "crypto", we create a symlink. If
  70. ID_FS_UUID is set, we use it in a by-uuid symlink. If ID_FS_LABEL_SAFE is set,
  71. we use it in a by-label symlink.
  72. Finally, we create EDD-based symlinks in the by-id directory. For whole-disk
  73. devices, we run edd_id to get the EDD-generated ID string. (For partition
  74. devices, we import this string from the parent.) If edd_id yields an ID_EDD
  75. value, we use it in a symlink, for both whole disks and partitions.
  76. The last rule in the file is merely a LABEL that various other rules use to
  77. bypass the file (or the rest of the file) when needed.