This article uses raid0 as an example to describe how to use mdadm to create a raid0 array and expand it later.
configuration list
name | Configuration | Remark |
---|---|---|
operating system | ubuntu 22.04 | |
Disk-1 | 10GB | /dev/xvdf |
Disk-2 | 10GB | /dev/xvdg |
Build raid0
Create raid0
sudo yum install mdadm
# --level=0 选项用于将阵列条带化
sudo mdadm --create --verbose /dev/md0 --level=0 --name=RAID0 --raid-devices=2 /dev/xvdf /dev/xvdg
# 查看md0情况
mdadm --detail /dev/md0
Create a file system for the raid and set labels
# -L 标签名称
sudo mkfs.ext4 -L mav-raid0 /dev/md0
Configuration file containing RAID information
To ensure that the RAID array is automatically reorganized on boot, create a configuration file containing the RAID information
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
Create a new Ramdisk Image to properly preload the block storage device modules for the new RAID configuration
sudo dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
Create a mounting directory and mount it
mkdir /mnt/raid
mount LABEL=mav-raid0 /mnt/raid/
Add to fstab boot mount (optional)
sudo cp /etc/fstab /etc/fstab.orig
echo "LABEL=mav-raid0 /mnt/raid ext4 defaults,nofail 0 2" >> /etc/fstab
# mount -a 若无输出,即为正常
mount -a
Configure raid expansion
Check raid disk information
请将 /dev/RAID-DEVICE 替换为 RAID 配置的映射
sudo mdadm --detail /dev/RAID-DEVICE
Increase disk size
Unmount
umount /mnt/raid
Stop RAID device
sudo mdadm --stop /dev/md0
Integrating and reassembling volumes with updated sizes
# sudo mdadm --assemble --update=devicesize /dev/RAID-DEVICE LIST-OF-DEVICES
# 请将 RAID-DEVICE 替换为 RAID 配置的映射。请将 LIST-OF-DEVICES 替换为 EBS 卷的设备名称,例如
sudo mdadm --assemble --update=devicesize /dev/md0 /dev/xvdf /dev/xvdg
mdadm --detail /dev/md0
Mount file system
# sudo mount -t TYPE /dev/RAID-DEVICE /MOUNT-PATH
sudo mount -t ext4 /dev/md0 /mnt/raid/
extended file system
xfs
sudo xfs_growfs /dev/RAID-DEVICE
Other file systems such as ext3, ext4
sudo resize2fs /dev/RAID-DEVICE