Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I add a label to a partition on a disk, and how do I then mount it by label (manually and via fstab)?

note: this is an external hard drive

share|improve this question
    
This would depend on your unix variant and partitioning method. Some partitioning methods (such as the usual PC one) don't support labels, but most filesystems do, which may be enough for you. –  Gilles Oct 24 '10 at 22:33

1 Answer 1

up vote 12 down vote accepted

If your partition is ext2,ext3 or ext4, you can use the e2label command to set the label:

       e2label - Change the label on an ext2/ext3/ext4 filesystem

SYNOPSIS
       e2label device [ new-label ]

after you have set the label to, say, "data" you can add a line in /etc/fstab like this one

LABEL=data /mnt/data ext4 noauto,users,rw 0 0

then you just need to say mount /mnt/data. If you don't want to modify fstab you can use mount's -L option to specify the label:

mount -L data /mnt/data
share|improve this answer
    
relatime should be redundant on recent kernels it's the default now, iirc. –  xenoterracide Oct 24 '10 at 20:54
    
Thanks, changed. –  fschmitt Oct 24 '10 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.