Labeling a Linux partition - Volume Labels

For labeling a Linux partition you can use e2label command, tune2fs or else mke2fs command. Each will support ext2 and ext3 filesystems. e2label can be used fro displaying the filesystem label also. Each volume label can have a maximum of 16 characters. And this label will be retained to the filesystem or partition even if you reconnected the hard disk to another controller or even another computer!!!!
NOTE: You need root privilages to use these commands. In debian/ubuntu based systems you can sudo command.
Usage
The syntax of the commands are as follows:

e2label /device/name label
tune2fs -L label /device/name

For example, if you want to create a label '/storage' to the filesystem /dev/sda5 type in the command as follows:

# e2label /dev/sda5 /storage
or
# tune2fs -L /storage /dev/sda5

Both the commands can be used for labeling the partition as '/storage' and the label stays with in that partition. 

Now lets check the usage of the mke2fs command.
It is just like the tune2fs command:

# mke2fs -L /storage /dev/sda5
or 
# mke2fs /storage /dev/sda5 (NOTE: -L not mandatory.)

However the difference is that the mke2fs command will first format the file system and applies the label. That is you will lose all the data in that drive. So it is always recommended to use the e2label or tune2fs for labeling unless you are very particular about it

Application
Now that you have labeled your partition you might wonder how could you use it!!!!
Yea that's what I am going to describe to you.

As I explained earlier we are using the volume label for creating a persistent name to the filesystem. And as you can guess, it is of utmost useful while mounting the filesystem during system startup. So you can edit the /etc/fstab to use the label instead of the device name for mounting the partition. Lets take our labeled partition /dev/sda5 as example here.

Open the /etc/fstab file in your favourite editor.As I have been using the partition earlier I have edited and added the entry of /dev/sda5 file system in the fstab for auto-mounting the fs during the system startup. Also I am mounting the filesystem to /storage directory.  It looks like this:

/dev/sda5        /storage        ext3      defaults      1      2

Now that we have labeled the partition we can change the device name as follows:

LABEL=/storage     /storage      ext3      defaults     1      2

Now during the system startup the fifth partition on the first hard-disk (dev/sda5) will be mounted to the /storage folder irrespective of the partition number or drive it is on. 

Displaying the current label 

You can use the e2label for displaying the label of a file system.

# e2label /dev/sda5

This will return you:

/storage

The current label of the filesystem!!!!!

Removing label
Now if you want to remove the label just use the tune2fs command as follows:

# tune2fs -L "" /dev/sda5

This will remove the label for the partition. After removing this do not forget to edit the fstab file!!!!!
Share on Google Plus

About Mr Arora

Tips Daddy, your adviser of blogger, windows, mobile, internet, fashion, movies, games, computer, insurance, server, Linux Tips, Hacks, Tutorials, And Ideas.
    Blogger Comment
    Facebook Comment

1 comments: