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
config:

        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
ata-QEMU_HARDDISK_QM00001
ata-QEMU_HARDDISK_QM00002

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:

devid
The device id for this vdev
physpath
The physical path to the device
encpath
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.

A different approach, since I still don’t see anything else - but it would get tricky if you don’t know the layout ahead of time

fred=($(zpool list -HPv tank))
echo ${fred[11]}
echo ${fred[21]}
echo ${fred[31]}

if you checked the length of the array you’d know how many times to increment by ten and keep outputting values, then I guess you’d grep out the “mirror-1” ?

Just a thought