大网数据广告活动
服务器运维问答

Problems with auto-mounting MDADM-created RAID array and creating RAID device

· 52CE 我爱测

I'm working on a script that automatically detects new drives that have been added so they can be formatted and turned into a RAID-5 array. I've been able to detect the drives and format them with little trouble, but am having is…

问题原文

原帖链接 · Darin Beaudreau · CC BY-SA 4.0

I'm working on a script that automatically detects new drives that have been added so they can be formatted and turned into a RAID-5 array. I've been able to detect the drives and format them with little trouble, but am having issues with creating (and later destroying) the RAID device.

Once detected and formatted, I pass the detected drives to the following commands like so:

mdadm --create ${RAID_DEVICE} --level=5 --raid-devices=${COUNT} ${DEVICES}
mkfs.ext4 ${RAID_DEVICE}
mdadm --detail --scan >> /etc/mdadm.conf

UUID=$(cat /etc/mdadm.conf | grep ${RAID_DEVICE} | awk '{print $6}')
UUID=$(echo ${UUID:5})

echo "UUID=${UUID} ${MOUNT_LOCATION} ext4 defaults 0 0" >> /etc/fstab

mount -a

Now, for testing purposes, because I don't currently have the SATA drives I will be using for this project yet, I've set it to detect USB devices specifically, and am using 3 USB devices. The script correctly identifies the UUID of the device from mdadm.conf, but when running mount -a from the script, it says that the UUID is not recognized as a device. However, when I replace the UUID with ${RAID_DEVICE}, usually /dev/md0, it can correctly mount the device.

Also, the install script (after testing the script several times and manually deconstructing and uninstalling the RAID device), says that the USB devices are already part of a RAID device. I manually tried to undo the device between tests by running the following commands:

umount ${MOUNT_LOCATION}
mdadm ${RAID_DEVICE} --fail ${DEVICES}
mdadm ${RAID_DEVICE} --remove ${DEVICES}
mdadm --stop ${RAID_DEVICE}
mdadm --zero-superblock ${DEVICES}

However, when recreating the RAID device, it seems to still see the devices as part of the md0 RAID device. Did I miss a step? Trying to call --remove on /dev/md0 after stopping it results in it saying there's no such directory.

So why does the UUID not work correctly as an identifier for the RAID device? And why can I not seem to properly remove the RAID information from the drives afterwards? Does it have anything to do with them being USB devices?

I appreciate any guidance towards the proper usage of the mdadm tool.

已采纳解答

原帖链接 · Mike Andrews · CC BY-SA 4.0

The UUID that you want to put in fstab is not the UUID of the array, but the UUID of the filesystem you created on the array. You can use the blkid utility to find its value. If you've got the same udev rules I have, you may find that there's an entry in /dev/disk/by-id that you can indirect through using the array's uuid, like:

$ sudo blkid /dev/disk/by-id/md-uuid-${UUID}
/dev/disk/by-id/md-uuid-c6a65df0:6df343e6:bd3d6cfc:1349c37c: UUID="901e8907-8f74-4300-8410-654a9410b236" TYPE="xfs"

Otherwise, you can just run blkid ${RAID_DEVICE}.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。