Linux uses mdadm to build and use raid arrays

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

Insert image description here
Insert image description here

Create a file system for the raid and set labels

# -L 标签名称
sudo mkfs.ext4 -L mav-raid0 /dev/md0

Insert image description here

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/

Insert image description here

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

Insert image description here

Configure raid expansion

Check raid disk information

请将 /dev/RAID-DEVICE 替换为 RAID 配置的映射

sudo mdadm --detail /dev/RAID-DEVICE

Insert image description here

Increase disk size

Insert image description here

Unmount

umount /mnt/raid

Insert image description here

Stop RAID device

sudo mdadm --stop /dev/md0

Insert image description here

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 

Insert image description here

Mount file system

# sudo mount -t TYPE /dev/RAID-DEVICE /MOUNT-PATH
sudo mount -t ext4 /dev/md0 /mnt/raid/

Insert image description here

extended file system

xfs

sudo xfs_growfs /dev/RAID-DEVICE

Other file systems such as ext3, ext4

sudo resize2fs /dev/RAID-DEVICE

Insert image description here

Guess you like

Origin blog.csdn.net/fly1574/article/details/135062707