150

Is there a command that will list all partitions along with their labels? sudo fdisk -l and sudo parted -l don't show labels by default.

EDIT: (as per comment below) I'm talking about ext2 labels - those that you can set in gparted upon partitioning.

EDIT2: The intent is to list unmounted partitions (so I know which one to mount).

4
  • 1
    Labels? What's a label? Are you talking about ext2 labels? Those have nothing to do with partition tables per se. Commented Mar 30, 2011 at 6:33
  • Hi @Chris Jester-Young, thanks for your comment! I have tried to clarify above - yes, I believe it is ext2 labels I'm talking about... Cheers!
    – sdaau
    Commented Mar 30, 2011 at 6:37
  • 4
    Partitions don't have labels, but file systems do. You need a combination of tools to do that. The blkid tool can tell you label of a known partition. But to find the partition you would have to loop over the output of fdisk.
    – Keith
    Commented Jun 2, 2011 at 3:13
  • 3
    @Keith, as a side note, I'd like to add that the new GPT partitions have a name field which is similar to filesystem labels. Commented Jun 3, 2014 at 16:26

14 Answers 14

214

with lsblk

For instance, the command

lsblk -o name,mountpoint,label,size,uuid

outputs:

NAME                           MOUNTPOINT     LABEL         SIZE UUID
sda                                                         1.4T
├─sda1                         /boot          boot          953M f557b9f0-edb5-42bb-94d8-27bc03c3c2c7
├─sda2                                                     46.6G 727fa348-8804-4773-ae3d-f3e176d12dac
│ └─sda2_crypt (dm-0)                                      46.6G P1kvJI-5iqv-s9gJ-8V2H-2EEO-q4aK-sx4aDi
│   ├─debian_crypt-swap (dm-1) [SWAP]                         2G 3f9f24d7-86d1-4e21-93e9-f3c181d05cf0
│   ├─debian_crypt-tmp (dm-2)  /tmp           tmp             5G 93fc8219-f985-45fb-bd5c-2c7940a7512d
│   ├─debian_crypt-home (dm-3) /home          home            6G 12e8566c-8f0f-45ec-8524-6d9d9ee91eae
│   └─debian_crypt-root (dm-4) /              root         33.6G 9685570b-4c9e-43ea-815e-49d10dc7a1bf
├─sda3                                                    651.9G d3e0436c-85f6-45c6-9d8f-28b79ee06102
│ └─crypt_gusto (dm-8)         /media/Gusto   Gusto       651.9G 0c084508-cb8b-4b61-832d-6b85273f33c4
├─sda4                                                        1K
├─sda5                                                      298G 5063da5f-9b68-43de-914c-32b89622bcc8
│ └─crypt_kabi (dm-7)          /media/Kabi    Kabi          298G e6a0b66c-8fe9-4e7b-9d54-7b2b430e109d
├─sda6                                                    213.6G 5129d860-bb41-4393-b4b1-f8af53d9155d
│ └─crypt_zami (dm-6)          /media/Zami    Zami        213.6G 19101155-6070-4f37-b39d-19f28867c66b
├─sda7                         /media/Server  Server       85.6G a9f4dae5-901c-4f49-bb30-592de3000713
└─sda8                                                    100.6G dc7f4586-a33d-4707-98e9-8b55c559b0d2
  └─crypt_grafi (dm-5)         /media/Grafi   Grafi       100.6G 5e3242e1-ec7a-4806-92f7-88a126feea94
sdb                                                        14.5G
├─sdb1                                        DEBIAN_LIVE     3G 6bf4d915-2b62-444e-a2c8-16307769b5c2
├─sdb2                                                        2G 90ec6f73-8fdb-4c8d-aebd-cadd0f51b412
│ └─crypt_sdb2 (dm-10)         /mnt           data            2G 91e779dd-0a3f-40b2-8ad0-257d860541a6
└─sdb3                                        linux         9.5G 14a783a4-96dd-4a85-8de7-6e8eea230594
loop0                                                      1000M a3be80bf-0f2c-44ed-8de5-d60e3b19c01a
└─crypt_dropbox (dm-9)         /media/Dropbox Dropbox       998M 8461e2cf-ae17-449b-8ee5-29cc88688b8b
zram0                          [SWAP]                       250M f8254ae5-5ae6-4fda-b8ef-83f25c405894
zram1                          [SWAP]                       250M 7e7ed90d-731c-422a-bf9b-828f09b80502

