自动检测并加载分区脚本
KanKer
|
1#
KanKer 发表于 2004-09-18 22:58
自动检测并加载分区脚本
受linuxsir上哈蜜瓜的启发,重新写了一个自动加载分区的脚本,条件所限,对scsi的检测还不太完善,请大家修正:
1、将下面脚本保存为/usr/sbin/fstype: [code:1]#!/bin/sh #节选自哈蜜瓜写的自动加载分区脚本。 FILE="$(LANG=C LC_ALL=C LC_MESSAGES=C file -Lkbs "$1")" if [ "$FILE" = "data" ]; then # could still be ReiserFS, since "file" only reads 64k in Debian FILE="$(dd if="$1" skip=16397 ibs=4 count=2 2>/dev/null)" fi case "$FILE" in *[Rr][Ee][Ii][Ss][Ee][Rr]*) echo "reiserfs";; # *ISO\ 9660*) echo "iso9660";; *[Mm][Ii][Nn][Ii][Xx]*) echo "minix";; *[Xx][Ff][Ss]*) echo "xfs";; *[Jj][Ff][Ss]*) echo "jfs";; *[Ee][Xx][Tt]3*) echo "ext3";; *[Ee][Xx][Tt]2*) echo "ext2";; # *[Ss][Ww][Aa][Pp]*) echo "swap";; *[Nn][Tt][Ff][Ss]*) echo "ntfs";; *[Ff][Aa][Tt]*) echo "vfat";; # *) echo "auto";; esac [/code:1] 2、将下面脚本放到/etc/rc.d/rc.local里(用ML1.2pre6以后系统的朋友可加在/etc/rc.d/rc.magic里),以便每次开机自动运行: --------------------------------------------------- [code:1] #自动检测加载分区 if [ -f /etc/profile.d/lang.sh ]; then . /etc/profile.d/lang.sh case $LANG in zh_CN*) MOUNTOPTIONS="iocharset=cp936" ;; zh_TW*) MOUNTOPTIONS="iocharset=cp950" ;; ja_JP*) MOUNTOPTIONS="iocharset=cp932" ;; ko_KR*) MOUNTOPTIONS="iocharset=cp949" esac fi if [ ! -f /etc/fstab ];then touch /etc/fstab fi #for ide devices for i in $(ls -d /proc/ide/h*);do if cat $i/media |grep -i disk >/dev/null;then for j in $(/sbin/fdisk -l /dev/$(basename $i)|cut -c1-10|grep hd);do LABEL=$(e2label $j 2>/dev/null) FSTYPE=$(/usr/sbin/fstype $j) if [ ! -z $FSTYPE ];then if [ -z $LABEL ];then if ! grep -Rn "$j " /etc/fstab >/dev/null;then MYMOUNT="/mnt/$(basename $j)" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi if echo $FSTYPE|grep -i vfat >/dev/null|| echo $FSTYPE|grep -i ntfs >/dev/null;then echo "$j $MYMOUNT $FSTYPE $MOUNTOPTIONS,umask=0,exec 0 0" >>/etc/fstab mount -t $FSTYPE -o $MOUNTOPTIONS,umask=0,exec,rw $j $MYMOUNT 2>/dev/null else echo "$j $MYMOUNT $FSTYPE defaults 0 0" >>/etc/fstab mount -t $FSTYPE -o defaults $j $MYMOUNT 2>/dev/null fi fi else if ! grep -Rn "$j " /etc/fstab >/dev/null && ! grep -Rn LABEL=$LABEL /etc/fstab >/dev/null;then MYMOUNT="/mnt/$(basename $j)" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi if echo $FSTYPE|grep -i vfat >/dev/null || echo $FSTYPE|grep -i ntfs >/dev/null;then echo "$j $MYMOUNT $FSTYPE $MOUNTOPTIONS,umask=0,exec 0 0" >>/etc/fstab mount -t $FSTYPE -o $MOUNTOPTIONS,umask=0,exec,rw $j $MYMOUNT 2>/dev/null else echo "$j $MYMOUNT $FSTYPE defaults 0 0" >>/etc/fstab mount -t $FSTYPE -o defaults $j $MYMOUNT 2>/dev/null fi fi fi fi done elif cat $i/media |grep -i cdrom >/dev/null;then if ! grep -Rn $(basename $i) /etc/fstab >/dev/null;then MYMOUNT="/mnt/cdrom-$(basename $i)" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi echo "/dev/$(basename $i) $MYMOUNT udf,iso9660 $MOUNTOPTIONS,user,noauto 0 0" >>/etc/fstab fi fi done # for scsi devices,now only for sata. if cat /proc/scsi/scsi |grep Direct >/dev/null;then for j in $(/sbin/fdisk -l /dev/sda|cut -c1-10|grep 'sda');do LABEL=$(e2label $j 2>/dev/null) FSTYPE=$(/usr/sbin/fstype $j) if [ ! -z $FSTYPE ];then if [ -z $LABEL ];then if ! grep -Rn "$j " /etc/fstab >/dev/null;then MYMOUNT="/mnt/$(basename $j)" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi if echo $FSTYPE|grep -i vfat >/dev/null || echo $FSTYPE|grep -i ntfs >/dev/null;then echo "$j $MYMOUNT $FSTYPE $MOUNTOPTIONS,umask=0,exec 0 0" >>/etc/fstab mount -t $FSTYPE -o $MOUNTOPTIONS,umask=0,exec,rw $j $MYMOUNT 2>/dev/null else echo "$j $MYMOUNT $FSTYPE defaults 0 0" >>/etc/fstab mount -t $FSTYPE -o defaults $j $MYMOUNT 2>/dev/null fi fi else if ! grep -Rn "$j " /etc/fstab >/dev/null && ! grep -Rn LABEL=$LABEL /etc/fstab >/dev/null;then MYMOUNT="/mnt/$(basename $j)" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi if echo $FSTYPE|grep -i vfat >/dev/null || echo $FSTYPE|grep -i ntfs >/dev/null;then echo "$j $MYMOUNT $FSTYPE $MOUNTOPTIONS,umask=0,exec 0 0" >>/etc/fstab mount -t $FSTYPE -o $MOUNTOPTIONS,umask=0,exec,rw $j $MYMOUNT 2>/dev/null else echo "$j $MYMOUNT $FSTYPE defaults 0 0" >>/etc/fstab mount -t $FSTYPE -o defaults $j $MYMOUNT 2>/dev/null fi fi fi fi done elif cat /proc/scsi/scsi |grep CD-ROM >/dev/null;then if ! grep -Rn sda /etc/fstab >/dev/null;then MYMOUNT="/mnt/cdrom-sda" if [ ! -d "$MYMOUNT" ]; then mkdir -p "$MYMOUNT" fi echo "/dev/sda $MYMOUNT udf,iso9660 $MOUNTOPTIONS,user,noauto 0 0" >>/etc/fstab fi fi[/code:1] |