How to create a zpool using uuid or truly unique identifier

filesystemsuuidzfs

I created my first zpool the other day, assigning by drive letter, and found that when I rebooted it was degraded. Upon closer inspection, I realized that my drive letters had changed with reboot, so I figured I should do it using UUIDs.

I took a look at blkid and saw that both drives had identical uuids, presumably because they are mirrored. So I destroyed the pool and created new partition tables on the disks. When I ran blkid again, I saw that the drives no longer had UUIDs, just a PTID. This led me to realizingt that UUID is a property of a filesystem, not the drive itself.

So, I tried using /dev/disk/by-id/ both with the UUID of the formatted drive, and the PTID of the unformatted drive. Neither worked.

user@ubuntu:~$ sudo zpool create nvme-tank mirror /dev/disk/by-id/493fa01d /dev/disk/by-id/9398aa9e
cannot resolve path '/dev/disk/by-id/493fa01d'

user@ubuntu:~$ sudo zpool create nvme-tank mirror /dev/disk/by-id/713e95ab-f307-466c-bc6c-f9ec97914a6a /dev/disk/by-id/44042f83-1654-45b4-9803-42107393af6c
cannot resolve path '/dev/disk/by-id/713e95ab-f307-466c-bc6c-f9ec97914a6a'

this is the output of blkid:

/dev/sdb1: UUID="1977-5195" TYPE="vfat" PARTUUID="117c616a-01"
/dev/sdd1: UUID="3d09d690-6110-3c87-abb6-c286e58cf8ae" UUID_SUB="481418c7-ff1c-3ee6-21e1-48be73d0a083" LABEL="ubuntu:0" TYPE="linux_raid_member" PARTUUID="edbfb533-01"
/dev/sdd2: UUID="bb4a8e51-48de-3c04-435f-d48ba763b176" UUID_SUB="3cd3b591-6c08-23df-c885-812b8a4dae09" LABEL="ubuntu:1" TYPE="linux_raid_member" PARTUUID="edbfb533-02"
/dev/sde1: UUID="3d09d690-6110-3c87-abb6-c286e58cf8ae" UUID_SUB="294836fe-a958-5aa8-f9e7-fcb0d5b3ad68" LABEL="ubuntu:0" TYPE="linux_raid_member" PARTUUID="870c34a5-01"
/dev/sde2: UUID="bb4a8e51-48de-3c04-435f-d48ba763b176" UUID_SUB="4f2b1400-7d20-79f5-106f-33fdb0dafc36" LABEL="ubuntu:1" TYPE="linux_raid_member" PARTUUID="870c34a5-02"
/dev/md1: UUID="be1c70fd-3000-4a69-9106-efc73309693d" TYPE="ext4"
/dev/md0: UUID="4c0b7a2c-1b40-4979-868a-0e363bcbe771" TYPE="swap"
/dev/nvme1n1p1: UUID="713e95ab-f307-466c-bc6c-f9ec97914a6a" TYPE="ext4" PARTUUID="9398aa9e-01"
/dev/nvme2n1p1: UUID="24d22c02-be8f-41ba-9907-9494b03c16bb" TYPE="ext4" PARTUUID="edc5ee37-01"
/dev/nvme0n1p1: UUID="44042f83-1654-45b4-9803-42107393af6c" TYPE="ext4" PARTUUID="493fa01d-01"
/dev/nvme0n1: PTUUID="493fa01d" PTTYPE="dos"
/dev/nvme2n1: PTUUID="edc5ee37" PTTYPE="dos"
/dev/nvme1n1: PTUUID="9398aa9e" PTTYPE="dos"
/dev/sda: PTUUID="d5f5a456" PTTYPE="dos"
/dev/sdc: PTUUID="b462c818" PTTYPE="dos"

some of the threads I looked at led me to look at /etc/default/zfs
I found that the relevant line was commented out, but I wasn't sure what to make about the comments above it, which are worded in a way that confuses me:

# Specify specific path(s) to look for device nodes and/or links for the
# pool import(s). See zpool(8) for more information about this variable.
# It supersedes the old USE_DISK_BY_ID which indicated that it would only
# try '/dev/disk/by-id'.
# The old variable will still work in the code, but is deprecated.
#ZPOOL_IMPORT_PATH="/dev/disk/by-vdev:/dev/disk/by-id"

So, my question is, can I directly create zpools using a unique and permenant identifier, such as serial number? Or is there another way to create them by UUID that actually works?

I am using ZFS on Ubuntu Server 18.04

Edit: Further attempts
I also tried the advice here: https://ubuntuforums.org/showthread.php?t=2087726

user@ubuntu:~$ sudo zpool create nvme-tank mirror nvme0n1 nvme1n1
user@ubuntu:~$ sudo zpool export nvme-tank
user@ubuntu:~$ sudo zpool import -d /dev/disk/by-id nvme-tank

But now I don't see them in blkid at all:

/dev/sdb1: UUID="1977-5195" TYPE="vfat" PARTUUID="117c616a-01"
/dev/sdd1: UUID="3d09d690-6110-3c87-abb6-c286e58cf8ae" UUID_SUB="481418c7-ff1c-3ee6-21e1-48be73d0a083" LABEL="ubuntu:0" TYPE="linux_raid_member" PARTUUID="edbfb533-01"
/dev/sdd2: UUID="bb4a8e51-48de-3c04-435f-d48ba763b176" UUID_SUB="3cd3b591-6c08-23df-c885-812b8a4dae09" LABEL="ubuntu:1" TYPE="linux_raid_member" PARTUUID="edbfb533-02"
/dev/sde1: UUID="3d09d690-6110-3c87-abb6-c286e58cf8ae" UUID_SUB="294836fe-a958-5aa8-f9e7-fcb0d5b3ad68" LABEL="ubuntu:0" TYPE="linux_raid_member" PARTUUID="870c34a5-01"
/dev/sde2: UUID="bb4a8e51-48de-3c04-435f-d48ba763b176" UUID_SUB="4f2b1400-7d20-79f5-106f-33fdb0dafc36" LABEL="ubuntu:1" TYPE="linux_raid_member" PARTUUID="870c34a5-02"
/dev/md1: UUID="be1c70fd-3000-4a69-9106-efc73309693d" TYPE="ext4"
/dev/md0: UUID="4c0b7a2c-1b40-4979-868a-0e363bcbe771" TYPE="swap"
/dev/nvme2n1p1: UUID="24d22c02-be8f-41ba-9907-9494b03c16bb" TYPE="ext4" PARTUUID="edc5ee37-01"

Best Answer

UUID is not always visible, (specially in VM env) I suggest to create a partition table and use PARTUUID

after you are able to list the desidered partition

lsblk --ascii -o NAME,PARTUUID,LABEL,PATH,FSTYPE
zpool create pool02 /dev/disk/by-partuuid/c8e0c300-5ec9-714c-aef9-fa0dc3f0cab6

there no performance penalties when partition table against entire raw disk and examining the partition table may save your work in case of Disaster recovery

Related Question