You can specify plenty of columns in whatever order you like:

Available columns:
       NAME  device name
      KNAME  internal kernel device name
    MAJ:MIN  major:minor device number
     FSTYPE  filesystem type
 MOUNTPOINT  where the device is mounted
      LABEL  filesystem LABEL
       UUID  filesystem UUID
         RO  read-only device
         RM  removable device
      MODEL  device identifier
       SIZE  size of the device
      STATE  state of the device
      OWNER  user name
      GROUP  group name
       MODE  device node permissions
  ALIGNMENT  alignment offset
     MIN-IO  minimum I/O size
     OPT-IO  optimal I/O size
    PHY-SEC  physical sector size
    LOG-SEC  logical sector size
       ROTA  rotational device
      SCHED  I/O scheduler name
    RQ-SIZE  request queue size
       TYPE  device type
   DISC-ALN  discard alignment offset
  DISC-GRAN  discard granularity
   DISC-MAX  discard max bytes
  DISC-ZERO  discard zeroes data
11
  • 5
    Thanks for showing me this tool! Note, this application works for regular users, but will show some info (including labels) only as root.
    – user689893
    Commented Jul 4, 2014 at 7:55
  • 2
    Will it show unmounted partitions also? If yes then it solves the question asked.
    – Ravi
    Commented Jul 29, 2014 at 7:26
  • 2
    Yes. As you can see sdb1 and sdb3 aren't mounted. Commented Jul 30, 2014 at 15:02
  • 19
    or easier to remember lsblk -f which is equivalent to lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT
    – LeoR
    Commented Aug 27, 2014 at 16:52
  • 2
    sudo is not necessary.
    – Dirk
    Commented Aug 2, 2018 at 8:21
117

With udev, You can use

ls -l /dev/disk/by-label

to show the symlinks by label to at least some partition device nodes.

Not sure what the logic of inclusion is, possibly the existence of a label.

6
  • 2
    At least on my machine, it is indeed only the filesystems with labels that get linked in there, as confirmed(?) by using Alan Kuras' mount -l suggestion.
    – Ilkka
    Commented Mar 30, 2011 at 6:43
  • 3
    Hi @Ilkka - thanks for your answer! Indeed, ls -la /dev/disk/by-label seems to show labels of unmounted partitions; so that solves my problem, I guess... Although, I really would have preferred an option for fdisk or parted instead :) Cheers!
    – sdaau
    Commented Mar 30, 2011 at 6:46
  • 2
    For me, my swap partition and mounted partitions are not shown, but that may just be coincidence. Anyhow, sudo lsblk -o name,mountpoint,label,size,uuid worked for me.
    – chtenb
    Commented Jan 17, 2016 at 9:18
  • On my system /dev/disk/by-label is unpopulated when the initramfs mounts root fs. Commented Nov 8, 2021 at 17:52
  • Answer is > 10 years old. Things have changed since? On my system (Ubuntu 20.04) there's no /dev/disk/by-label OTOH: there's /dev/disk/by-partlabel
    – arielf
    Commented Feb 1, 2022 at 6:50
31

There is a blkid command which may be what you are looking for. Results are similar to the following:

$ sudo blkid /dev/mapper/vg_rootdisk-lv_var
/dev/mapper/vg_rootdisk-lv_var: LABEL="LV_VAR" UUID="08520908-03cd-4e42-a4e4-0f5a771be16c" TYPE="ext4"

One other option is to use the udevadm command, which likely will give you far more than you need:

$ sudo udevadm info --query=all --name=/dev/mapper/vg_rootdisk-lv_var
1
  • 2
    This was the only suggestion so far that worked on ddwrt
    – Karthik T
    Commented Aug 16, 2016 at 18:23
17

Try to use this command:

