Ubuntu 24.04设置软raid 1
先要建立分区,分区类型为
fd
,Linux raid autodetect
。不做这步后面会无法开机自动启动软件raidsudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.39.3). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS (MBR) disklabel with disk identifier 0xfab081e6. Command (m for help): o Created a new DOS (MBR) disklabel with disk identifier 0xc3896bcc. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): Created a new partition 1 of type 'Linux' and of size 20 GiB. Command (m for help): t Selected partition 1 Hex code or alias (type L to list all): fd Changed type of partition 'Linux' to 'Linux raid autodetect'. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
安装
mdadm
软raid
工具sudo apt install mdadm
创建磁盘阵列
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
查看同步状态,完成同步后可以进行后续步骤
cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdc[1] sdb[0]
976630464 blocks super 1.2 [2/2] [UU]
[>....................] resync = 0.2% (2607936/976630464) finish=80.9min speed=200610K/sec
bitmap: 8/8 pages [32KB], 65536KB chunk
unused devices: <none>
格式化磁盘阵列
sudo mkfs.ext4 /dev/md0
挂载到目录
sudo mkdir /data sudo mount /dev/md0 /data
将配置写入到文件设置开机生效
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf sudo update-initramfs -u
- 如果想要开机自动挂载还需要把配置写进
fstab
检查软raid
的方法
sudo mdadm --detail /dev/md0
删除raid的步骤
如果不需要软raid了,其删除步骤如下
卸载磁盘分区
sudo umount /dev/md0
停止
raid
设备sudo mdadm --stop /dev/md0
删除
raid
的配置文件并更新initramfs
# delete # ARRAY /dev/md0 metadata=1.2 UUID=XXXXXXXXXXXXX sudo update-initramfs -u
删除
raid
的元信息sudo mdadm --zero-superblock /dev/sdb sudo mdadm --zero-superblock /dev/sdc
参考链接:
https://developer.aliyun.com/article/1353755
https://blog.csdn.net/qq_44673299/article/details/113771436
https://www.digitalocean.com/community/tutorials/how-to-create-raid-arrays-with-mdadm-on-ubuntu
https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_041_raid.html
感谢扫码支持