实战-raid1更换大硬盘扩容
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
数据大于一切,谨慎操作!
背景需求:
原来2块4T磁盘组成raid1,现需要替换成两块8T磁盘。
思路:
- 安装好磁盘,格式化分区;
- 原raid阵列中退出一块磁盘(作为备份,万一操作失败,数据还在)
- 新磁盘加入到raid阵列中,同步数据;
- 将剩下的4T磁盘也退出raid阵列,调整raid大小到最大;
- 将另一块新磁盘格式化后加入到raid阵列,等待同步完成;
- 重置raid阵列大小到8T;
实施记录
- 查看raid状态
[root@localhost /]# mdadm --detail /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Tue Mar 24 18:13:23 2020
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 15991
Number Major Minor RaidDevice State
3 8 33 0 active sync /dev/sdc1
2 8 17 1 active sync /dev/sdb1
- 关机,插上新磁盘后开机
- 插上第一块新磁盘(8T),分区,格式化
[root@localhost ~]# parted /dev/sdd
GNU Parted 3.2
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
(parted) mkpart
Partition name? []? sdd1
File system type? [ext2]? ext4
Start? 0
End? 8002G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: ATA WDC WD80EFAX-68K (scsi)
Disk /dev/sdd: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 8002GB 8002GB ext4 sdd1
(parted) q
Information: You may need to update /etc/fstab.
# 分区命令或者为mkpart primary 0% 100%
[root@localhost ~]# fdisk -l
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sectors
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: 0xf7cb259a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 234440703 233414656 111.3G 8e Linux LVM
Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F954F1E6-DF93-4CAC-92A4-EF3DE06A0AEF
Device Start End Sectors Size Type
/dev/sdb1 2048 7814035455 7814033408 3.7T Linux filesystem
Disk /dev/sdc: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 4F73F4C1-E3E5-412E-9052-A3B6C3A51E45
Device Start End Sectors Size Type
/dev/sdc1 2048 7814035455 7814033408 3.7T Linux filesystem
Disk /dev/sdd: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9FCCF687-80B1-4DD6-A0BB-287C3B5D6121
Device Start End Sectors Size Type
/dev/sdd1 34 15628053134 15628053101 7.3T Linux filesystem
Partition 1 does not start on physical sector boundary.
Disk /dev/mapper/fedora-root: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/fedora-swap: 3.4 GiB, 3623878656 bytes, 7077888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md127: 3.7 TiB, 4000650887168 bytes, 7813771264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/fedora-home: 57.9 GiB, 62188945408 bytes, 121462784 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# 格式化分区
[root@localhost ~]# mkfs.ext4 /dev/sdd1
mke2fs 1.42.13 (17-May-2015)
/dev/sdd1 alignment is offset by 3072 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Creating filesystem with 1953506637 4k blocks and 244191232 inodes
Filesystem UUID: 435da5fe-4804-4b86-a4f1-fd0ef0d27483
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
- umount md移除其中一块老的4T磁盘sdc
[root@localhost /]# umount /home/work
[root@localhost /]# mdadm --manage /dev/md127 --fail /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md127
[root@localhost /]# mdadm --manage /dev/md127 --remove /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md127
[root@localhost /]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Tue Mar 24 18:19:06 2020
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 15994
Number Major Minor RaidDevice State
0 0 0 0 removed
2 8 17 1 active sync /dev/sdb1
- 关机,拔掉磁盘sdc
- 开机,新磁盘编号变成了sdc(实际在第四个sata口)
[root@localhost ~]# mdadm --manage /dev/md127 --add /dev/sdd1
mdadm: Cannot find /dev/sdd1: No such file or directory
[root@localhost ~]# fdisk -l
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sectors
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: 0xf7cb259a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 234440703 233414656 111.3G 8e Linux LVM
Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F954F1E6-DF93-4CAC-92A4-EF3DE06A0AEF
Device Start End Sectors Size Type
/dev/sdb1 2048 7814035455 7814033408 3.7T Linux filesystem
Disk /dev/sdc: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9FCCF687-80B1-4DD6-A0BB-287C3B5D6121
Device Start End Sectors Size Type
/dev/sdc1 34 15628053134 15628053101 7.3T Linux filesystem
Partition 1 does not start on physical sector boundary.
Disk /dev/mapper/fedora-root: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/fedora-swap: 3.4 GiB, 3623878656 bytes, 7077888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md127: 3.7 TiB, 4000650887168 bytes, 7813771264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/fedora-home: 57.9 GiB, 62188945408 bytes, 121462784 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
- 添加新磁盘(8T)到md,等待同步文件
[root@localhost ~]# mdadm --manage /dev/md127 --add /dev/sdc1
mdadm: added /dev/sdc1
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Tue Mar 24 18:25:55 2020
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Rebuild Status : 0% complete
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 15999
Number Major Minor RaidDevice State
3 8 33 0 spare rebuilding /dev/sdc1
2 8 17 1 active sync /dev/sdb1
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Tue Mar 24 18:25:55 2020
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Rebuild Status : 0% complete
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 15999
Number Major Minor RaidDevice State
3 8 33 0 spare rebuilding /dev/sdc1
2 8 17 1 active sync /dev/sdb1
- 第二天,查看同步完成,移除掉sdb(老的4T磁盘)
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Mar 25 02:25:18 2020
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 21833
Number Major Minor RaidDevice State
3 8 33 0 active sync /dev/sdc1
2 8 17 1 active sync /dev/sdb1
[root@localhost ~]# mdadm --manage /dev/md127 --fail /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md127
[root@localhost ~]# mdadm --manage /dev/md127 --remove /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md127
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 3906885632 (3725.90 GiB 4000.65 GB)
Used Dev Size : 3906885632 (3725.90 GiB 4000.65 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Mar 25 09:47:24 2020
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 21836
Number Major Minor RaidDevice State
3 8 33 0 active sync /dev/sdc1
2 0 0 2 removed
9. 重置raid大小到磁盘最大
```python
[root@localhost ~]# mdadm -G /dev/md127 --size=max
mdadm: component size of /dev/md127 has been set to 7813895478K
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 7813895478 (7451.91 GiB 8001.43 GB)
Used Dev Size : 7813895478 (7451.91 GiB 8001.43 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Mar 25 18:36:35 2020
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 25972
Number Major Minor RaidDevice State
3 8 33 0 active sync /dev/sdc1
2 0 0 2 removed
- 关机,拔掉老磁盘,装上第二块新磁盘(8T)
槽位搞混了没有关系,重要的是每次操作前先检查硬盘和分区
- 查看磁盘信息和md的同步情况
[root@localhost ~]# fdisk -l
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sectors
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: 0xf7cb259a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 234440703 233414656 111.3G 8e Linux LVM
Disk /dev/sdb: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9FCCF687-80B1-4DD6-A0BB-287C3B5D6121
Device Start End Sectors Size Type
/dev/sdb1 34 15628053134 15628053101 7.3T Linux filesystem
Partition 1 does not start on physical sector boundary.
Disk /dev/sdc: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/fedora-root: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/fedora-swap: 3.4 GiB, 3623878656 bytes, 7077888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md127: 7.3 TiB, 8001428969984 bytes, 15627790957 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Alignment offset: 3072 bytes
Disk /dev/mapper/fedora-home: 57.9 GiB, 62188945408 bytes, 121462784 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 7813895478 (7451.91 GiB 8001.43 GB)
Used Dev Size : 7813895478 (7451.91 GiB 8001.43 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Mar 25 18:36:35 2020
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 25972
Number Major Minor RaidDevice State
3 8 17 0 active sync /dev/sdb1
2 0 0 2 removed
- 给第二块8T磁盘分区,格式化
注意后加的磁盘为:/dev/sdc
[root@localhost ~]# parted /dev/sdc
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
(parted) mkpart
Partition name? []? sdc1
File system type? [ext2]? ext4
Start? 0
End? 8002G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: ATA WDC WD80EFAX-68K (scsi)
Disk /dev/sdc: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 8002GB 8002GB ext4 sdc1
(parted) q
Information: You may need to update /etc/fstab.
[root@localhost ~]# mkfs.ext4 /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
/dev/sdc1 alignment is offset by 3072 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Creating filesystem with 1953506637 4k blocks and 244191232 inodes
Filesystem UUID: bb1d6318-260d-4018-a6bf-0be8c6a6b735
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
- 将新的磁盘加入到md127中, 并查看状态
[root@localhost ~]# mdadm --manage /dev/md127 --add /dev/sdc1
mdadm: added /dev/sdc1
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
Version : 1.2
Creation Time : Thu Mar 16 19:04:32 2017
Raid Level : raid1
Array Size : 7813895478 (7451.91 GiB 8001.43 GB)
Used Dev Size : 7813895478 (7451.91 GiB 8001.43 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Mar 25 19:05:29 2020
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Rebuild Status : 0% complete
Name : localhost:1
UUID : 1d6f0f24:e857bcde:776a084b:f3d42cb2
Events : 25980
Number Major Minor RaidDevice State
3 8 17 0 active sync /dev/sdb1
2 8 33 1 spare rebuilding /dev/sdc1
- 等同步完成,最后挂载上硬盘(注意一定要挂载好,以便能自动在线扩容),执行命令,很快就扩容成功
[root@localhost ~]# resize2fs /dev/md127
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/md127 is mounted on /home/work; on-line resizing required
old_desc_blocks = 233, new_desc_blocks = 466
The filesystem on /dev/md127 is now 1953473869 (4k) blocks long.
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 508K 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/fedora-root 50G 39G 12G 78% /
tmpfs 2.0G 4.0K 2.0G 1% /tmp
/dev/sda1 477M 97M 351M 22% /boot
/dev/mapper/fedora-home 58G 44G 15G 76% /home
tmpfs 393M 0 393M 0% /run/user/0
/dev/md127 7.2T 3.5T 3.5T 50% /home/work




A beautiful web dashboard for Linux
最近提交(Master分支:7 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
所有评论(0)