最後更新: 2024-10-23
目錄
- Create disk fault
- Replace Fault Disk
Create disk fault
[方式1]
position=$(cat /dev/urandom | tr -dc 0-9 | head -c 8)
echo $position
dd if=/dev/random of=/home/storage/fault_disk bs=512 count=1 seek=$position
* For simple storage pools, metadata is dual redundant, but data is not redundant.
[方式2]
# 扮斷線
virsh qemu-monitor-command rocky8 --hmp device_del scsi0-0-0-2
# Connect 返
id="drive-scsi0-0-0-2"
virsh qemu-monitor-command rocky8 --hmp drive_add 0 \
file=/mnt/raid/rockylinux/data2.raw,format=raw,if=none,id=$id
block_size="logical_block_size=4096,physical_block_size=4096"
virsh qemu-monitor-command rocky8 --hmp device_add \
scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=2,drive=${id},id=scsi0-0-0-2,${block_size}
virsh qemu-monitor-command rocky8 --hmp info block
Replace Fault Disk
Step1: Find faulted disk
nas: ~ # zpool status
# 沒有 reboot 時
pool: lxc
state: DEGRADED
status: One or more devices are faulted in response to persistent errors.
Sufficient replicas exist for the pool to continue functioning in a
degraded state.
action: Replace the faulted device, or use 'zpool clear' to mark the device
repaired.
config:
NAME STATE READ WRITE CKSUM
lxc DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
sda1 FAULTED 4 117 0 too many errors
sdb1 ONLINE 0 0 0
errors: No known data errors
# reboot 後 (sdb 變成了 sda, 因為 device 沒有 fix name)
config:
NAME STATE READ WRITE CKSUM
lxc DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
3580605110681011631 FAULTED 0 0 0 was /dev/sda1
sda1 ONLINE 0 0 0
* 有半死的 Disk 時別 reboot, 因為 sdb 有機會變成 sda, 之後影響了 pool
[方式1] offline, online
zpool offline lxc sda1
zpool status | grep sda1
sda1 OFFLINE 4 165 0
zpool online lxc sda1
warning: device 'sda1' onlined, but remains in faulted state use 'zpool clear' to restore a faulted device
zpool scrub lxc
zpool clear lxc sda1
zpool status
[方式2] zpool replace
zpool replace lxc sdc1
[方式3] detach & attach
Step1: detach fault disk from pool
zpool detach MyPool /dev/ada3
OR
zpool detach MyPool 9179400675110531610
detach 後
nas: ~ # zpool status
pool: MyPool state: ONLINE scan: resilvered 21.2G in 0h24m with 0 errors on Mon Oct 28 23:54:28 2013 config: NAME STATE READ WRITE CKSUM MyPool ONLINE 0 0 0 ada1 ONLINE 0 0 0 errors: No known data errors
* mirror 不見了
Step2: add disk back to pool
zpool attach MyPool ada1 /dev/ada3 # /dev/ada3 係新 disk
attach 後
nas: ~ # zpool status
pool: MyPool
state: ONLINE
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Mon Oct 28 23:30:06 2013
1.22G scanned out of 21.2G at 10.6M/s, 0h32m to go
1.22G resilvered, 5.77% done
config:
NAME STATE READ WRITE CKSUM
MyPool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada1 ONLINE 0 0 0
ada3 ONLINE 0 0 0 (resilvering)
errors: No known data errors