Chapter 7. User-Defined Device Names

The /dev/ directory contains virtual files that represent devices. Each virtual file represents a device for the system such as a storage device, USB device, or printer. These virtual files are called device names.

Device names for IDE devices begin with hd, and device names for SCSI devices begin with sd. The prefix is followed by a letter, starting with a, that represents the drive order. For example, /dev/hda is the first IDE hard drive, /dev/hdb is the second IDE hard drive, /dev/hdc is the third IDE drive, and so on.

If the device name is followed by a number, the number represents the partition number. For example, /dev/hda1 represents the first partition on the first IDE drive.

If a hard drive is physically moved to a different location in the machine, is removed, or fails to initialize, some of the device names will change, potentially leaving device name references invalid. For example, as shown in Figure 7-1, if a system has three SCSI hard drives, and the second SCSI hard drive is removed, /dev/sdc becomes /dev/sdb, causing any references to /dev/sdc to become invalid and any references to /dev/sdb invalid as well since it is a different drive.

Figure 7-1. Removing a Hard Drive

Every hard drive has a unique identifier associated with it, called a UUID. To solve the problem of changing device names, devlabel allows for user-defined device names that are associated with these UUIDs. A symbolic link is created from the user-defined device name to the actual device name. If the actual device name changes, the symbolic link is updated to point to the same drive according to its UUID. Thus, both IDE and SCSI storage devices can be referenced by their user-defined names.

Devlabel also allows for automatically mounting hotplug devices such as removable hard drives and USB devices such as memory cards for digital cameras. If configured to mount automatically, after the device is plugged in, it is mounted with the user-defined device name.

7.1. Configuring Devlabel

User-defined device names can be added based on the device name, partition name, or the UUID of the drive.

Use the following syntax to add a user-defined device name for a storage device. The device specified can be the entire device or a single partition on a device.

devlabel add -d <device> -s <symlink>

For example, to add the symbolic link /dev/work to represent the /dev/hdb1 partition, use the following command:

devlabel add -d /dev/hdb1 -s /dev/work

If the command was successful, the following is displayed:

Created symlink /dev/work -> /dev/hdb1
Added /dev/work to /etc/sysconfig/devlabel

To add a device name for a device based on a UUID, use the following syntax:

devlabel add -u <uuid> -s <symlink>

To use devlabel to retrieve the UUID for a device (or to make sure it has one), use the following command:

devlabel printid -d <device>

The symbolic link names must be unique. If an existing link already exists when an attempt is made to add it, the configuration file is not modified, and the following is displayed:

The file /dev/work already exists.
Failure. Could not create a symlink.

To remove a symbolic link from the devlabel list, use the following command:

devlabel remove -s <symlink>

The entry is removed from the configuration file, and the symbolic link is deleted.

To determine the status of the devlabel symbolic links, use the following command:

devlabel status

It returns output similar to the following:

lrwxrwxrwx    1 root            9 Apr 29 13:20 /dev/work -> /dev/hdb1
lrwxrwxrwx    1 root            9 Apr 29 13:41 /dev/tcf -> /dev/hda1

7.1.1. Hotplug Devices

A program called hotplug performs actions when a system event, such as hardware being added or removed, takes place while the system is running. For example, if a USB hard drive or a USB media card reader is attached to the system, hotplug notifies users by logging a message in the system log file (/var/log/messages) and loads the proper kernel modules so the device works.

When a PCI, USB, or IEEE 1394 (also known as FireWire) device is plugged in, the hotplug scripts also restart devlabel so that the removable storage media receives a user-defined device name (such as /dev/usbcard), and optionally it can automatically mount the storage device.

After inserting the USB card reader into the USB port of the computer, issue the following command as root (where /dev/sda1 is the device name for the media card and /dev/usbcard is the user-defined device name to use):

devlabel add -d /dev/sda1 -s /dev/usbcard --automount

This commands adds an entry for the mount point to /etc/sysconfig/devlabel and creates a symbolic link from /dev/usbcard to /dev/sda1. The --automount option to devlabel specifies that the device should be automatically mounted when devlabel restarts if an entry for it is located in /etc/fstab and if the device exists (a device with the same UUID is found).

The updfstab is a program that scans the IDE and SCSI buses for new devices and adds entries to /etc/fstab for them if entries do not already exist. It also adds entries for USB devices since they appear as SCSI devices. Refer to the updfstab man page for more information.

When a USB device is inserted, hotplug runs the updfstab program, which adds an entry to /etc/fstab for the storage device (such as the media card) if it exists. (If a card reader without a card in it is inserted, an entry is not added.) The line added contains the actual device name (such as /dev/sda1) and the kudzu option. The kudzu option tells Kudzu [1] that it can remove the line if the device does not exist. Since the line is required by devlabel, the kudzu option must be removed so the line remains in the file. Also change the device name to the devlabel device name (such as /dev/usbcard) and create the mount point (such as /mnt/usbcard).

After modifying the line, it should look similar to the following:

/dev/usbcard   /mnt/usbcard   auto    noauto,owner 0 0

Because of --automount, when devlabel is restarted, the storage media in the USB card reader device is mounted in /mnt/usbcard when the USB device is plugged into the computer. The trick is that when the USB card reader is plugged into the computer, the card must already be in the reader. If not, devlabel can not find the storage device, and thus it can not automatically mount it.

If the USB card reader is already plugged in without a card, when the card is inserted, run the command devlabel restart as root to mount the media card.

Notes

[1]

Kudzu is a hardware probing tool run at system boot time to determine what hardware has been added or removed from the system.