在 Solaris 環境中,當開機磁碟因為容量吃緊或出現硬體故障而必須替換時,ZFS 根池(rpool)的處理方式會依「是否為鏡像」而分成兩條完全不同的路徑。以下把兩種情境的作法和容易踩到的坑整理清楚。
如果 rpool 本身就是 mirror 結構,流程相對單純,用 zpool replace 就能完成,事後別忘了補上開機區塊。
# zpool offline rpool c1t0d0s0 # cfgadm -c unconfigure c1::dsk/c1t0d0 <實體拔除故障碟> <實體插入新碟> # cfgadm -c configure c1::dsk/c1t0d0 # zpool replace rpool c1t0d0s0 # zpool online rpool c1t0d0s0 # zpool status rpool <等待 resilver 完成後再安裝開機區塊>
開機區塊的安裝要依平台而異:
SPARC# installboot -F zfs /usr/platform/`uname -i`/lib/fs/zfs/bootblk /dev/rdsk/c1t0d0s0 x86# installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c1t0d0s0
若根池只是單顆碟,不能直接 replace,必須先把新碟切好分割區並寫入標籤,再用 attach 把它拉進池裡形成 mirror。
# devfsadm
# format -e c8t1d0 format> partition partition> print Current partition table (original): Total disk cylinders available: 30398 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 1 - 30396 232.85GB (30396/0/0) 488311740 2 backup wu 0 - 30396 232.85GB (30397/0/0) 488327805 8 boot wu 0 - 0 7.84MB (1/0/0) 16065 partition> quit format> label [0] SMI Label [1] EFI Label Specify Label type[0]: 0 Ready to label disk, continue? y
這一步的 resilver 時間取決於資料量,可能相當漫長,切勿中途重開機。
# zpool attach rpool c0d0s0 c0d2s0
Make sure to wait until resilver is done before rebooting.
# zpool status
pool: rpool
state: ONLINE
status: One or more devices is currently being resilvered.
scan: resilver in progress since Wed Jul 24 15:39:51 2013
302M scanned out of 7.47G at 11.2M/s, 0h10m to go
269M resilvered, 3.95% done
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
c0d0s0 ONLINE 0 0 0
c0d2s0 ONLINE 0 0 0 (resilvering)
SPARC# installboot -F zfs /usr/platform/`uname -i`/lib/fs/zfs/bootblk /dev/rdsk/c1t9d0s0 x86# installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c1t9d0s0
先查出目前的 bootpath,再據此推導新碟的裝置路徑(例如尾端由 disk@0:a 變成 disk@2:a),然後在 ok 提示下設定並試開。
# prtconf -vp | grep -i bootpath
bootpath: '/virtual-devices@100/channel-devices@200/disk@0:a'
{0} ok setenv boot-device /virtual-devices@100/channel-devices@200/disk@2:a
{0} ok printenv boot-device
{0} ok boot /virtual-devices@100/channel-devices@200/disk@2:a
新碟容量若大於舊碟,摘除後可用 autoexpand 讓池自動撐到新容量。
# zpool detach rpool c0d0s0 # zpool set autoexpand=on rpool
做到這裡,整顆根池磁碟的換裝就完成了。