In Linux, ensuring persistent device names for storage volumes is crucial, especially in environments where device names can change across reboots or when new devices are added. This persisting mapping become more crucial if you want to provision raw storage volume for Oracle ASM disks. There are two common methods to achieve this persistence either through udev rules or through multipath configuration. In this article I will explain both methods by providing detailed instructions and examples for each.
Udev Rules for Persistent Device Naming
Udev is the device manager for the Linux kernel, responsible for managing device nodes in /dev. By creating custom udev rules, you can ensure consistent device naming based on specific attributes like UUIDs, serial numbers, or other unique identifiers.
Why Use Udev Rules?
- Consistency: Persistent naming ensures that devices always appear with the same name across reboots.
- Ease of Management: Custom names or symbolic links can make it easier to identify and manage devices.
Creating a Udev Rule
To create a udev rule, you need to create a new file in the /etc/udev/rules.d/ directory. The filename typically follows the convention NN-name.rules, where NN is a number determining the rule’s priority.
Example: Binding a Device by Serial Number
- Identify the Device: First, identify the unique attribute of your device. You can use udevadm to find this information:
udevadm info –query=all –name=/dev/sda | grep ID_SERIAL
Suppose the output is:
ID_SERIAL=3600508b400105e210000900000490000
- Create the Udev Rule: Create a file /etc/udev/rules.d/96-cjdevices.rules with the following content:
KERNEL==”sd*”, SUBSYSTEM==”block”, ENV{ID_SERIAL}==”3600508b400105e210000900000490000″, SYMLINK+=”cjdisk1″
- Reload Udev Rules: After creating the rule, reload the udev rules and trigger them:
sudo udevadm control –reload-rules
sudo udevadm trigger
- Verify the Symbolic Link: Check if the symbolic link has been created:
ls -l /dev/cjdisk1
Benefits and Considerations
- Flexibility: Udev rules offer great flexibility in naming devices based on various attributes.
- Manual Effort: Requires manual creation and maintenance of rules, especially in environments with many devices.
Multipath Configuration for Persistent Device Naming
Multipath I/O is used in environments where multiple physical paths to the same storage device are present. Multipathing aggregates these paths into a single logical device, improving redundancy and performance.
Why Use Multipath Configuration?
- Redundancy: Provides failover capabilities in case one path fails.
- Performance: Can improve performance by load balancing across multiple paths.
- Consistency: Ensures consistent naming of multipath devices.
Configuring Multipath
- Install Multipath Tools: Ensure you have the necessary multipath tools installed.
Command for checking if multipath tool is available in your Linux server:
dpkg -l | grep multipath-tools # Debian/Ubuntu
rpm -qa | grep device-mapper-multipath # CentOS/RHEL
If above command does not show output then you need to install the multipath package by running below commands:
sudo apt-get install multipath-tools # Debian/Ubuntu
sudo yum install device-mapper-multipath # CentOS/RHEL
- Edit the Configuration File: Edit /etc/multipath/multipath.conf to define your multipath devices. For example:
defaults {
user_friendly_names yes
}
multipaths {
multipath {
wwid 3600508b400105e210000900000490000
alias cjdisk1
}
}
- Restart the Multipath Service: Apply the configuration by restarting the multipath service:
sudo systemctl restart multipathd
- Verify the Multipath Device: Check the status of multipath devices:
sudo multipath -ll
Benefits and Considerations
- High Availability: Essential for enterprise environments requiring high availability and performance.
- Complexity: More complex to set up and manage compared to simple udev rules, but provides significant benefits in multipath environments.
Combining Udev and Multipath
In some cases, you may need to use both udev rules and multipath configuration to achieve your desired setup. For example, you can use multipath for managing multiple paths and udev rules for creating additional symbolic links.
Example
- Configure Multipath: As shown in the previous section.
- Create Udev Rule for Multipath Device: Add a rule in /etc/udev/rules.d/96-cjdevices.rules:
KERNEL==”dm-*”, SUBSYSTEM==”block”, ENV{DM_UUID}==”mpath-3600508b400105e210000900000490000″, SYMLINK+=”cjdisk1″
- Reload Udev Rules:
sudo udevadm control –reload-rules
sudo udevadm trigger
Wrap up!
Choosing between udev rules and multipath configuration depends on your specific needs:
- Use udev rules for simple environments where you need persistent device names or symbolic links.
- Use multipath configuration for environments with multiple physical paths to storage devices, requiring high availability and performance.
By understanding and implementing these methods, you can ensure consistent and reliable device naming in your Linux environment, tailored to your specific requirements.