OpenWrt掛載U盤(NTFS)並在網路上的芳鄰共享訪問
工具/原料
- 刷好OpenWrt(帶LuCI介面)的路由器一臺 當然必須帶USB介面
- 軟體:putty 用於命令列操作路由器
- 軟體:WinSCP 用於修改路由器配置檔案
方法/步驟
- 1
用putty連線路由器,用putty下載安裝所需的軟體包:(直接複製下面內容到提示符)
opkg update
opkg install kmod-usb-core
opkg install kmod-usb2 #安裝usb2.0
opkg install kmod-usb-ohci #安裝usb ohci控制器驅動
opkg install kmod-usb-storage #安裝usb儲存裝置驅動
opkg install kmod-fs-ext3 #安裝ext3分割槽格式支援元件
opkg install kmod-fs-vfat #掛載FAT
opkg install ntfs-3g #掛載NTFS
opkg install mount-utils #掛載解除安裝工具
opkg install block-mount
opkg install luci-app-samba #SAMBA網路共享服務
/etc/init.d/samba enable #啟用並開始SAMBA共享
/etc/init.d/samba restart
注意 線上安裝軟體包需保證路由器Wan口可以連線Internet
- 2
重啟路由器 登陸路由器設定介面可以看到多了掛載點和網路共享兩個選項(也可全部做完再重啟)
- 3
用WinSCP連線路由器,開啟/etc/hotplug.d/block/10-mount檔案(如果不存在請新建)
修改為如下內容
#!/bin/sh
# Copyright (C) 2009 OpenWrt.org (C) 2010 OpenWrt.org.cn
blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then
device=`basename $DEVPATH`
case "$ACTION" in
add)
mkdir -p /mnt/$device
# vfat & ntfs-3g check
if [ `which fdisk` ]; then
isntfs=`fdisk -l | grep $device | grep NTFS`
isvfat=`fdisk -l | grep $device | grep FAT`
isfuse=`lsmod | grep fuse`
isntfs3g=`which ntfs-3g`
else
isntfs=""
isvfat=""
fi
# mount with ntfs-3g if possible, else with default mount
if [ "$isntfs" -a "$isfuse" -a "$isntfs3g" ]; then
ntfs-3g -o nls=utf8 /dev/$device /mnt/$device
elif [ "$isvfat" ]; then
mount -t vfat -o iocharset=utf8,rw,sync,umask=0000,dmask=0000,fmask=0000 /dev/$device /mnt/$device
else
mount /dev/$device /mnt/$device
fi
if [ -f /dev/${device}/swapfile ]; then
mkswap /dev/${device}/swapfile
swapon /dev/${device}/swapfile
fi
;;
remove)
if [ -f /dev/${device}/swapfile ]; then
swapoff /dev/${device}/swapfile
fi
umount /dev/$device
;;
esac
fi
這段指令碼可實現自動掛載,如不想編輯指令碼,也可在掛載點中自己設定(PS.沒試過)
- 4
插入U盤或行動硬碟 再次重啟路由器 在掛載點中就可以看到已經掛載的裝置
如果U盤只有一個分割槽,就是/mnt/sda1,第二個分割槽是/mnt/sda2
如果用Hub接入多個U盤,第二個裝置就是/mnt/sdb,以此類推
- 5
進入網路共享中,新增共享目錄例如/mnt/sda1,許可權為777(即完全訪問)。
至此就可以在網路上的芳鄰中看到路由器的這個共享檔案夾了。
- 6
注意XP系統 必須保證
Computer Browser
Server
Application Layer Gatway Service
Windows Firewall/Internet Connection Sharing
這幾個服務開啟 並且在本地連線屬性中
Microsoft 網路的檔案和印表機共享
啟用時 網路上的芳鄰檔案才可以訪問。
轉載自http://jingyan.baidu.com/article/5225f26b6b273fe6fa090829.html