Linux解除软Raid

#!/bin/sh

# 假设要解除的软raid 是  /dev/md0


# 卸载  /dev/md0
umount  /dev/md0


# 抹掉软raid信息,停软raid,多次执行,确保抹除
mdadm -S /dev/md0
mdadm -S /dev/md0
mdadm -S /dev/md0
mdadm -S /dev/md0
mdadm -S /dev/md0


# 逐盘重新分区
disk_arr=(/dev/nvme0n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1)
for device in ${disk_arr[@]}
do
/sbin/fdisk $device 2>&1 << EOF
d
n
p
1
1
36481
t
fd
p
w
EOF
done


# 再次操作抹掉软raid信息,停软raid,多次执行,确保抹除
mdadm -S /dev/md0
mdadm -S /dev/md0
mdadm -S /dev/md0


# 格盘
for disk in {0..3}
do
     echo mkfs.ext4 /dev/nvme${disk}n1;
     mkfs.ext4 /dev/nvme${disk}n1 > /dev/null 2>&1
done


# 盘信息写入 /etc/fstab
echo "/dev/nvme0n1          /data1           ext4       noatime,acl,user_xattr  1  2
/dev/nvme1n1          /data2           ext4       noatime,acl,user_xattr  1  2
/dev/nvme2n1          /data3           ext4       noatime,acl,user_xattr  1  2
/dev/nvme3n1          /data4           ext4       noatime,acl,user_xattr  1  2" >> /etc/fstab


# 建挂载目录
for i in `seq 1 4`;
do
        mkdir   /data${i}
done


# 挂载
mount -a


# 查看挂载后效果
df -h

你可能感兴趣的:(Linux系统管理)