ZFS Pool 里增加硬盘做镜像

ZFS 第一次出现在 OpenSolaris 上是在2005年11月发布的 build 27 版本,因为稳定性、可靠性等原因直到最近 VPSee 才有考虑把它用在生产环境里,现在 VPSee 所有的 Solaris 服务器还是在用很古老的 UFS,UFS 仍是 Solaris 10 的默认文件系统。昨天简单玩了一下 ZFS,用6个文件模拟6个硬盘在 ZFS 上进行了一系列添加、删除、镜像的操作,立刻体会到了 ZFS 的强大,但这与实际操作物理硬盘还是有点差别。VPSee 当时安装 OpenSolaris 的时候只用了一块 250GB 的硬盘,现在可以增加一块 250GB 的硬盘做镜像,试验一下 ZFS 强大的 mirror,相当于做 RAID1.

检查 pool

要在服务器上增加一块实际硬盘,先要看看系统原来的 pool 有什么:

# zpool status
  pool: rpool
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        rpool       ONLINE       0     0     0
          c8t0d0s0  ONLINE       0     0     0

errors: No known data errors

上面显示 c8t0d0s0 是里面唯一的一块硬盘。现在插上一块新硬盘后(必要时需要重启)运行 format 工具:

# format
Searching for disks...

The device does not support mode page 3 or page 4,
or the reported geometry info is invalid.
WARNING: Disk geometry is based on capacity data.

The current rpm value 0 is invalid, adjusting it to 3600
done

c8t1d0: configured with capacity of 232.87GB


AVAILABLE DISK SELECTIONS:
       0. c8t0d0 
          /pci@0,0/pci108e,534c@5/disk@0,0
       1. c8t1d0 
          /pci@0,0/pci108e,534c@5/disk@1,0
Specify disk (enter its number):

按 “Ctrl + C” 退出。c8t0d0 是原来的硬盘,c8t1d0 是后来加上去的新硬盘。

分区和 label

现在用 -e 参数再次运行 format,然后选择 partition,创建一个 Solaris 分区后打印出分区表看看,只有 s0, s2, s8 有内容。完成分区后退到 format 菜单,接着选择 label,因为大多数的 PC BIOS 都不支持 EFI labels,所以要选择 SMI:

# format -e c8t1d0

format> partition
SELECT ONE OF THE FOLLOWING:
   1. Create a 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
  1 unassigned    wu       0                0         (0/0/0)             0
  2     backup    wu       0 - 30396      232.85GB    (30397/0/0) 488327805
  3 unassigned    wu       0                0         (0/0/0)             0
  4 unassigned    wu       0                0         (0/0/0)             0
  5 unassigned    wu       0                0         (0/0/0)             0
  6 unassigned    wu       0                0         (0/0/0)             0
  7 unassigned    wu       0                0         (0/0/0)             0
  8       boot    wu       0 -     0        7.84MB    (1/0/0)         16065
  9 unassigned    wu       0                0         (0/0/0)             0
partition>quit

format> label
[0] SMI Label
[1] EFI Label
Specify Label type[0]: 0
Ready to label disk, continue? y

做镜像

退出 format,在 rpool 里增加新硬盘作为第1一块硬盘 mirror,会出现以下报错:

# zpool attach -f rpool c8t0d0 c8t1d0
cannot label 'c8t1d0': EFI labeled devices are not supported on root pools.

我们必须把 VTOC 从第1块硬盘拷贝到第2块硬盘,注意这里 s2 是 slice(分区),c8t0d0s2 是 c8t0d0 的 s2 分区,注意上面打印的分区显示 s2 代表整个硬盘,看 Blocks 发现 s2 = s0 + s8,s0 是 root 分区,s8 是 boot 分区:

# prtvtoc /dev/rdsk/c8t0d0s2 | fmthard -s - /dev/rdsk/c8t1d0s2 
fmthard: Partition 2 specifies the full disk and is not equal
full size of disk.  The full disk capacity is 488343870 sectors.
fmthard:  New volume table of contents now in place.

新硬盘的 c8t1d0s0 分区做成 c8t0d0s0 的镜像,注意上面打印的分区显示 s0 是 root 分区,有 232.85GB 空间,也是我们想 mirror 的分区:

# zpool attach -f rpool c8t0d0s0 c8t1d0s0
Please be sure to invoke installgrub(1M) to make 'c8t1d0s0' bootable.

安装 grub

这一步非常重要,需要把 grub 安装在第二块硬盘上:

# installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c8t1d0s0 
Updating master boot sector destroys existing boot managers (if any).
continue (y/n)?y

校验 pool

校验 pool 后查看校验后状态:

# zpool scrub rpool

# zpool status
  pool: rpool
 state: ONLINE
 scrub: scrub in progress for 0h0m, 0.95% done, 0h26m to go
config:

        NAME        STATE     READ WRITE CKSUM
        rpool       ONLINE       0     0     0
          c8t0d0s0  ONLINE       0     0     0
          c8t1d0s0  ONLINE       0     0     0

errors: No known data errors

发表评论