Computing, Linux, system administration

Mounting file systems by label in Linux

The classic way to mount a file system in Linux (and UNIX-like systems) is to modify the /etc/fstab file. For example, to mount the file system on /dev/sdc1 on /mnt/ExpansionDrive, you add this line to /etc/fstab:

/dev/sdc1    /mnt/ExpansionDrive    auto    defaults

… and then issue this command in a terminal (using root privileges):

mount /mnt/ExpansionDrive

In this example, you reference the file system by the disk and partition it’s located on: the first partition (1) on the third drive in the system (sdc).

This has two drawbacks. Firstly, it’s complicated to keep track of drive and partition numbers, and secondly, the name of the drive may change when you reconfigure the hardware. For example, if you add a drive to the system, /dev/sdc1 may suddenly become /dev/sdd1, and the wrong file system may be mounted.

Another way to reference file systems is by using the volume id. For example, the file system on your drive may have been assigned the volume id AE12-B3C5 by the factory. In that case, you can use this line in /etc/fstab:

UUID=AE12-B3C5    /mnt/ExpansionDrive    auto    defaults

This method ensures the correct file system is mounted, but it’s still hard to read and remember.

A third way to reference file systems is by using the volume label. For example, the file system on your drive may have been assigned the volume label ExpansionDrive by the factory. In that case, you can use this line in /etc/fstab:

LABEL=ExpansionDrive    /mnt/ExpansionDrive    auto    defaults

With this method, it’s very easy to see which file system is referenced. To ensure the correct file system is mounted, you only need to assign each disk a unique label.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s