Zfs

增長 ZFS 鏡像

  • April 22, 2022

我有一個 RAID 10 配置中包含 6 個磁碟的 ZFS 池。

我想將其中一個鏡像中的驅動器從 1TB 升級到 3TB。我在系統中安裝了所有驅動器。

我不希望通過更換一個驅動器,重新同步,重複來做到這一點。有沒有辦法從現有鏡像中執行所有讀取操作,同時保持我要移除的驅動器上的所有磨損?

root@e7-4860:~# zpool status
 pool: stuffpoll
state: ONLINE
 scan: scrub repaired 0 in 6h50m with 0 errors on Sun Dec 10 07:14:34 2017
config:

   NAME                                               STATE     READ WRITE CKSUM
   stuffpoll                                          ONLINE       0     0     0
     mirror-0                                         ONLINE       0     0     0
       ata-HGST_HTS721010A9E630_JR10004M0LGN6E-part1  ONLINE       0     0     0
       ata-HGST_HTS721010A9E630_JR10004M0M17TE-part1  ONLINE       0     0     0
     mirror-1                                         ONLINE       0     0     0
       ata-HGST_HTS541010A9E680_JA1000102MG9UR-part1  ONLINE       0     0     0
       ata-HGST_HTS541010A9E680_JA1009C03158BP-part1  ONLINE       0     0     0
     mirror-2                                         ONLINE       0     0     0
       ata-HGST_HTS721010A9E630_JR100X6P2TJKVE        ONLINE       0     0     0
       ata-HGST_HTS721010A9E630_JR100Y4M01200M        ONLINE       0     0     0

errors: No known data errors


root@e7-4860:~# zpool list
NAME        SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
stuffpoll  2.72T  2.47T   254G         -    48%    90%  1.00x  ONLINE  -


root@e7-4860:~# ls /dev/disk/by-id/ -1
ata-CT240BX200SSD1_1613F0194817
ata-CT240BX200SSD1_1613F0194817-part1
ata-HGST_HTS541010A9E680_JA1000102MG9UR
ata-HGST_HTS541010A9E680_JA1000102MG9UR-part1
ata-HGST_HTS541010A9E680_JA1000102MG9UR-part9
ata-HGST_HTS541010A9E680_JA1009C03158BP
ata-HGST_HTS541010A9E680_JA1009C03158BP-part1
ata-HGST_HTS541010A9E680_JA1009C03158BP-part9
ata-HGST_HTS721010A9E630_JR10004M0LGN6E
ata-HGST_HTS721010A9E630_JR10004M0LGN6E-part1
ata-HGST_HTS721010A9E630_JR10004M0LGN6E-part9
ata-HGST_HTS721010A9E630_JR10004M0M17TE
ata-HGST_HTS721010A9E630_JR10004M0M17TE-part1
ata-HGST_HTS721010A9E630_JR10004M0M17TE-part9
ata-HGST_HTS721010A9E630_JR100X6P2TJKVE
ata-HGST_HTS721010A9E630_JR100X6P2TJKVE-part1
ata-HGST_HTS721010A9E630_JR100X6P2TJKVE-part9
ata-HGST_HTS721010A9E630_JR100Y4M01200M
ata-HGST_HTS721010A9E630_JR100Y4M01200M-part1
ata-HGST_HTS721010A9E630_JR100Y4M01200M-part9
scsi-35000c50055fb009b
scsi-35000c50055fb395f

我想最終mirror-1scsi-35000c50055fb009b和替換驅動器scsi-35000c50055fb395f

如果您想手動擴展卷,您只需使用該-e選項將其聯機即可。

zpool online -e stuffpoll

您還可以切換自動擴展選項以使其自動發生。

zpool set autoexpand=on stuffpoll

因此,假設您正在向 mirror-2 添加新驅動器,以便您可以擴展它。您需要使用現有設備名稱之一作為目標來連接新驅動器。您可以在刪除舊設備之前將這兩個新設備添加到鏡像中。

# zpool attach pool existing_vdev_member new_device
zpool attach stuffpoll ata-HGST_HTS721010A9E630_JR100X6P2TJKVE new_dev1
zpool attach stuffpoll ata-HGST_HTS721010A9E630_JR100X6P2TJKVE new_dev2

新設備同步完成後,您可以移除舊設備。

zpool detach stuffpoll ata-HGST_HTS721010A9E630_JR100X6P2TJKVE
zpool detach stuffpoll ata-HGST_HTS721010A9E630_JR100Y4M01200M

男人 zpool

zpool attach [-f] pool device new_device

Attaches new_device to an existing zpool device. The existing device
cannot be part of a raidz configuration. If device is not currently
part of a mirrored configuration, device automatically transforms
into a two-way mirror of device and new_device.  If device is part of
a two-way mirror, attaching new_device creates a three-way mirror,
and so on. In either case, new_device begins to resilver immediately.
...

zpool detach pool device

Detaches device from a mirror.  The operation is refused if there are
no other valid replicas of the data.  If device may be re-added to
the pool later on then consider the zpool offline command instead.
...

zpool online [-e] pool device ...

Brings the specified physical device online.
-e  Expand the device to use all available space. If the device
   is part of a mirror or raidz then all devices must be
   expanded before the new space will become available to the
   pool.

連結

另外,我喜歡提醒人們。首先驗證您的備份/恢復。總是有可能發生不好的事情。還可以考慮在測試機器/VM 上建構一個 zfs 池並提前練習您的命令。

引用自:https://serverfault.com/questions/887543