#!/bin/bash
read -p "Enter drive letter:" name
if [ -b "$name" ]
then
mkdir /opt/qfusion >/dev/null 2>&1
mkfs.xfs -f $name
blkid|grep $name |awk '{print $2}'
echo "$(blkid|grep $name |awk '{print $2}') /opt/qfusion xfs defaults 0 0 " >>/etc/fstab
mount -a
#echo "mount $(blkid|grep $name |awk '{print $2}') /opt/qfusion" >> /etc/rc.d/rc.local
#chmod +x /etc/rc.d/rc.local
#systemctl start rc-local.service
else
echo "Drive letter does not exist"
fi
#!/bin/bash
# 获取所有NVMe盘的设备名
nvme_devices=$(lsblk |grep nvme|awk '{print$1}')
# 挂载所有NVMe盘
for device in ${nvme_devices}
do
echo "-----------------------------------"
echo "start to mount nvme named ${device}"
echo "-----------------------------------"
# 判断这块nvme盘是否已经挂载
if [ -z $(lsblk |grep ${device} |awk '{print $7}') ];then
# NVMe格式化
mkfs.xfs -f /dev/${device}
else
echo "Error: The ${device} has been mounted by $(lsblk |grep ${device} |awk '{print $7}')"
continue
fi
# 获取设备的UUID
uuid=$(blkid -o value -s UUID /dev/${device})
if [ -z "${uuid}" ]; then
echo "Error: Failed to get UUID for ${device}"
continue
fi
# 指定挂载点,创建挂载点目录
read -p "please input mount_point: " mount_point
if [ ! -d "${mount_point}" ]; then
mkdir -p ${mount_point}
fi
# 挂载设备
mount -U ${uuid} ${mount_point}
if [ $? -ne 0 ]; then
echo "Error: Failed to mount ${device} with UUID ${uuid}"
else
echo "Success: Mounted ${device} with UUID ${uuid} at ${mount_point}"
fi
# 将挂载信息写入/etc/fstab文件,实现开机自动挂载
echo "UUID=${uuid} ${mount_point} xfs defaults 0 0" >> /etc/fstab
done