Certain devices, like multi media cards (MMC), are appropriately identified by their vendor and product attributes, while others are not. This discrepancy results in some devices being displayed as “Unnamed Drive” within the desktop environment, such as the MATE desktop using Caja. This document aims to provide a detailed method for assigning a name to such devices by implementing an udev rule.
Drive Naming Convention
Named drive with a label
On the MATE desktop, as well as on other desktop environments and the command line, the name of a drive is typically derived from the product name and the disk label.
Named drive without a label but showing size
In the absence of a disk label, the drive’s size is used instead.
Unnamed drive with a hidden label before applying fix
However, if the product name is missing, the disk label will not be displayed; instead, the system defaults to showing the device name (e.g., /dev/mmcblk0).
Named drive with a label after applying fix
Shows the renamed device after applying the fix with a changed symbol and the label.
Label Assignment
For demonstration, we use two FAT32 formatted SDHC disks. One is named, and the other is unnamed. Their partition structure is illustrated as follows:
# Output showing disk and partition details
fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 7.51 GiB, 8059355136 bytes, 15740928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x68c04c1e
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 15740927 15738880 7.5G b W95 FAT32
To set a disk label, execute:
# Read current label:
fatlabel /dev/mmcblk0p1
OLDLABEL
# Set new label:
fatlabel /dev/mmcblk0p1 NEWLABEL
Name Determination
Prior to setting a name, it’s crucial to identify the current name using tools such as udeadm.
Functional Drive
Below is an example of a properly recognized drive, clearly displaying ID_NAME:
Although altering the disk firmware is a potential solution (more feasible for Nvme disks), it’s not a viable option for most SDHC disks. Instead, we can create an udev rule to dynamically assign a name. This is feasible since the required name is present in the E (environment) section.
First, identify unique strings using udevadm:
# For the operational drive:
udevadm info --attribute-walk /dev/mmcblk0|grep -i serial
ATTRS{serial}=="0x002256e1"
# For the problematic drive:
udevadm info --attribute-walk /dev/mmcblk0|grep -i serial
ATTRS{serial}=="0x00026ff3"
Create the udev rule:
cd /etc/udev/rules.d
echo\
'SUBSYSTEM=="block", ATTRS{serial}=="0x00026ff3", ENV{ID_NAME}="SDHC08GB"' >\
99-custom-disk-name.rules
Apply the rule:
udevadm control --reload-rules
udevadm trigger /dev/mmcblk0
Catching ACTION=="add" via the udev rule would propagate ID_NAME to all children of mmcblk0 and itself, when the drive information tree is added. However, upon unmounting a partition, ID_NAME would be removed, rendering ACTION=="add" unsuitable.
To refine the udev rule, consider adding a symbolic link. Unlike a named mmc, an unnamed mmc cannot be accessed via a /dev/ link containing its name. SYMLINK+= could be used for this purpose, but it is not essential for this basic example.
Ansible Playbook
This Ansible playbook is designed to apply specific udev rules across a group of client systems. It focuses on the automation of udev rule deployment for disk naming. The above example is added.