3

I've been searching around, and can't find a clear answer, or I find that the answer is 'no' when my system shows me otherwise.

I'm running Arch Linux, and while attaching new HDD into a zfs pool I noticed that my main SSD system drive has a LABEL attribute/property (not sure what the terminology is). NOTE: I'm talking about the drive, not the partitions within that drive.

I would really like to have my other disks have a LABEL like that, but can't figure out how to get that done.

Anyone have any idea how to achieve this?

Below is a cleaned-up output of lsblk to illustrate what I'm looking for. In my system <#LABEL1#> is set as seen in the output, I want to set/change <#WANTTHIS#>.

NAME      SIZE TYPE LABEL        PTTYPE PTUUID                               MODEL                 SUBSYSTEMS
loop0   ###.#M loop                                                                                block
loop1   ###.#M loop                                                                                block
loop2   ###.#M loop                                                                                block
loop3   ###.#M loop                                                                                block
sda     ###.#G disk <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa SomeModelString1      block:scsi:pci
├─sda1  ###.#M part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda2  ###.#M part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda3  ###.#M part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda4  ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda5  ###.#M part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda6  ###.#M part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda7  ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda8  ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda9  ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
├─sda10 ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
└─sda11 ###.#G part <#LABEL1#>   gpt    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa                       block:scsi:pci
.
.
.
sdg     ###.#G disk              dos    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx SomeModelString2      block:scsi:pci
└─sdg1  ###.#G part <#LABEL2#>   dos    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                       block:scsi:pci
sdh     ###.#T disk <#WANTTHIS#> gpt    bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb SomeModelString3      block:scsi:usb:pci
sdi     ###.#T disk <#WANTTHIS#> gpt    cccccccc-cccc-cccc-cccc-cccccccccccc SomeModelString3      block:scsi:usb:pci
├─sdi1  ###.#T part some-part    gpt    cccccccc-cccc-cccc-cccc-cccccccccccc                       block:scsi:usb:pci
└─sdi9  ###.#M part              gpt    cccccccc-cccc-cccc-cccc-cccccccccccc                       block:scsi:usb:pci
.
.
.

Edit: After accepting answer

Per @frostschutz In my example above, the FSTYPE in my case was zfs_member, and the label was actually the name of the zfs-pool (which was named exactly like my system name, so I thought I might have named it manually in the past - I did not).

The one relevant unique identifier that ties to the physical disk is the WWN, and the one that ties to the GPT partition table is the PTUUID.

So, as with all other answers I've found before, the answer is 'NO'.
There is no way to assign a name to a disk device.

From now on my lsblk command options of choice for listing relevant IDs would be:

$ lsblk --output=NAME,SIZE,RO,TYPE,WWN,PTTYPE,PTUUID,MODEL,SUBSYSTEMS,LABEL,PARTLABEL,PARTUUID,MOUNTPOINT
  • actually I did manage to label a whole disk, although accidentaly: I made an fs (btrfs in fact but may not matter) on the whole unpartitioned disk and labelled it, then created an MBR, partition table and partitions (overwriting the btrfs), but the old btrfs label stayed. lsblk and other tools detect it. I wish to have a stadard way to save label in the inter-partition area of the disk. – bandie Jan 28 at 22:15
  • i drafted a script to patch (btfs-style) label into the disk's unpartitioned area: github.com/bAndie91/tools/blob/master/disk-mgmt/phantomlabel - note it can corrupt your data if something else uses that disk area (around a bit above the first 64k), eg. bootloader, softRAID, partition starting earlier than the usual sector 2048, etc. – bandie Jan 29 at 15:23
3

That depends on the contents of the device. More specifically, it depends on whether or not there is a known superblock that provides a label.

This can be a filesystem superblock (like ext4, xfs, fat, iso9660, ...), a swap device, a raid superblock (mdadm), or even a crypt container (LUKS2).

Accordingly you can specify a label when you mkfs a filesystem, or perhaps change it later with a filesystem specific tool (for ext4, that would be tune2fs -L), in case of mdadm it's the --name of the array and in case of LUKS2 the cryptsetup --label option.

To my knowledge there is no way to set labels arbitrarily without having it attached to some filesystem or other superblock providers. Closest you can get is with PARTLABEL in a GPT partition table (parted name ...), then it's attached to the partition table itself, but then, a PARTLABEL is not a LABEL. It does not override or replace the filesystem labels.

There is no generic standard for labels, it's all hand-knitted, see for example this implementation of superblocks formats in util-linux. If you invent a new filesystem tomorrow, even if it has a label, it won't show up until support is added.

In your lsblk output, if you add the FSTYPE column, you might get some idea what might have provided the labels you are seeing. Then if you want to provide a label on another device the same way, you just... have to put the same filesystem (or raid superblock, or whatever it was...) on that device, too. Doing so will naturally remove whatever else was on there before (you can't have two filesystems on one device, not without creating new devices first).

  • FSTYPE indeed solved the mystery. It's zfs_member, although not formatted as zfs, I had played a while back with a partition as a member of a zfs array. This explains so much. Thanks for this! – Lockszmith Jul 7 '19 at 18:40
  • Moreover, looks like the best way to designate a drive is using it's WWN field, that's the unique unchanged value that I should look for. – Lockszmith Jul 7 '19 at 18:45
  • 1
    @Lockszmith you can surgically remove old superblocks with wipefs, however great caution is necessary, as it might surgically remove everything else too... well, this is mainly a concern for old RAID superblocks you don't want to trigger a resync... – frostschutz Jul 7 '19 at 18:45
  • (and this is also why I don't recommend putting fake superblocks on your disks, although it would certainly be possible, you can't rule out side effects. not worth it for a label, when sane alternatives exist) – frostschutz Jul 7 '19 at 18: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.