2

I am looking for a way to list all partitions of a specific type on linux. (Specifically: all EFI system partitions).

I know blkid can filter on filesystem type: the command blkid -t TYPE=vfat returns the correct results, but is not very robust: there might be other vfat filesystems which aren't ESPs, or there might be ESPs formatted with a different filesystem.

So, is there an equivalent command that can list devices but filter on partition type?

EDIT

I need a list of all EFI System Partitions (or ESPs). These partitions have partition type EF00 in gdisk or partition type ef in fdisk. They are most commonly formatted as vfat. Now, I can use blkid to list all partitions which are formatted with vfat, but that leaves two problems:
a) There might be EFI partitions not formatted with vfat (or not formatted at all) which would be missing from the list, and
b) there might be regular filesystemes formatted as vfat, which would be included in the list incorrectly. So matching on filesystem type is not the way to go. That's why I am looking for something that can match on partition type, so EF00 or ef.

If such a command does not exist, I would probably need to do the following to get at the information I want:
- list all disks
- for each disk, find out if there is an MBR or GPT partition table on it
- list the partition table
- filter the results to only print the ESP partitions

This is cumbersome and error-prone, so if an equivalent of blkid exists that is able to match partition types, I would like to use that.

1
  • lsblk -fcombined with grep could do it, I am not quite sure what you mean by EFI system partitions.
    – mzhaase
    Nov 23, 2016 at 11:19

3 Answers 3

2

lsblk -o +PARTTYPE includes the partition type UUID in the listing. The EFI System Partition type UUID is C12A7328-F81F-11D2-BA4B-00A0C93EC93B, so grepping for this (in lower case, or use the -i flag with grep) lists your ESPs.

0

1) For list partitions of specific type:

:~# lsblk -ln -o NAME,TYPE
...
sda          disk
sda1         part
sda1_crypt   crypt
vg0xa-system lvm
vg0xa-swap   lvm
vg0xa-tmp    lvm
vg0xa-var    lvm
vg0xa-usr    lvm
...

See also: lsblk -ln -o NAME,PARTTYPE

2) or more specifically:

:~# lsblk -ln -o NAME,TYPE | grep sda1_crypt
sda1_crypt   crypt
1
  • I'm not looking for partitions of a specific filesystem type, but of a specific partition type. I'll expand my question. Nov 23, 2016 at 12:20
0

In order to list EFI partition you can use:

$ lsblk -ln -o NAME,LABEL | grep EFI_SYSPART | awk '{print $1}'
nvme0n1p1
nvme1n1p1

or filer by filesystem FSTYPE:

lsblk -ln -o NAME,FSTYPE | grep vfat
nvme0n1p1 vfat
nvme1n1p1 vfat
  • for each disk, find out if there is an MBR or GPT partition table on it

Try parsing JSON output of lsblk -J (you'll need version > 2.25, 2.33 seems to support this).

You can process it with jq or Python/Ruby/Perl script:

$ lsblk -J -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL | jq .blockdevices
[
  {
    "name": "sr0",
    "fstype": null,
    "size": "1024M",
    "mountpoint": null,
    "label": null
  },
  {
    "name": "nvme0n1",
    "fstype": null,
    "size": "894,3G",
    "mountpoint": null,
    "label": null,
    "children": [
      {
        "name": "nvme0n1p1",
        "fstype": "vfat",
        "size": "511M",
        "mountpoint": "/boot/efi",
        "label": "EFI_SYSPART"
      },
      {
        "name": "nvme0n1p2",
        "fstype": "linux_raid_member",
        "size": "29,3G",
        "mountpoint": null,
        "label": null,
        "children": [
          {
            "name": "md2",
            "fstype": "ext4",
            "size": "29,3G",
            "mountpoint": "/",
            "label": "/"
          }
        ]
      },
...

You must log in to answer this question.

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