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 ~]#
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:
zpoolget [-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.
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” ?