This should arguably be done by importing the udev git repo as a submodule, but I am too lazy to figure out how to do that right now. I suppose this could also be done by rewriting the 95udev-rules.sh module for each distribution, but that is something best left to the distro maintainers once we acheive some sort of widespread adoption. Until then, stealing rules from upstream udev seems like the most portable solution. --- rules.d/50-udev-default.rules | 120 +++++++++++++++++++++++++++++++ rules.d/60-persistent-storage.rules | 70 ++++++++++++++++++ rules.d/61-persistent-storage-edd.rules | 12 +++ rules.d/64-device-mapper.rules | 4 + rules.d/64-md-raid.rules | 33 +++++++++ rules.d/80-drivers.rules | 16 ++++ rules.d/95-udev-late.rules | 8 ++ 7 files changed, 263 insertions(+), 0 deletions(-) diff --git a/rules.d/50-udev-default.rules b/rules.d/50-udev-default.rules new file mode 100644 index 0000000..95d82d7 --- /dev/null +++ b/rules.d/50-udev-default.rules @@ -0,0 +1,120 @@ +# do not edit this file, it will be overwritten on update + +SUBSYSTEM=="block", SYMLINK+="block/%M:%m" +SUBSYSTEM!="block", SYMLINK+="char/%M:%m" + +KERNEL=="pty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660" +KERNEL=="tty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660" +KERNEL=="ptmx", GROUP="tty", MODE="0666" +KERNEL=="tty", GROUP="tty", MODE="0666" +KERNEL=="tty[0-9]*", GROUP="tty", MODE="0620" +KERNEL=="vcs|vcs[0-9]*|vcsa|vcsa[0-9]*", GROUP="tty" +KERNEL=="console", MODE="0600" + +# serial +KERNEL=="tty[A-Z]*[0-9]|pppox[0-9]*|ircomm[0-9]*|noz[0-9]*", GROUP="dialout" +KERNEL=="ppp", MODE="0600" +KERNEL=="mwave", NAME="modems/mwave", GROUP="dialout" +KERNEL=="hvc*|hvsi*", GROUP="dialout" + +# mem +KERNEL=="null|zero|full|random|urandom", MODE="0666" +KERNEL=="mem|kmem|port|nvram", GROUP="kmem", MODE="0640" + +# input +KERNEL=="mouse*|mice|event*", NAME="input/%k", MODE="0640" +KERNEL=="ts[0-9]*|uinput", NAME="input/%k", MODE="0640" +KERNEL=="js[0-9]*", NAME="input/%k", MODE="0644" + +# video4linux +SUBSYSTEM=="video4linux", GROUP="video" +KERNEL=="vttuner*", GROUP="video" +KERNEL=="vtx*|vbi*", GROUP="video" +KERNEL=="winradio*", GROUP="video" + +# graphics +KERNEL=="agpgart", MODE="0600", GROUP="video" +KERNEL=="card[0-9]*", NAME="dri/%k" +KERNEL=="pmu", GROUP="video" +KERNEL=="nvidia*|nvidiactl*", GROUP="video" +SUBSYSTEM=="graphics", GROUP="video" +SUBSYSTEM=="drm", GROUP="video" + +# DVB (video) +SUBSYSTEM=="dvb", ENV{DVB_ADAPTER_NUM}=="?*", NAME="dvb/adapter$env{DVB_ADAPTER_NUM}/$env{DVB_DEVICE_TYPE}$env{DVB_DEVICE_NUM}", GROUP="video" +SUBSYSTEM=="dvb", ENV{DVB_ADAPTER_NUM}=="", PROGRAM="/bin/sh -c 'K=%k; K=$${K#dvb}; printf dvb/adapter%%i/%%s $${K%%%%.*} $${K#*.}'", NAME="%c", GROUP="video" + +# Firewire +KERNEL=="dv1394[0-9]*", NAME="dv1394/%n", GROUP="video" +KERNEL=="video1394[0-9]*", NAME="video1394/%n", GROUP="video" + +# libusb device nodes +SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", NAME="bus/usb/$env{BUSNUM}/$env{DEVNUM}", MODE="0664" + +# printer +KERNEL=="parport[0-9]*", GROUP="lp" +SUBSYSTEM=="printer", KERNEL=="lp*", GROUP="lp" +SUBSYSTEM=="ppdev", GROUP="lp" +SUBSYSTEM=="usb", KERNEL=="lp*", NAME="usb/%k", SYMLINK+="usb%k", GROUP="lp" +KERNEL=="lp[0-9]*", GROUP="lp" +KERNEL=="irlpt[0-9]*", GROUP="lp" + +# block +SUBSYSTEM=="block", GROUP="disk" + +# floppy +KERNEL=="fd[0-9]", GROUP="floppy" +KERNEL=="fd[0-9]", ACTION=="add", ATTRS{cmos}=="?*", RUN+="create_floppy_devices -c -t $attr{cmos} -m %M -M 0640 -G floppy $root/%k" +KERNEL=="hd*", SUBSYSTEMS=="ide", ATTRS{media}=="floppy", OPTIONS+="all_partitions" + +# cdrom +SUBSYSTEM=="block", KERNEL=="sr[0-9]*", SYMLINK+="scd%n", GROUP="cdrom" +SUBSYSTEM=="block", KERNEL=="hd*", SUBSYSTEMS=="ide", ATTRS{media}=="cdrom", GROUP="cdrom" +SUBSYSTEMS=="scsi", ATTRS{type}=="4|5", GROUP="cdrom" +KERNEL=="pktcdvd[0-9]*", NAME="pktcdvd/%k", GROUP="cdrom" +KERNEL=="pktcdvd", NAME="pktcdvd/control", GROUP="cdrom" + +# tape +KERNEL=="ht[0-9]*|nht[0-9]*", GROUP="tape" +KERNEL=="pt[0-9]*|npt[0-9]*|pht[0-9]*", GROUP="tape" +SUBSYSTEMS=="scsi", ATTRS{type}=="1|8", GROUP="tape" + +# block-releated +KERNEL=="sch[0-9]*", GROUP="disk" +SUBSYSTEMS=="scsi", ATTRS{type}=="0", GROUP="disk" +KERNEL=="pg[0-9]*", GROUP="disk" +KERNEL=="qft[0-9]*|nqft[0-9]*|zqft[0-9]*|nzqft[0-9]*|rawqft[0-9]*|nrawqft[0-9]*", GROUP="disk" +KERNEL=="rawctl", NAME="raw/rawctl", GROUP="disk" +SUBSYSTEM=="raw", KERNEL=="raw[0-9]*", NAME="raw/%k", GROUP="disk" +SUBSYSTEM=="bsg", NAME="bsg/%k" +SUBSYSTEM=="aoe", NAME="etherd/%k", GROUP="disk", MODE="0220" +SUBSYSTEM=="aoe", KERNEL=="err", MODE="0440" + +# network +KERNEL=="tun", NAME="net/%k", MODE="0666" + +# CPU +KERNEL=="cpu[0-9]*", NAME="cpu/%n/cpuid" +KERNEL=="msr[0-9]*", NAME="cpu/%n/msr" +KERNEL=="microcode", NAME="cpu/microcode", MODE="0600" + +# miscellaneous +KERNEL=="fuse", MODE="0666" +SUBSYSTEM=="rtc", DRIVERS=="rtc_cmos", SYMLINK+="rtc" +KERNEL=="auer[0-9]*", NAME="usb/%k" +KERNEL=="hw_random", NAME="hwrng" +KERNEL=="mmtimer", MODE="0644" +KERNEL=="rflash[0-9]*", MODE="0400" +KERNEL=="rrom[0-9]*", MODE="0400" +KERNEL=="sxctl", NAME="specialix_sxctl"" +KERNEL=="rioctl", NAME="specialix_rioctl" +KERNEL=="iowarrior[0-9]*", NAME="usb/%k" +KERNEL=="hiddev[0-9]*", NAME="usb/%k" +KERNEL=="legousbtower[0-9]*", NAME="usb/%k" +KERNEL=="dabusb[0-9]*", NAME="usb/%k" +KERNEL=="usbdpfp[0-9]*", NAME="usb/%k" +KERNEL=="cpad[0-9]*", NAME="usb/%k" + +# do not delete static device nodes +ACTION=="remove", NAME=="?*", TEST=="/lib/udev/devices/$name", OPTIONS+="ignore_remove" +ACTION=="remove", NAME=="", TEST=="/lib/udev/devices/%k", OPTIONS+="ignore_remove" diff --git a/rules.d/60-persistent-storage.rules b/rules.d/60-persistent-storage.rules new file mode 100644 index 0000000..14bd75f --- /dev/null +++ b/rules.d/60-persistent-storage.rules @@ -0,0 +1,70 @@ +# do not edit this file, it will be overwritten on update + +# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path} +# scheme based on "Linux persistent device names", 2004, Hannes Reinecke <hare@xxxxxxx> + +# forward scsi device event to corresponding block device +ACTION=="change", SUBSYSTEM=="scsi", ENV{DEVTYPE}=="scsi_device", TEST=="block", ATTR{block/*/uevent}="change" + +ACTION!="add|change", GOTO="persistent_storage_end" +SUBSYSTEM!="block", GOTO="persistent_storage_end" + +# skip rules for inappropriate block devices +KERNEL=="ram*|fd*|nbd*|gnbd*|dm-*|md*|btibm*", GOTO="persistent_storage_end" + +# never access non-cdrom removable ide devices, the drivers are causing event loops on open() +KERNEL=="hd*[!0-9]", ATTR{removable}=="1", DRIVERS=="ide-cs|ide-floppy", GOTO="persistent_storage_end" +KERNEL=="hd*[0-9]", ATTRS{removable}=="1", GOTO="persistent_storage_end" + +# ignore partitions that span the entire disk +TEST=="whole_disk", GOTO="persistent_storage_end" + +# for partitions import parent information +ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*" + +# by-id (hardware serial number) +KERNEL=="hd*[!0-9]", IMPORT{program}="ata_id --export $tempnode" +KERNEL=="hd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}" +KERNEL=="hd*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}-part%n" + +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", IMPORT{program}="usb_id --export %p" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="scsi" +KERNEL=="cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="cciss" +KERNEL=="sd*|sr*|cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" +KERNEL=="sd*|cciss*", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n" + +# firewire +KERNEL=="sd*[!0-9]|sr*", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}" +KERNEL=="sd*[0-9]", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}-part%n" + +# libata compat (ata-* links, like old hd* devices did create) +KERNEL=="sd*[!0-9]", ENV{ID_VENDOR}=="ATA", PROGRAM="ata_id $tempnode", RESULT=="?*", ENV{ID_ATA_COMPAT}="$result", SYMLINK+="disk/by-id/ata-$env{ID_ATA_COMPAT}" +KERNEL=="sd*[0-9]", ENV{ID_ATA_COMPAT}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_ATA_COMPAT}-part%n" + +KERNEL=="mmcblk[0-9]", SUBSYSTEMS=="mmc", ATTRS{name}=="?*", ATTRS{serial}=="?*", ENV{ID_NAME}="$attr{name}", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/mmc-$env{ID_NAME}_$env{ID_SERIAL}" +KERNEL=="mmcblk[0-9]p[0-9]", ENV{ID_NAME}=="?*", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/mmc-$env{ID_NAME}_$env{ID_SERIAL}-part%n" +KERNEL=="mspblk[0-9]", SUBSYSTEMS=="memstick", ATTRS{name}=="?*", ATTRS{serial}=="?*", ENV{ID_NAME}="$attr{name}", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/memstick-$env{ID_NAME}_$env{ID_SERIAL}" +KERNEL=="mspblk[0-9]p[0-9]", ENV{ID_NAME}=="?*", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/memstick-$env{ID_NAME}_$env{ID_SERIAL}-part%n" + +# by-path (parent device path) +ENV{DEVTYPE}=="disk", IMPORT{program}="path_id %p" +ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}" +ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" + +# skip unpartitioned removable media devices from drivers which do not send "change" events +ENV{DEVTYPE}=="disk", KERNEL!="sd*|sr*", ATTR{removable}=="1", GOTO="persistent_storage_end" + +# probe filesystem metadata of optical drives which have a media inserted +KERNEL=="sr*", ENV{ID_CDROM_MEDIA_TRACK_COUNT}=="?*", IMPORT{program}="vol_id --export --skip-raid --offset=$env{ID_CDROM_MEDIA_SESSION_LAST_OFFSET} $tempnode" + +# probe filesystem metadata of disks +KERNEL!="sr*", IMPORT{program}="vol_id --export $tempnode" + +# watch for future changes +KERNEL!="sr*", OPTIONS+="watch" + +# by-label/by-uuid links (filesystem metadata) +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" +ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" + +LABEL="persistent_storage_end" diff --git a/rules.d/61-persistent-storage-edd.rules b/rules.d/61-persistent-storage-edd.rules new file mode 100644 index 0000000..bd020b7 --- /dev/null +++ b/rules.d/61-persistent-storage-edd.rules @@ -0,0 +1,12 @@ +# do not edit this file, it will be overwritten on update + +ACTION!="add|change", GOTO="persistent_storage_edd_end" +SUBSYSTEM!="block", GOTO="persistent_storage_edd_end" +KERNEL!="sd*|hd*", GOTO="persistent_storage_edd_end" + +# BIOS Enhanced Disk Device +ENV{DEVTYPE}=="disk", IMPORT{program}="edd_id --export $tempnode" +ENV{DEVTYPE}=="disk", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}" +ENV{DEVTYPE}=="partition", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}-part%n" + +LABEL="persistent_storage_edd_end" diff --git a/rules.d/64-device-mapper.rules b/rules.d/64-device-mapper.rules new file mode 100644 index 0000000..8154ef3 --- /dev/null +++ b/rules.d/64-device-mapper.rules @@ -0,0 +1,4 @@ +# do not edit this file, it will be overwritten on update + +KERNEL=="device-mapper", NAME="mapper/control" + diff --git a/rules.d/64-md-raid.rules b/rules.d/64-md-raid.rules new file mode 100644 index 0000000..abb029c --- /dev/null +++ b/rules.d/64-md-raid.rules @@ -0,0 +1,33 @@ +# do not edit this file, it will be overwritten on update + +SUBSYSTEM!="block", GOTO="md_end" +ACTION!="add|change", GOTO="md_end" + +# import data from a raid member and activate it +#ENV{ID_FS_TYPE}=="linux_raid_member", IMPORT{program}="/sbin/mdadm --examine --export $tempnode", RUN+="/sbin/mdadm --incremental $env{DEVNAME}" +# import data from a raid set +KERNEL!="md*", GOTO="md_end" + +# container devices have a metadata version of e.g. 'external:ddf' and +# never leave state 'inactive' +ATTR{md/metadata_version}=="external:[A-Za-z]*", ATTR{md/array_state}=="inactive", GOTO="md_ignore_state" +TEST!="md/array_state", GOTO="md_end" +ATTR{md/array_state}=="|clear|inactive", GOTO="md_end" +LABEL="md_ignore_state" + +IMPORT{program}="/sbin/mdadm --detail --export $tempnode" +ENV{DEVTYPE}=="disk", ENV{MD_NAME}=="?*", SYMLINK+="disk/by-id/md-name-$env{MD_NAME}", OPTIONS+="string_escape=replace" +ENV{DEVTYPE}=="disk", ENV{MD_UUID}=="?*", SYMLINK+="disk/by-id/md-uuid-$env{MD_UUID}" +ENV{DEVTYPE}=="disk", ENV{MD_DEVNAME}=="?*", SYMLINK+="md/$env{MD_DEVNAME}" +ENV{DEVTYPE}=="partition", ENV{MD_NAME}=="?*", SYMLINK+="disk/by-id/md-name-$env{MD_NAME}-part%n", OPTIONS+="string_escape=replace" +ENV{DEVTYPE}=="partition", ENV{MD_UUID}=="?*", SYMLINK+="disk/by-id/md-uuid-$env{MD_UUID}-part%n" +ENV{DEVTYPE}=="partition", ENV{MD_DEVNAME}=="*[^0-9]", SYMLINK+="md/$env{MD_DEVNAME}%n" +ENV{DEVTYPE}=="partition", ENV{MD_DEVNAME}=="*[0-9]", SYMLINK+="md/$env{MD_DEVNAME}p%n" + +IMPORT{program}="vol_id --export $tempnode" +OPTIONS+="link_priority=100" +OPTIONS+="watch" +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" +ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" + +LABEL="md_end" diff --git a/rules.d/80-drivers.rules b/rules.d/80-drivers.rules new file mode 100644 index 0000000..7e13e80 --- /dev/null +++ b/rules.d/80-drivers.rules @@ -0,0 +1,16 @@ +# do not edit this file, it will be overwritten on update + +ACTION!="add", GOTO="drivers_end" + +DRIVER!="?*", ENV{MODALIAS}=="?*", RUN{ignore_error}+="/sbin/modprobe -b $env{MODALIAS}" +SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="SD", RUN+="/sbin/modprobe -b tifm_sd" +SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="MS", RUN+="/sbin/modprobe -b tifm_ms" +SUBSYSTEM=="memstick", RUN+="/sbin/modprobe -b --all ms_block mspro_block" +SUBSYSTEM=="mmc", RUN+="/sbin/modprobe -b mmc_block" +SUBSYSTEM=="i2o", RUN+="/sbin/modprobe -b i2o_block" +SUBSYSTEM=="scsi", ATTR{type}=="8", RUN+="/sbin/modprobe -b ch" +SUBSYSTEM=="scsi", ENV{DEVTYPE}=="scsi_device", TEST!="[module/sg]", RUN+="/sbin/modprobe -b sg" +SUBSYSTEM=="module", KERNEL=="parport_pc", RUN+="/sbin/modprobe -b ppdev" + +LABEL="drivers_end" + diff --git a/rules.d/95-udev-late.rules b/rules.d/95-udev-late.rules new file mode 100644 index 0000000..7207081 --- /dev/null +++ b/rules.d/95-udev-late.rules @@ -0,0 +1,8 @@ +# do not edit this file, it will be overwritten on update + +# run a command on remove events +ACTION=="remove", ENV{REMOVE_CMD}!="", RUN+="$env{REMOVE_CMD}" + +# event to be catched by udevmonitor +RUN+="socket:@/org/kernel/udev/monitor" + -- 1.6.0.6 -- To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html