Linux下RAID5增加磁盘来增加容量

前情回顾

之前使用3块500G硬盘组了一个软RAID5,实际可用容量也就1T。现在有一块相同的硬盘闲置了,想增加进去,把容量扩到1.5T。

步骤

查看挂载设备

$ df -h
Filesystem     Size  Used Avail Use% Mounted on
...
/dev/md5       931G  93G  838G 10%  /data
...

我这边的设备是/dev/md5,挂载在/data上。

查看md设备的状态:

$ cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid1] [raid10]
md5 : active raid5 sdd1[1] sda1[0] sdc1[3]
      976506880 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      bitmap: 1/4 pages [4KB], 65536KB chunk

unused devices: <none>

[UUU]确定RAID5的状态正常,也没有其他异常信息。

查看md设备的详细信息:

sudo mdadm --detail /dev/md5

准备新磁盘

需要把新的磁盘处理成已经组成RAID5的磁盘的相同格式。
我这边之前是使用了一个分区,所以新磁盘也分一个分区。

$ sudo fdisk /dev/sdb
$ sudo fdisk -l
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: ***
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x********

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 976773167 976771120 465.8G fd Linux raid autodetect


Disk /dev/sdd: 465.76 GiB, 500107862016 bytes, 976773168 sectors
...
Device     Boot Start       End   Sectors   Size Id Type
/dev/sdd1        2048 976773167 976771120 465.8G fd Linux raid autodetect


Disk /dev/sdb: 465.76 GiB, 500107862016 bytes, 976773168 sectors
...
Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1        2048 976773167 976771120 465.8G fd Linux raid autodetect


Disk /dev/sdc: 465.76 GiB, 500107862016 bytes, 976773168 sectors
...
Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1        2048 976773167 976771120 465.8G fd Linux raid autodetect


Disk /dev/md5: 931.27 GiB, 999943045120 bytes, 1953013760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes

添加新磁盘

sudo mdadm --manage /dev/md5 --add /dev/sdb1

查看md设备的状态:

Personalities : [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid1] [raid10]
md5 : active raid5 sdb1[4](S) sdd1[1] sda1[0] sdc1[3]
      976506880 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      bitmap: 1/4 pages [4KB], 65536KB chunk

unused devices: <none>

扩容RAID5

sudo mdadm --grow /dev/md5 --raid-devices=4

这边我原先是3块硬盘,现在加了一块,所以--raid-devices=4。 此时再看一下md设备的状态:

$ cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid1] [raid10]
md5 : active raid5 sdb1[4] sdd1[1] sda1[0] sdc1[3]
      976506880 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
      [>....................]  reshape =  0.0% (330684/488253440) finish=49.1min speed=165342K/sec
      bitmap: 1/4 pages [4KB], 65536KB chunk

unused devices: <none>

再次查看md设备的详细信息:

$ sudo mdadm --detail /dev/md5
/dev/md5:
           Version : 1.2
     Creation Time : Wed Sep 30 23:18:18 2020
        Raid Level : raid5
        Array Size : 976506880 (931.27 GiB 999.94 GB)
     Used Dev Size : 488253440 (465.63 GiB 499.97 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Wed Dec  4 19:50:26 2024
             State : active, reshaping
    Active Devices : 4
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : bitmap

    Reshape Status : 0% complete
     Delta Devices : 1, (3->4)

              Name : ***
              UUID : ***
            Events : 1828986

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       49        1      active sync   /dev/sdd1
       3       8       33        2      active sync   /dev/sdc1
       4       8       17        3      active sync   /dev/sdb1

reshape需要很长的时间,期间就慢慢等吧,尽量不要去打断它。完成后,调整整列容量

sudo mdadm --grow /dev/md5 --size=max

之后可以看到,整列容量已经变了

$ sudo fdisk -l /dev/md5
Disk /dev/md5: 1.36 TiB, 1499914567680 bytes, 2929520640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 1572864 bytes

扩容文件系统

到此块设备已经扩容完成,但是块设备之上的文件系统还没有扩容,所有从挂载的容量看是还没有变的。
需要对文件系统进行扩容,不同的文件系统用不同的命令。 如果是ext2/ext3/ext4文件系统

sudo resize2fs /dev/md5

我这边是xfs文件系统,故使用

sudo xfs_growfs /dev/md5

完成后重新查看挂载的文件系统大小,已经变了

$ df -h
Filesystem     Size  Used Avail Use% Mounted on
...
/dev/md5        1.4T  114G  1.3T    9% /data
...

最后修改于 2024-12-09