1.挂载硬盘/取消挂载
fdisk -l
mount /dev/sdb1 /mnt/usb
umount /mnt/usb
或者 umount /dev/sdb1
2.设置硬盘自动挂载
blkid /dev/sdl
查看磁盘的uuid,如果查看不到uuid,就对磁盘进行格式化
格式化命令:mkfs.ext4 /dev/sdl
,/dev/sdl为磁盘名
vi /etc/fstab
添加开机自动
格式如下:
批量挂载磁盘脚本:
#!/bin/sh
#backup /etc/fstab
cp /etc/fstab /etc/fstab.bak
PARTITION_LIST="sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl"
cnt=0
for PARTITION in $PARTITION_LIST
do
cnt=$(($cnt+1));
UUID=`blkid "/dev/""$PARTITION" | awk '{print $2}' | sed 's/\"//g'`
echo $UUID
echo "add $PARTITION to /etc/fstab"
MOUNTDIR="/mnt/disk"$cnt
echo "mkdir -p $MOUNTDIR"
mkdir -p $MOUNTDIR
echo "appending \"$UUID $MOUNTDIR ext4 defaults 0 0\" to /etc/fstab "
echo "$UUID $MOUNTDIR ext4 defaults 0 0" >> /etc/fstab
echo ""
done
#mount all partitions
mount -a
#show mounted partitions
df -h
网友评论