e2label /dev/sda2
9

Try to use mount -l, it work's fine for me.

0
8

/dev/disk

In newer versions of the Linux kernel this info can now be found here under /dev/disk.

Example

$ ls -l /dev/disk
total 0
drwxr-xr-x 2 root root 300 Mar  4 18:43 by-id
drwxr-xr-x 2 root root 140 Mar  4 18:21 by-label
drwxr-xr-x 2 root root  80 Mar  4 18:18 by-path
drwxr-xr-x 2 root root 200 Mar  4  2015 by-uuid

So you can find it by by-id, by-label, by-path or by by-uuid.

  • by-id

    $ ls -l /dev/disk/by-id
    total 0
    lrwxrwxrwx. 1 root root  9 Jan 11 17:01 ata-Optiarc_DVD_RW_AD-7930H -> ../../sr0
    lrwxrwxrwx. 1 root root  9 Jan 11 17:01 ata-ST95005620AS_5YX1K0Q5 -> ../../sda
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 ata-ST95005620AS_5YX1K0Q5-part1 -> ../../sda1
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 ata-ST95005620AS_5YX1K0Q5-part2 -> ../../sda2
    ...
    ...
    
  • by-uuid

    $ ls -l /dev/disk/by-uuid
    total 0
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 xxxxxx -> ../../sda1
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 xxxxxx -> ../../dm-1
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 xxxxxx -> ../../dm-0
    lrwxrwxrwx. 1 root root 10 Jan 11 17:01 xxxxxx -> ../../dm-2
    

    Where the xxxxxx would be an actual UUID such as 5ece678c-1234-5678-12e3-88c06ec11111.

  • by-label

    $ ls -l /dev/disk/by-label/
    total 0
    lrwxrwxrwx 1 root root 10 Mar  4 18:21 LABEL1 -> ../../sda4
    lrwxrwxrwx 1 root root 10 Mar  4 18:17 LABEL2 -> ../../sda3
    lrwxrwxrwx 1 root root 10 Mar  4 18:21 LABEL3 -> ../../sda6
    lrwxrwxrwx 1 root root 10 Mar  4 18:42 LABEL4 -> ../../sda7
    lrwxrwxrwx 1 root root 10 Mar  4 18:20 LABEL5 -> ../../sda5
    

    Where LABEL1,LABEL2,... etc are label which shows symbolic links to actual partition (e.g /dev/sda3).

1
  • To sort by partition name: ls -l /dev/disk/by-label/ | sort -k10
    – Digger
    Commented Jul 18, 2018 at 17:11
5

This will not list all partitions but you can view and alter what you like with tune2fs.

$ sudo tune2fs -l /dev/sda1

You can use a command such as this to get all the /dev/sda* devices.

$ sudo sh -c 'echo /dev/sda* /dev/mapper/fedora* | xargs -n 1 tune2fs -l'
4

e2label didn't work for me with UDF filesystem labels. blkid did;

blkid -s LABEL -o value /dev/sdg1
2
  • this answer is potentially the more complete Commented Nov 8, 2021 at 17:52
  • This is perfect for WSL because e2label requires always sudo and there is no /dev/disk. Commented Jan 13, 2022 at 16:34
4

In a Linux terminal (console) type :

blkid

Followed by Enter

The result is the list of block devices, each with LABEL and TYPE

4

Very easy:

lsblk -fp

Description from the man page:

  -f, --fs
          Output info about filesystems.  This option is equivalent to -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT.  The authoritative information about filesystems and raids is provided by the blkid(8) command.

  -p, --paths
          Print full device paths.

On both of the following distributions I have tested the command:

  • Red Hat Enterprise Linux 8.1 (Ootpa)
  • Ubuntu 18.04.3 LTS (Bionic Beaver)

Result:

