为了方便的管理系统分区,在/mnt目录下创建挂载点并自动挂载分区,自动更新/etc/fstab文件
#自动挂载所有windows分区的脚本
# !/bin/bash
#查找系统中所有的fat和ntfs 分区,并把分区保存到/tmp/temp$$.log文件中
fdisk -l |awk '$1~/\dev/&&$NF~/FAT/ | | $NF ~ /NTFS/{PRINT $1;}'>/tmp/temp$
$.log
#备份fstab文件
if [ ! -f /etc/fstab.bak ]; then
cp /etc/fstab /etc/fstab.bak
fi
#对/etc/fstab和/tmp/temp$$.log两个文件进行比较,并把结果保存到/tmp /temp${$}$.log
文件中
awk 'NR==FNR{a [$1]=$1}NR>FNR{if ($1 !=a[$1] )print $0 ; }' /tmp/temp$$.log
/etc/fstab > /tmp/temp${$}$.log
#生成windows分区的自动开机挂载记录
awk
' { split($1 ,dir, "/") ;printf ("%s\t\t/mnt/%s\t\tauto
\tiocharset=cp936,umask=0,exec,sync 0 0\n", $1 ,dir [3])}' /tmp/temp$$.log>>
/tmp/temp$$.log
#替换fstab文件
mv -f /tmp/temp${$}$.log /etc/fstab
#创建分区挂载点
awk -F [/] '{print "/mnt/" $3;}' /tmp/temp$$.log | xargs mkdir 2 > /dev/null
rm -f /tmp/temp$$.log
#挂载所有分区
mount -a
#判断运行结果
if [ $? -eq 0 ]; then
echo "All windows Partitions are mounted iinto the /mnt !";
else
echo "Not all of the windows Partitions are mounted into the /mnt !" ;
fi
#把上述代码保存为automount.sh ,并且需要为脚本添加执行权限
#脚本运行方式如下:
# ./automount.sh
#