Open Source Software and Linux

Oct 31 2008   2:15AM GMT

Filesystem Labels – They are important

John Little Profile: Xjlittle

Labeling your filesystems can save you a major headache. Using that label in /etc/fstab is key to keeping your disks mounted where they belong.

Disks in Linux are assigned special device files. Anytime you replace a drive Linux is liable to change that file based on the order which it sees the new disk. Filesystem labels provide an alternative way for Linux to identify the partitions and drive and mount them where they belong.

On Red Hat systems partitions are automatically labeled if they are created during install. You can check this out by using the command

[root@centos5-lt ~]# e2label /dev/sda1
[root@centos5-lt ~]#

You can also see this in /etc/fstab:

[root@centos5-router ~]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/var /var ext3 defaults 1 2
LABEL=/home /home ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
/dev/router/backups /backups ext3 user,defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-hda6 swap swap defaults 0 0
[root@centos5-router ~]#

As system administration goes though we create partitions with labels. We then put the path to the device file in /etc/fstab and point it to the mount point. This could present a problem when replacing a disk in your machine.

To label an existing partition use the e2label command.

[root@centos5-router ~]# e2label /dev/router/backups backups
[root@centos5-router ~]# e2label /dev/router/backups
[root@centos5-router ~]#

Now we can change our entry in fstab to use the labe for our backups filesystem and check that it works with mount -a:

LABEL=/backups /backups ext3 user,defaults 1 2
[root@centos5-router ~]# mount -a
[root@centos5-router ~]#

Mount will return without any output if you have entered the label correctly.

The easiest way to label a new partition is to do it when you create the partition:

mkefs -j -L /newDisk /dev/sdaX

This will give us a journaled ext3 filesystem with a label of newDisk. If we want to mount the directory /test on this our entry into /etc/fstab would look like this:

LABEL=/newDisk /test ext3 user,defaults, 1 2

Now you know why you want to label your partitions. Save yourself a major headache and get them labeled!


 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: