linux磁盘多块挂载脚本
时间: 2023-11-01 22:00:39 浏览: 130
可以使用以下脚本将多个磁盘块挂载到Linux系统中:
```bash
#!/bin/bash
# Define disk devices and mount points
devices=("sdb" "sdc" "sdd")
mount_points=("/mnt/disk1" "/mnt/disk2" "/mnt/disk3")
# Create mount points if they don't exist
for mount_point in "${mount_points[@]}"; do
if [ ! -d "$mount_point" ]; then
mkdir -p "$mount_point"
fi
done
# Mount disks
for ((i=0; i<${#devices[@]}; i++)); do
device="/dev/${devices[$i]}"
mount_point="${mount_points[$i]}"
# Check if disk is already mounted
if grep -qs "$device" /proc/mounts; then
echo "Disk $device is already mounted"
else
# Mount the disk
mount "$device" "$mount_point"
# Check if mount was successful
if [ $? -eq 0 ]; then
echo "Disk $device mounted at $mount_point"
else
echo "Failed to mount disk $device"
fi
fi
done
```
注意:在脚本中,`devices`数组包含要挂载的磁盘设备名,`mount_points`数组包含对应的挂载点路径。脚本会首先检查挂载点是否存在,如果不存在则创建它们。然后,循环遍历设备和挂载点,检查每个设备是否已经挂载,如果没有挂载则进行挂载操作。
阅读全文