Configuring devlabel



Adding device Labels

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/sdb5  partition, use the following command:

[root@localhost student]# ls /dev/sd* -l
brw-rw---- 1 root disk 8,  0 Mar  7 00:35 /dev/sda
brw-rw---- 1 root disk 8, 16 Mar  6 23:12 /dev/sdb
brw-rw---- 1 root disk 8, 17 Mar  6 23:12 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Mar  6 23:12 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Mar  7 00:35 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Mar  6 23:12 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Mar  6 23:12 /dev/sdb5
brw-rw---- 1 root disk 8, 32 Mar  6 23:12 /dev/sdc
brw-rw---- 1 root disk 8, 48 Mar  6 23:12 /dev/sdd

[root@localhost student]# devlabel add -d /dev/sdb5 -s /dev/work
SYMLINK: /dev/work -> /dev/sdb5
Added /dev/work to /etc/sysconfig/devlabel
[root@localhost student]#

Partition /dev/sdb5 in the example's server configuration is mapped to the /home folder.

At this point we can create a folder on the file system and map it to our new user defined device (/dev/work).

see below:

We create a new user defined device label for /dev/sdb5 = content of the /home directory

[root@localhost student]# devlabel add -d /dev/sdb5 -s /dev/userfiles
SYMLINK: /dev/userfiles -> /dev/sdb5
Added /dev/userfiles to /etc/sysconfig/devlabel

Creating a user defined name  for the device in the format /dev/dev_name  is not mandatory. However is recommended to follow this format in order to have all the device mappings listed within /dev.



Then we create e new folder userfiles under filesystem  root /

[root@localhost student]# mkdir /userfiles

at this point the directory is empty

[root@localhost student]# ls /userfiles/
<empty>

We mount the  device /dev/userfiles  to the directory /userfiles

[root@localhost student]# mount /dev/userfiles /userfiles/

We can verify the created symlink at /dev folder

[root@localhost student]# ls /dev/use*  -l
lrwxrwxrwx 1 root root 9 Mar  7 01:13 /dev/userfiles -> /dev/sdb5
[root@localhost student]#


If we list now the content of the directory we can verify that it has the same content as /home

[root@localhost student]# ls /userfiles/
lost+found  student  user1  user10  user2  user20  user3  user4


We unmount the /dev/userfiles device

[root@localhost student]# umount /dev/userfiles


we verify that the content of the /usefiles folder is empty

[root@localhost student]# ls /userfiles/
[root@localhost student]#


devlabel config file

/etc/sysconfig/devlabel

Symlinks that map the device UUID to device labels created with devlabels are stored in /etc/sysconfig/devlabel

Example /etc/sysconfig/devlabel file

[root@localhost student]# cat /etc/sysconfig/devlabel
# devlabel configuration file
#
# This file should generally not be edited by hand.
# Instead, use the /sbin/devlabel program to make changes.
# devlabel by Gary Lerhaupt <gary_lerhaupt@dell.com>
#
# format:  <SYMLINK> <DEVICE> <UUID>
# or format:  <RAWDEVICE> <DEVICE> <UUID>

/dev/work /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba
/projects /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba
/dev/projects /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba
/dev/userfiles /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba
[root@localhost student]#


Removing device labels

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

devlabel remove -s <symlink>


Example
[root@localhost student]# devlabel remove -s /dev/userfiles
Deleted symlink /dev/userfiles
Removed symlink /dev/userfiles from /etc/sysconfig/devlabel
[root@localhost student]#


Status of devlabel symlinks


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

devlabel status

Example

[root@localhost student]# devlabel status
brw-rw----    root    disk    /dev/work -> /dev/sdb5
brw-rw----    root    disk    /projects -> /dev/sdb5
brw-rw----    root    disk    /dev/projects -> /dev/sdb5
[root@localhost student]#



Reloading devlabel-s

If the disk configuration changes , for example e disk is removed symlinks in the /etc/sysconfig/devlabel  should change.

Consider the disk configuration below:

[root@localhost student]# ls /dev/sd* -l
brw-rw---- 1 root disk 8,  0 Mar  7 00:35 /dev/sda
brw-rw---- 1 root disk 8, 16 Mar  6 23:12 /dev/sdb
brw-rw---- 1 root disk 8, 17 Mar  6 23:12 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Mar  6 23:12 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Mar  7 00:35 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Mar  6 23:12 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Mar  6 23:12 /dev/sdb5
brw-rw---- 1 root disk 8, 32 Mar  6 23:12 /dev/sdc
brw-rw---- 1 root disk 8, 48 Mar  6 23:12 /dev/sdd



