老版本的红旗的automount脚本,也发上来让大家分析:
包括两部分,一个是/etc/rc.d/init.d/WinAutoMnt:
[code:1]
#!/bin/sh
#
# WinAutoMnt mount the windows partitions automatically
#
# chkconfig: 345 17 05
# description: mount the windows partitions automatically
# source function library
. /etc/rc.d/init.d/functions
WINAUTOMNTCMD=/sbin/WinAutoMnt.sh
UNMOUNTCMD=/bin/umount
if [ ! -x $UNMOUNTCMD -a -x /sbin/umount ]; then
UNMOUNTCMD=/sbin/umount
fi
if [ -x $WINAUTOMNTCMD ]; then
case "$1" in
start)
# mount the windows partitions automatically
rmdir /mnt/win_*
rm -f /root/win_*
/bin/sh $WINAUTOMNTCMD >/dev/null 2>&1
;;
stop)
if [ -x $UNMOUNTCMD ]; then
$UNMOUNTCMD /mnt/win_* >/dev/null 2>&1
else
umount /mnt/win_* >/dev/null 2>&1
fi
# delete all the win mount points
rmdir /mnt/win_*
rm -f /root/win_*
;;
restart|reload)
/bin/sh $0 stop
/bin/sh $0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
fi
[/code:1]
另一个是/sbin/WinAutoMnt.sh
[code:1]
#!/bin/sh
# mount path : mount in /bin/mount, /usr/bin/mount
if [ -x /bin/mount ]
then
MOUNT=/bin/mount
elif [ -x /usr/bin/mount ]
then
MOUNT=/usr/bin/mount
fi
if [ ! -x $MOUNT ]
then
echo "mount command cann't be found, exit here!"
exit 1
fi
# mount parameters
# fdisk path
if [ -x /sbin/fdisk ]
then
FDISK=/sbin/fdisk
elif [ -x /usr/sbin/fdisk ]
then
FDISK=/usr/sbin/fdisk
fi
if [ ! -x $FDISK ]
then
echo "fdisk command cann't be found, exit here!"
exit 1
fi
# if this have been done, exit with 1
if [ -d /mnt/win_C ]; then
if [ `ls /mnt/win_C | wc | awk '{printf $1}'` != "0" ] ; then
echo "windows partitions have been mounted!"
exit 1
fi
fi
# delete all the mounted points here
rmdir /mnt/win_* >/dev/null 2>&1
# mount location
MntLoc[0]=C ; MntLoc[1]=D ; MntLoc[2]=E ; MntLoc[3]=F ;
MntLoc[4]=G ; MntLoc[5]=H ; MntLoc[6]=I ; MntLoc[7]=J ;
MntLoc[8]=K ; MntLoc[9]=L ; MntLoc[10]=M ; MntLoc[11]=N ;
MntLoc[12]=O ; MntLoc[13]=P ; MntLoc[14]=Q ; MntLoc[15]=R ;
MntLoc[16]=S ; MntLoc[17]=T ; MntLoc[18]=U ; MntLoc[19]=V ;
MntLoc[20]=W ; MntLoc[21]=X ; MntLoc[22]=Y ; MntLoc[23]=Z ;
# get all the hard disk partitions we need to think over:
# ntfs, fat16, fat32 etc
# get all the partitions first, then filter out the informations
# about comments. The next thing is to get all the
# NTFS, FAT16, FAT32, and Extended.
# Extended Key word for dividing Primary and Extended partitions.
# delete the * , which mark the bootable partitions
# get only the partitions and partitions mark.
# get all the harddisk in /dev/hd?
PARTITIONS="" # partitions string
if [ ! -x /bin/dmesg ]; then
echo "/bin/dmesg is not exit!"
exit 1
fi
for HDDEV in `/bin/dmesg | grep "^hd.*DISK drive" | awk -F: '{print $1}'`
do # do for every hard disk devices
# until the last available one
# get the NTFS, FAT16, FAT32, and Extended
# delete things between /dev/hda? and FAT32
PARTITIONONE=`$FDISK -l /dev/$HDDEV 2>/dev/null | \
grep ^\/dev | \
sed 's/\*/ /g' | \
grep -i "['FAT'|'NTFS']" | \
sed 's/ (LBA)$//g' | sed 's/ .* / /g' `
if [ "${PARTITIONONE}" = "" ]; then
break
fi
# for the logical partitions in windows
# the Primary state before the logical one
# so we need to do something mark the Primary
# one
# we know the non-primary partitions is after
# the Extended one
# so here mark the primary one with BEFOREXTENDED
BFEX=1 # BFEX = 1 means before Extended partitions,
# BFEX = 0 means after Extended partitions,
for LOGICALPART in $PARTITIONONE
do
if [ "$LOGICALPART" = "Extended" ]
then
BFEX=0
fi
if [ $BFEX -eq 1 ]
then
MODIFYPARTITIONS="$MODIFYPARTITIONS BEFOREXTENDED$LOGICALPART "
else
MODIFYPARTITIONS="$MODIFYPARTITIONS $LOGICALPART"
fi
PARTITIONS="$PARTITIONS $MODIFYPARTITIONS"
MODIFYPARTITIONS=""
done # end for one devcice
done # end for all available hard disk devices
# $PARTITIONS store all the informations about the
# partitions name and its type(NTFS, FAT.., Extended,etc)
#echo $PARTITIONS
# deal with the PARTITIONS, sort it in the following orders, ex.:
# /dev/hda1 primaryone
# /dev/hda2 primaryone
# /dev/hdb1 primaryone
# /dev/hdb2 primaryone
# /dev/hda4 extended one
# /dev/hda5 extended one
# /dev/hdb4 extended one
{
{ STEP=0
for ParaOne in $PARTITIONS
do
echo -e -n "$ParaOne "
STEP=`expr $STEP + 1`
STEP=`expr $STEP % 2`
if [ $STEP -eq 0 ]
then
echo ""
fi
done
} | \
sort | sed -e '/Extended $/d' -e 's/BEFOREXTENDED//g'
} | \
{
WINPARTSTEP=0
while read PartitionName PartitionType
do
# mount location is located at /mnt/..., named from C, D,...
# if the mount location doesn't exist, make it with mkdir
MOUNTLOCATITION=/mnt/win_${MntLoc[$WINPARTSTEP]}
if [ ! -d $MOUNTLOCATITION ]
then
mkdir -p $MOUNTLOCATITION
ln -sf $MOUNTLOCATITION /root/win_${MntLoc[$WINPARTSTEP]}
fi
echo $PartitionName $PartitionType
echo $MOUNTLOCATITION
# mount partition according to the PartitionType
WINPARTSTEP=`expr $WINPARTSTEP + 1`
MountType=""
case $PartitionType in
FAT16) MountType=vfat
MNTFLAGS="-o rw"
;;
FAT32) MountType=vfat
MNTFLAGS="-o rw"
;;
HPFS/NTFS) MountType=ntfs
MNTFLAGS="-o ro,iocharset=cp936"
;;
esac
if [ "$MountType" != "" ]
then
$MOUNT $MNTFLAGS -t $MountType $PartitionName $MOUNTLOCATITION >/dev/null 2>&1
if [ $? != 0 ]; then
echo -e "\tERROR in mount $PartitionName at $MOUNTLOCATITION, fs: $MountType"
rmdir $MOUNTLOCATITION
WINPARTSTEP=`expr $WINPARTSTEP - 1`
else
echo "mount $PartitionName Readonly at $MOUNTLOCATITION, fs: $MountType";
fi
fi
done
}
[/code:1]