Labeling Linux partitions

Here’s something a lot of Linux users probably overlook. If you manually create a partition or file system on a new hard drive but you want mount during each boot you should mount the drive based on its label instead of it’s device name. This will prevent the system from mounting a drive in the wrong place if you ever switch cables around or move the drive to a different machine.

Labeling a partition is simple, just use e2label /dev/

e2label /dev/sdb1 "NewDrive"

To mount this drive on boot, edit your /etc/fstab file as root with your favorite editor. Add a new line at the bottom with, based on the example above, the following:

LABEL=NEWDRIVE /mountpoint defaults 0 0

You can use the other entries in the file as a template. Use ‘man fstab’ and ‘man e2label’ to learn more about how to use e2label.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.