There is a disk at /dev/sda  which will be removed. The configuration after removal ( and reboot ) will be as follows:

[root@localhost student]# ls /dev/sd* -l
brw-rw---- 1 root disk 8,  0 Mar  7 01:55 /dev/sda
brw-rw---- 1 root disk 8,  1 Mar  7 01:48 /dev/sda1
brw-rw---- 1 root disk 8,  2 Mar  7 01:48 /dev/sda2
brw-rw---- 1 root disk 8,  3 Mar  7 01:55 /dev/sda3
brw-rw---- 1 root disk 8,  4 Mar  7 01:48 /dev/sda4
brw-rw---- 1 root disk 8,  5 Mar  7 01:48 /dev/sda5
brw-rw---- 1 root disk 8, 16 Mar  7 01:48 /dev/sdb
brw-rw---- 1 root disk 8, 32 Mar  7 01:48 /dev/sdc

[root@localhost student]# 

The disk /dev/sda is removed and disk /dev/sdb is renamed to /dev/sda.

The symlinks stored at /etc/sysconfig/devlabel cstill point to /dev/sdb while the name of the partition has changed to sda:

[root@localhost student]# cat /etc/sysconfig/devlabel

/dev/work /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba 
/projects /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba 
/dev/projects /dev/sdb5 P:bc67a097-6666-43c7-a082-5c3d9d7cc2ba 

if we verify the status of the symlinks:

[root@localhost student]# devlabel status
/dev/work->/dev/sdb5 ignored. Cannot confirm UUID. No link will exist!
/projects->/dev/sdb5 ignored. Cannot confirm UUID. No link will exist!
/dev/projects->/dev/sdb5 ignored. Cannot confirm UUID. No link will exist!
[root@localhost student]#

we can understand that the link is not functional. All software that rely on these symlinks to  refer to disk partitions will not work at this point.

By reloading the devlabel configuration the content of the /etc/sysconfig/devlabel will be updated and the links will become functional again.

[root@localhost student]# devlabel reload

Device name inconsistency detected for symlink /dev/work!
The device /dev/sdb5 is now /dev/sda5.
The symlink /dev/work will now point to the new device name.
SYMLINK: /dev/work -> /dev/sda5

Device name inconsistency detected for symlink /projects!
The device /dev/sdb5 is now /dev/sda5.
The symlink /projects will now point to the new device name.
SYMLINK: /projects -> /dev/sda5

Device name inconsistency detected for symlink /dev/projects!
The device /dev/sdb5 is now /dev/sda5.
The symlink /dev/projects will now point to the new device name.
SYMLINK: /dev/projects -> /dev/sda5
[root@localhost student]#


Verifying now the status of the symlinks will result in correct links:

[root@localhost student]# devlabel status
brw-rw---- root disk /dev/work -> /dev/sda5
brw-rw---- root disk /projects -> /dev/sda5
brw-rw---- root disk /dev/projects -> /dev/sda5
[root@localhost student]# 


devlabel reload on System Boot

Scheduling a devlabel reload on system boot in order to make sure that when system is booted user defined device labels are sinchronized with the disks


We first make a /etc/init.d/dvl text file with the devlabel reload  command on it

[root@localhost student]# cat > /etc/init.d/dvl
devlabel reload
[root@localhost student]# cat  /etc/init.d/dvl
devlabel reload

This file is just a text file up to now. Herewith we need to give execute rights. 

Note
In this example we will give execute rights to everyone, however in real time scenarios you should limit this to root.

[root@localhost student]# ls   /etc/init.d/dvl -l
-rw-r--r-- 1 root root 16 Mar  7 02:31 /etc/init.d/dvl

[root@localhost student]# chmod a+x  /etc/init.d/dvl

[root@localhost student]# ls   /etc/init.d/dvl -l
-rwxr-xr-x 1 root root 16 Mar  7 02:31 /etc/init.d/dvl
[root@localhost student]# 


Now the file is an executable script that reloads the devlabel configuration.

In order to execute this script we swill add an entry to the /etc/rc.local file

[root@localhost student]# cat /etc/rc.local 

touch /var/lock/subsys/local
/etc/init.d/dvl
[root@localhost student]# 



Note
Remember that rc.local scripts run after all other initiation scripts. Herewith you might like to use rcx.d where x is the execution level to make sure the disk labels are synchronized before the services that use those are started.