17

I have noticed that when partitioning and formatting a hard drive, I can independently set the partition name and the partition label. For example, when partitioning with gdisk, it is possible to change partition names, and when afterwards formatting with mkfs.ext4 it is possible to set the partition label (with -L option). Apparently the two are independent.

What is the difference? How each is used?

I know about ls /dev/disk/by-label, but not much more. Quick search in the Internet did not help.

15

The GPT disk format can simply contain more data than its predecessors. One of these fields is the partition name, which, as you have found, can be set by gdisk or similar. However, before GPT, there were formats which didn't support labels in the partition table (e.g. MBR), so the data was stored in the fs as a filesystem label. Using GPT with a filesystem that supports labels (i.e. basically anything) therefore produces the slightly confusing combination of partition name/label and filesystem name/label.

These values are totally independent, (although I don't exactly recommend making them totally different) and most programs will use the fs label, as that one is available across basically all file systems, unlike the partition name, which is only on GPT. However, some programs can use the partition name too. (E.g. /dev/disk/ contains by-label/ as well as by-partlabel/.)

I'm not quite sure as to why you'd ever have to use the partition label, but a contrived example could be an encrypted /home partition. Because the partition is encrypted, the label (or UUID for that matter) cannot be extracted without decrypting it first. (Note that common containers do support these values.) Therefore, you'd have to hardcode the partition number somewhere. Because no one likes hardcoded numbers, you could instead set the partition label and access the partition like that when you decrypt.

  • Note that the LUKS encryption container has its own UUID (though unfortunately not a label field), as does the mdraid metadata and LVM metadata. – grawity Jul 11 '16 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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