Tag Archives: snapraid

给SnapRAID替换硬盘

之前在我的乞丐版NAS及配置这篇文章中介绍了NAS的配置。
正常工作近5年之后,其中一块硬盘开始报了SMART Error。

SMART Error

一开始的SMART Error是这样:

# SMART error (CurrentPendingSector) detected on host
Device: /dev/sde [SAT], 1 Currently unreadable (pending) sectors

稳定了几天之后,pending sectors变为了这样:

Device: /dev/sde [SAT], 41 Currently unreadable (pending) sectors

看到unreadable sector明显增加了。

看一下snapraid smart的输出

$ sudo snapraid smart
SnapRAID SMART report:

   Temp  Power   Error   FP Size
      C OnDays   Count        TB  Serial           Device    Disk
 -----------------------------------------------------------------------
     32   1750       0   5%  6.0  WD-WX31D88R41HT  /dev/sdb  d1
     35   1749 selferr 100%  6.0  WD-WX31D88AEC9Z  /dev/sde  d2
     33   1749       0   4%  6.0  WD-WX31D88AERKL  /dev/sdd  parity

d2这块盘的寿命快到了。

替换硬盘

在SnapRAID中替换硬盘的步骤不复杂,记录一下。

  1. 停止所有会写数据的服务,比如把日常的docker容器都停了

    docker stop $(docker ps -a -q)
  2. 确保数据正确,如果有,sync一下

    $ sudo snapraid diff # 看下有没有数据不一致
    Loading state from /var/snapraid/snapraid.content...
    Comparing...
    ...
    6 removed
    18 updated
    There are differences!
    
    # 有不一致,跑一下sync
    $ sudo snapraid sync
    ...
    Everything OK
    ...
    Verifying...
    Verified /mnt/data/disk2/snapraid.content in 0 seconds
    Verified /var/snapraid/snapraid.content in 0 seconds
    Verified /mnt/data/disk1/snapraid.content in 0 seconds
    
    # 再次确保数据一致
    $ sudo snapraid diff
    Loading state from /var/snapraid/snapraid.content...
    Comparing...
    ...
    No differences
  3. 给新硬盘创建分区,并格式化。使用之前文章中相同的方式。

    $ sudo parted -a optimal /dev/sdc
    ...
    $ sudo mkfs.ext4 -m 2 -T largefile4 /dev/sdc1
  4. 从旧硬盘拷数据。这一步花了好几个小时…

    # 新硬盘临时mount在 /mnt/tmp
    sudo mount -t auto /dev/sdc1 /mnt/tmp
    # 拷贝旧硬盘数据
    cp -av /mnt/data/disk2/. /mnt/tmp
  5. 重新mount文件系统

    # umount mergerfs
    $ sudo umount /mnt/storage
    
    # umount 旧硬盘
    $ sudo umount /mnt/data/disk2
    
    # 修改/etc/fstab,使用新硬盘,mount到原始位置
    /dev/disk/by-id/ata-XXXXXXXXXXX-part1 /mnt/data/disk2 ext4 defaults 0 2
    
    # 重新mount
    sudo mount /mnt/data/disk2/
  6. 使用snapraid确认数据,可以注意到snapraid发现d2这块硬盘的uuid变了。
    snapraid check这一步也要花好几个小时(胆大的也可以跳过)

    $ sudo snapraid diff
    Loading state from /var/snapraid/snapraid.content...
    UUID change for disk 'd2' from 'dd5c3760-1e4e-4d72-b710-56c782f416c3' to '55a67bea-3ca1-4cbe-b9ed-83ca9825d627'
    Comparing...
    WARNING! UUID is changed for disks: 'd2'. Not using inodes to detect move operations.
    No differences
    
    # 检查数据一致性
    $ sudo snapraid check -a -d d2
    Self test...
    Loading state from /var/snapraid/snapraid.content...
    UUID change for disk 'd2' from 'dd5c3760-1e4e-4d72-b710-56c782f416c3' to '55a67bea-3ca1-4cbe-b9ed-83ca9825d627'
    Selecting...
    Using 1235 MiB of memory for the file-system.
    Initializing...
    Selecting...
    Hashing...
    8%, 191365 MB, 123 MB/s, 524 stripe/s, CPU 0%, 4:22 ETA TA
  7. 最后一步,sync一下

    $ sudo snapraid sync

到这里,snapraid相关的事情就完成了。

其它

相比之前文章里的aufs,后来在ubuntu不再支持aufs的情况下,改用mergerfs了,性能也还行。

我的配置如下

/mnt/data/* /mnt/storage fuse.mergerfs defaults,allow_other,use_ino,cache.files=partial,dropcacheonclose=true,category.create=mfs,minfreespace=20G,fsname=mergerfs 0 0

最后把旧硬盘拔掉,重新mount /mnt/storage目录,全部工作搞定。

Share