Here we shall discuss about labeling a Linux partition and its advantages.
Hope you know about the iSCSI target and initiator stuffs, it is the low cost, high efficient alternative for costly storage solutions. Hope I could give you an elaborate post about iSCSI soon coz that too is one of my hot favorite topic. However here we will discuss about labeling the Linux partition labeling.
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.)
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
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
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!!!!!
Cheers,
Jayakrishnan. L
awesome, just what i needed!!!
ReplyDeleteGood to hear that you found my article interesting!!!!
ReplyDeletethanks a ton !!!!!!
ReplyDeleteDid not know the purpose of e2label and filesystem label until I read this post...
ReplyDeleteThanks
wonderful article!!! thans a ton!!!
ReplyDeletee2label show blank output.... So does it mean by volume is not mounted
ReplyDeletee2label labels the partition and hence it does not require the volume to be mounted. If e2label does not displays anything, then there wont be any label to the file system !!
DeleteCould you paste the entire command and its output ? then we can get to a conclusion !!
It shows blank after using this command but in blkid shows label name
ReplyDeleteLABEL=/storage /storage ext3 defaults 1 2
ReplyDeleteits worng should be:
LABEL=storage /storage ext3 defaults 0 0
so it will not block the system from booting if file system check is stuck and the dash after the LABEL=/ will give error message:
# echo "LABEL=/storage /mnt ext4 defaults 0 0" >> /etc/fstab
# vi /etc/fstab
# mount -a
mount: can't find LABEL=/storage
Are you sure about this? I have already labelled the filesystem as "/storage".
DeleteThe error you are getting could because you have not labelled the filesystem properly. Do check the label of the filesystem using:
$ e2label fileSystem