index.html

Manage Hard Drives in Zpool Using Vdev ID

字数统计: 489阅读时长: 3 min
2019/05/09 Share

It is easy to set up a disk raid using ZFS. Many tutorials / documents give the examples using # zpool create tank /dev/sdb /dev/sdc /dev/sdd.

However, this is not a good practice, descibed in the ZFS on Linux FAQ, the names of the devices are not persistent. Any device change, for example, unplug a removable hard drive, could mess up with the configuration.

It is suggested to use a persistent disk identifier to manage the zpool, for example using disk ID.

To switch an exist zpool from /dev/sdX to /dev/disk/by-id, just export then import the pool.

1
2
sudo zpool export tank
sudo zpool import -d /dev/disk/by-id tank

The above command should replace the disk in zpool with something like ata-WDC_WD40EZRZ-00GXCB0_WD-WCC3Z7KHKLAN or wwn-0x50014ee215a0e59e.

But in some rare case, the output of # zpool stauts tank may seems like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[email protected]local:~$ sudo zpool export tank
[email protected]local:~$ sudo zpool import -d /dev/disk/by-id/ tank
[email protected]local:~$ sudo zpool status
pool: tank
state: ONLINE
scan: resilvered 114M in 51h41m with 0 errors on Thu May 9 19:81:00 2019
config:

NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
wwn-0x50014ee25a19e0e5 ONLINE 0 0 0
wwn-0x50014ee2646a219f ONLINE 0 0 0
wwn-0x50014ee2809e2fb0 ONLINE 0 0 0
wwn-0x50014ee2c1d4b99f ONLINE 0 0 0
raidz1-1 ONLINE 0 0 0
ata-WDC_WD40EZRZ-00GXCB0_WD-WCC7YK40YEAY ONLINE 0 0 0
wwn-0x50014ee214b0cbbd ONLINE 0 0 0
wwn-0x50014ee23103e7a2 ONLINE 0 0 0
wwn-0x50014ee25646e036 ONLINE 0 0 0

errors: No known data errors

One disk often has multiple entries under /dev/disk/by-id/, there is no garantee which one will be used by zpool.

The solution is to use vdev ID.

Benefits: The main benefit of this approach is that it allows you to choose meaningful human-readable names. Beyond that, the benefits depend on the naming method employed. If the names are derived from the physical path the benefits of /dev/disk/by-path are realized. On the other hand, aliasing the names based on drive identifiers or WWNs has the same benefits as using /dev/disk/by-id.

Create the config file /etc/zfs/vdev_id.conf

1
2
3
4
5
6
7
8
9
10
# alias for the disk
alias A0 /dev/disk/by-id/wwn-0x50014ee25a19e0e5
alias A1 /dev/disk/by-id/wwn-0x50014ee2646a219f
alias A2 /dev/disk/by-id/wwn-0x50014ee2809e2fb0
alias A3 /dev/disk/by-id/wwn-0x50014ee2c1d4b99f

alias B0 /dev/disk/by-id/wwn-0x50014ee215f5a14d
alias B1 /dev/disk/by-id/wwn-0x50014ee214b0cbbd
alias B2 /dev/disk/by-id/wwn-0x50014ee23103e7a2
alias B3 /dev/disk/by-id/wwn-0x50014ee25646e036

This will create friendly disk shortcuts in /dev/disk/by-vdev/

After reboot, export and import the zpool:

1
2
sudo zpool export tank
sudo zpool import -d /dev/disk/by-vdev tank

The detailed tutorial of vdev_id.conf can be found here or here.

Remeber when miggrate the pool, also copy the vdedv_id.conf to the new place.

EOF

CATALOG