19

Is there a command to list all partition labels?

I can list the partitions with

sudo fdisk -l

but it doesn't show the labels of unmounted partitions.

Pandya
  • 37,289
rubo77
  • 34,024
  • 52
  • 172
  • 299

4 Answers4

23
sudo blkid -o list

lists all devices with labels:

device          fs_type  label     mount point         UUID
----------------------------------------------------------------------------------
/dev/sda1       ntfs     WINRE_DRV (not mounted)       604C3A6A4C3A3B5C
/dev/sda2       vfat     SYSTEM_DRV (not mounted)      6C3C-72E3
/dev/sda3       vfat     LRS_ESP   (not mounted)       5240-1BEE
/dev/sda5       ntfs     Windows8_OS /media/Win8       A47A42FF7A42CDAC
/dev/sda6       ntfs     Daten     /media/Daten        72860971860936DF
rubo77
  • 34,024
  • 52
  • 172
  • 299
18

Simply labels?

$ ls /dev/disk/by-label/              
Download  MuruHome  Ubuntu  Windows8  arch

Or better:

$ tree /dev/disk/by-label/  # or use ls -l
/dev/disk/by-label/
├── Download -> ../../sda6
├── MuruHome -> ../../sdc2
├── Ubuntu -> ../../sdc1
├── Windows8 -> ../../sda2
└── arch -> ../../sda1

If you're willing to use sudo (which blkid requires), then you could also use the lsblk command:

$ sudo lsblk -o NAME,LABEL
NAME                    LABEL
sda                     
├─sda1                  System Reserved
├─sda2                  windows
├─sda3                  ubuntu
├─sda4                  
├─sda5                  arch
├─sda6                  
│ └─lvmg-homelvm (dm-0) homelb
└─sda7                  
sdb                     
└─sdb1                  
  └─lvmg-homelvm (dm-0) homelb
muru
  • 207,228
3

Use the command

lsblk -nPo  MOUNTPOINT,UUID,LABEL    

You will get a list of fields that are most useful for your requirement.

zx485
  • 2,865
0

To see the GUID partition table (GPT) names (including unmounted partitions): use fdisk -l also with the switch -o and option Name. For example:

sudo fdisk -l -o Name,Device,Size,Type

prints:

Name           Device           Size Type
ubuntu         /dev/nvme0n1p1   400G Linux filesystem
home           /dev/nvme0n1p2  2000G Linux filesystem
recover        /dev/nvme0n1p3   300G Linux filesystem
               /dev/nvme0n1p4    16M Linux filesystem
win            /dev/nvme0n1p5   400G Microsoft basic data

to see columns for gpt partition table that you may choose from, run:

fdisk -h

output:

Available output columns:
 gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID
 dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S
 bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize
 sgi: Device Start End Sectors Cylinders Size Type Id Attrs
 sun: Device Start End Sectors Cylinders Size Type Id Flags

you need to look for the line that starts with gpt and combine chosen names with comma ,.

fdisk for gpt all columns example:

sudo fdisk -l -o Device,Start,End,Sectors,Size,Type,Type-UUID,Attrs,Name,UUID
Jimmix
  • 131