$ lsblk -fp      
NAME                            FSTYPE      LABEL    UUID                                MOUNTPOINT
/dev/nvme0n1
├─/dev/nvme0n1p1                vfat        BOOT     xxxx-7xxD                           /boot/efi
├─/dev/nvme0n1p2
├─/dev/nvme0n1p3                ntfs        Windows  22xxxxxxxx1222B3001
├─/dev/nvme0n1p4                ntfs        Recovery xxxx1222222xxxx1
├─/dev/nvme0n1p5                ext4                 xxxxxx-5xx9-4xxb-xxxx-xxxxxxxxxx1   /boot
├─/dev/nvme0n1p6
├─/dev/nvme0n1p7                ext4                 xxxxxx-6xxb-4xx6-xxd7-xxxxxxxxxxxx
└─/dev/nvme0n1p8                crypto_LUKS          xxxxxx-exx0-415a-xxxx-xxxxxxxxxxxx
  └─/dev/mapper/lukslvm         LVM2_member          xxxxxx-lxxH-Rxxn-xxxx-xxxx1-xxxxxx
    ├─/dev/mapper/vgubuntu-swap swap                 xxxxxx-5xx9-4xxb-xxxx-xxxxxxxxxxxx  [SWAP]
    └─/dev/mapper/vgubuntu-root ext4                 xxxxxx-fxxa-4xxd-9e41-xxxxxxxxxxxx  /
2

You can also use this command:

$ sudo udevadm info --query all --path /sys/block/sdb/sdb1 \
     | grep ID_PART_ENTRY_NAME

You can use the above to print all the block devices' info.

$ echo /sys/block/* | xargs -n 1 udevadm info --query all --path
1

If you like, you can use my bash script for that purpose. It actually does a little more than you need, i. e. it will also show how much space is used. Hope you like it :) And I also hope that the output will be as neat as on my linux box... (Note: it will only show real hardware like your HDDs and DVD-ROMs, but that's sufficient for my purposes.)

Important note: This script might have to be run under sudo ONCE because of blkid. At least on my distro, blkid -o export will output nil when run as regular user after bootup. This is because in the "regular user rendition" of blkid, data will actually be retrieved from a cache file (normally /run/blkid/blkid.tab), which is only writable by root and will thus require one run under sudo in order to get populated with current data.

#!/bin/bash
# LICENSE: GPL

if [[ $(id -u) -ne 0 ]]; then
  if [[ ! -s /run/blkid/blkid.tab ]]; then
   # no cache file found when run as regular user
   # this will require one run under sudo to populate cache file
   echo -e "Cache file does not exist or is empty.\nPlease give your root password to continue:\n\n"   
   sudo blkid >/dev/null
  fi
fi

df -P |
sort  |
awk 'BEGIN {
             fmthdr = "%-12s%-22s%-10s\t%-5s\n"

         # since we want to use single quotes for showing label names, we had better
         # replace the problematic single quote character by its hex representation, "\x27"
             fmtlin_w_qu = "%-12s\x27%-17s\x27\t   %-10s\t%4s used\n"
             fmtlin_wo_qu = "%-12s%-17s\t   %-10s\t%4s used\n"

             printf fmthdr, " Device ",  "Volume Label", "File System", "Storage usage"
             printf fmthdr, "---------", "------------", "-----------", "-------------"
           }    
           /^\/dev\/[sh]/{
              lab = ""      # CLEAR lab w/every run (very important!)
              ("blkid -o export "$1" | grep LABEL | cut -f2 -d=") | getline lab
              ("blkid -o export "$1" | grep TYPE | cut -f2 -d=") | getline fs
              if (lab == "") {
                lab = "<none>"
                fmtlin = fmtlin_wo_qu
              }
              else
                fmtlin = fmtlin_w_qu

              printf fmtlin, $1, lab, fs, $5
           }'
0

I use also lsblk mentioned above, but I find the following options better suiting:

sudo lsblk -o name,mountpoint,tran,fstype,label,size
0

I found out how I get the fslabel of the fsroot partition as a regular user. This page helped me to succeed. Was not easy. Many commands only work with sudo, but /etc/mtab and /dev/disk/by-label are readable as regular user.

Here is the bash code:

test=`cat /etc/mtab|grep " / "`
test=${test%% *}
test=${test##*/}
test=`ls -l /dev/disk/by-label/|grep $test`
test=${test%% ->*}
test=${test##* }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .