How to remove an udev rule for an `sd` device ?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 5
    • udev

Issue

  • How to remove udev rules ?
  • Configured some udev rules for sd devices. How to remove them?
  • How to remove an udev rule for an sd device ?

Resolution

  • In order to change the udev rule for a device, ensure that the changes would not affect working of the system OR an application.
  • There are some device parameters which could be changed online without disconnecting the device from applications using it. In this case, udev rule could be changed online.

  • Simply remove the udev rule and reload udev, ie: run udevtrigger.

brw-r----- 1 root disk 8, 32 May  2 14:07 /dev/sde   <--- sde device created from below udev rule
brw-r----- 1 root disk 8, 32 May  2 14:20 /dev/sdc   <--- sdc device appeared after udevtrigger

# cat /etc/udev/rules.d/99-my.rules   <--- udev rule to create sde device
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -s %p",RESULT=="360a980005034446267346a576f35594f", NAME="sde"

When udev triggers the specified rule, it performs actions based off an 'existing' device which matches stated criteria in the rule; in this case it is simply assigning a new kernel name based off an existing device that matches the given wwid. Without the rule, the device still exists and the kernel assigns the enumerated name based off of discovery. If the expectation is that removing the udev rule will delete the device then that would be incorrect if storage is still presenting it.

If you wish to remove the device:

1. Remove the entry within the rule
2. Delete the device from the system: 
  # echo 1 > /sys/block/$DEVICE/delete
3. Have san admin unzone target

Diagnostic Steps

Detail steps to remove the udev rule.

  • Existing udev rule and the device that was created by that rule.
# ll /dev/sd*
brw-r----- 1 root disk 8,  0 May  2 14:07 /dev/sda
brw-r----- 1 root disk 8,  1 May  2 14:07 /dev/sda1
brw-r----- 1 root disk 8,  2 May  2 14:07 /dev/sda2
brw-r----- 1 root disk 8, 16 May  2 14:07 /dev/sdb
brw-r----- 1 root disk 8, 32 May  2 14:07 /dev/sde   <--- sde device created from below udev rule

# ll /sys/block/sd  <-- no sde device in /sys. Using iscsi device for testing
sda/ sdb/ sdc/ 

# cat /etc/udev/rules.d/99-my.rules   <--- udev rule to create sde device
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -s %p",RESULT=="360a980005034446267346a576f35594f", NAME="sde"
  • Move the file where udev rules are created or delete the particular rule.
#mv /etc/udev/rules.d/99-my.rules  /tmp
  • Reload udev.
# udevtrigger 

OR do 

echo change > /sys/block/sdc/uevent
  • Verify the result
# ll /dev/sd*
brw-r----- 1 root disk 8,  0 May  2 14:07 /dev/sda
brw-r----- 1 root disk 8,  1 May  2 14:07 /dev/sda1
brw-r----- 1 root disk 8,  2 May  2 14:07 /dev/sda2
brw-r----- 1 root disk 8, 16 May  2 14:07 /dev/sdb
brw-r----- 1 root disk 8, 32 May  2 14:20 /dev/sdc   <--- sdc device appeared after udevtrigger
brw-r----- 1 root disk 8, 32 May  2 14:07 /dev/sde


# ll /sys/block/sd
sda/ sdb/ sdc/ 

# pvcreate /dev/sde
  Physical volume "/dev/sde" successfully created

# pvs
  PV         VG         Fmt  Attr PSize  PFree 
  /dev/sda2  VolGroup00 lvm2 a-   67.62G     0 
  /dev/sdc              lvm2 --   50.00M 50.00M

# pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped

[root@dhcp210-195 ~]# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/sda2  VolGroup00 lvm2 a-   67.62G    0 
  • The block device will not getting deleted. We would have to delete the block device manually.
# udevtest /block/sdc 
main: looking at device '/block/sdc' from subsystem 'block'
run_program: '/lib/udev/usb_id -x'
run_program: '/lib/udev/usb_id' returned with status 1
run_program: '/lib/udev/scsi_id -g -x -s /block/sdc -d /dev/.tmp-8-32'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_VENDOR=NETAPP'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_MODEL=LUN'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_REVISION=7330'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_SERIAL=360a980005034446267346a576f35594f'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_TYPE=disk'
run_program: '/lib/udev/scsi_id' (stdout) 'ID_BUS=scsi'
run_program: '/lib/udev/scsi_id' returned with status 0
udev_rules_get_name: add symlink 'disk/by-id/scsi-360a980005034446267346a576f35594f'
run_program: '/lib/udev/path_id /block/sdc'

[root@dhcp210-195 ~]# udevtest /block/sde
main: unable to open '/block/sde'
  • Remove the unwanted device. (Device that was created by the deleted rule.)
#rm /dev/sde

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments