• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Configure Device File owner/group with udev rules

by admin

What is udev and udev rules

Udev is the mechanism used to create and name /dev device nodes corresponding to the devices that are present in the system. Udev uses matching information provided by sysfs with rules provided by the user to dynamically add the required device nodes.

There are no static files under /dev directory for devices, devices are created/removed dynamically by udev(or udevd) which is a daemon monitoring what devices are connected/disconnected on to the kernel, and run additional appropriate scripts accordingly. Manually creating files under /dev directory or changing its file attributions does no effect, manually modifications would be ignored or could be revised automatically.

This post describes how to configure attributions of device files under /dev directory via udev. The common configuration files for udev are under /etc/udev/rules.d directory, which describes rules for creating device files. The files must have .rules extension/suffix and unique names, others would be ignored. These files are referred in lexical order, thus 60-raw.rules is referred before 70-persistent-net.rules, and the later rules overwrite the previous ones unless you specify an exemption in the later rules file.

Note: The syntax of .rules files are described in udev man page.

Changing file owner/group using udev rules

Let us see an example to change the owner/group to oracle/oinstall of device /dev/sdx using udev rules.
1. Add a file with name /etc/udev/rules.d/99-perm.rules which includes the below line. The file name can be anything with prefix of appropriate number like 99.

# vi /etc/udev/rules.d/99-perm.rules
KERNEL=="sdx", OWNER="oracle", GROUP="oinstall"

2. Test the new rule with “udevadm” command. As shown in the output below the rule is applied for the device /dev/sdx.

# udevadm test /block/sdx 2>&1 | grep "OWNER\|GROUP"
udev_rules_apply_to_event: OWNER ## /etc/udev/rules.d/99-perm.rules
udev_rules_apply_to_event: GROUP ## /etc/udev/rules.d/99-perm.rules

where ## shows UID/GID of oracle/oinstall.

3. Run udevadm to activate the new rule and check the changes:

# udevadm control –reload-rules
# udevadm trigger /block/sdx

4. Verify the permissions of the /dev/sdx device.

# ls -al /dev/sdx
brw-rw----. 1 oracle oinstall 202, 0 Feb  9 14:20 /dev/sdx
Note: It is not required to reboot the system after configuring the udev rules, But its recommended

Filed Under: ASM, CentOS/RHEL 6, CentOS/RHEL 7, Linux, oracle

Some more articles you might also be interested in …

  1. just Command Examples in Linux
  2. How to set ulimit values for a systemd service
  3. getopt Command Examples in Linux
  4. Beginners Guide to Oracle Temporary Tablespace Groups
  5. jlink: command not found
  6. kpartx: command not found
  7. lrztar Command Examples in Linux
  8. openfortivpn: command not found
  9. Oracle 12C Enhancements for Cascaded Standby Databases
  10. atool Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright