Is it possible to get a list of disks in zpool using without grep/awk/sed?

Hi just came over from the reddit :slight_smile:

I’m trying to find a quick way to get a list of the physical devices in a zpool for use in a script. Is there a way to do this without resorting to grep/awk/sed of zpool status ?

So, instead of this

[root@archlinux ~]# zpool status
  pool: rootfs
 state: ONLINE

        NAME                           STATE     READ WRITE CKSUM
        rootfs                         ONLINE       0     0     0
          mirror-0                     ONLINE       0     0     0
            ata-QEMU_HARDDISK_QM00001  ONLINE       0     0     0
            ata-QEMU_HARDDISK_QM00002  ONLINE       0     0     0

errors: No known data errors
[root@archlinux ~]#

I’d have this

$ some-zpool-command

It’d return all disks for a given pool or all disks for all pools.

Does that exist at all?

In theory—and according to the manpage for zpool get—that would be zpool get physpath rootfs all-vdevs.

The manpage specifies the following syntax for getting properties of vdevs:

zpool get [-Hp ] [-o field[,field]…] all |property[,property]… pool [all-vdevs |vdev]…

And the manpage for vdev properties offers the following relevant properties:

The device id for this vdev
The physical path to the device
The enclosure path to the device

edit: But in practice, it turns out that the zpool get all-vdevs feature is only available in OpenZFS master, and hasn’t worked its way down to a proper release yet.

This is the most compact thing I can think of:

zpool list -Pv rpool | awk '/^ / {print $1}'

(that’s 4 spaces at the beginning of line)

You can make a shell function, or a tiny helper command to place in ~/bin if you use this often.