openwrt 可实现挂载U盘 , 并支持 Samba , ftp , dlna 等文件操做,而且经过usb 能够实现 4G dongle 的拨号功能网络
咱们都知道,拥有usb 接口的硬件PCB 板,是能够进行USB 开发的,在openwrt 上已经实现了对应的驱动,和大量的开发包程式工具
1、 添加USB扩展(注:本文默认你们的路由器是自带USB接口的,若是主板上自己不带USB接口的,能够考虑对硬件进行改动)oop
1. 添加USB支持测试
Kernel modules —> USB Support —> <*> kmod-usb-core. ##默认已经选了 CONFIG_PACKAGE_kmod-usb-core=y Kernel modules —> USB Support —> <*> kmod-usb-ohci. ##默认已选 old usb1.0 CONFIG_PACKAGE_kmod-usb-ohci=y Kernel modules —> USB Support —> <*> kmod-usb-uhci. ## usb1.1 CONFIG_PACKAGE_kmod-usb-uhci=y Kernel modules —> USB Support —> <*> kmod-usb-storage. # CONFIG_PACKAGE_kmod-usb-storage=y Kernel modules —> USB Support —> <*> kmod-usb-storage-extras. # CONFIG_PACKAGE_kmod-usb-storage-extras Kernel modules —> USB Support —> <*> kmod-usb2. ##默认已经选了 usb2.0 CONFIG_PACKAGE_kmod-usb2=y
2. 添加SCSI支持ui
Kernel modules —> Block Devices —> <*>kmod-scsi-core ##默认已经选了 usb3.0 CONFIG_PACKAGE_kmod-scsi-core=y
3. 添加usb挂载,热插拔,以及boot支持this
Base system —> <*>block-mount #CONFIG_PACKAGE_block-mount=y CONFIG_PACKAGE_libmount=y CONFIG_BUSYBOX_CONFIG_MOUNT=y
mount 命令:挂接命令 spa
mount dervice dir // mount /dev/sda /mnt/
命令格式:mount [-t vfstype] [-o options] device dir 1. t vfstype :指定文件系统的类型,一般没必要指定。mount 会自动选择正确的类型。 经常使用类型有: 光盘或光盘镜像:iso9660 DOS fat16文件系统:msdos Windows 9x fat32文件系统:vfat Windows NT ntfs文件系统:ntfs Mount Windows文件网络共享:smbfs UNIX(LINUX) 文件网络共享:nfs 2. -o options 主要用来描述设备或档案的挂接方式。经常使用的参数有: loop:用来把一个文件当成硬盘分区挂接上系统 ro:采用只读方式挂接设备 rw:采用读写方式挂接设备 iocharset:指定访问文件系统所用字符集 3. device 要挂接(mount)的设备。 4. dir设备在系统上的挂接点(mount point)。
4. 添加热插拔code
默认热插拔是开启的,不用理会
5. boot支持blog
CONFIG_FSTOOLS_UBIFS_EXTROOT=y
6. 此时,能够插上U盘测试一下接口
ls -l /dev |grep sda
显示结果
root@Openwrt:/#ls -l /dev |grep sda brw-r--r-- 1 root root 8, 0 Jan 1 1970 sda
观察里面是否出现sda sda1 sda2 sda3等字样,sda说明是名为sda的设备,而sda1是它的第一个分区,后面依次类推。
2、 添加USB分区 (可选功能)
1. 为什么要对U盘进行分区呢?
第一,方便管理文件。咱们但愿从U盘启动openwrt,所以将系统镜像运行在U盘上,从而得到更多的空间用于存放各类文件。为了增强管理,必要的分区是有用的。 第二,建立Swap交换分区。咱们须要在U盘上开辟部分空间用于Swap交换。经过Swap提高RAM的吞吐率,从而防止,部分软件须要大量调用RAM时,系统挂掉(例如,Transmission脱机下载服务)。
2. 准备工做,添加必要软件
CONFIG_BUSYBOX_CONFIG_FDISK=y CONFIG_BUSYBOX_CONFIG_FDISK_SUPPORT_LARGE_DISKS=y CONFIG_BUSYBOX_CONFIG_FEATURE_FDISK_WRITABLE=y CONFIG_BUSYBOX_CONFIG_FEATURE_AIX_LABEL=y CONFIG_BUSYBOX_CONFIG_FEATURE_SGI_LABEL=y CONFIG_BUSYBOX_CONFIG_FEATURE_SUN_LABEL=y CONFIG_BUSYBOX_CONFIG_FEATURE_OSF_LABEL=y CONFIG_BUSYBOX_CONFIG_FEATURE_GPT_LABEL=y CONFIG_BUSYBOX_CONFIG_FEATURE_FDISK_ADVANCED=y #以上部分表示添加分区工具 CONFIG_PACKAGE_kmod-fs-ext4=y #添加文件系统支持 CONFIG_PACKAGE_e2fsprogs=y #添加格式化和检测工具
3. 对U盘进行分区
3.1 列出当前挂载盘的状况
fdisk -l #以列表的形式,列出当前挂载盘的状况 ~ # fdisk -l Disk /dev/ram0: 16 MB, 16777216 bytes 255 heads, 63 sectors/track, 2 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/ram0 doesn't contain a valid partition table Disk /dev/mtdblock0: 83 MB, 83886080 bytes 255 heads, 63 sectors/track, 10 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/mtdblock0 doesn't contain a valid partition table Disk /dev/mtdblock10: 268 MB, 268435456 bytes 255 heads, 63 sectors/track, 32 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/mtdblock10 doesn't contain a valid partition table Disk /dev/sda: 15.9 GB, 15931539456 bytes 255 heads, 63 sectors/track, 1936 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 1 1937 15554048 7 HPFS/NTFS ~ #
3.2 分区操做
~ # fdisk /dev/sda #分区操做 The number of cylinders for this disk is set to 1936. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): m Command Action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help):
此处选择“n”,而后依次添加各个分区,分完区以后记得选择“w”,进行保存退出。建立分区以后,是没有格式化的,所以接下来须要进行格式化操做。
3.3 分区格式化
mkfs.ext3 /dev/sda1 #将第一个分区格式化为ext3格式 mkswap /dev/sda2 #将第二个分区格式化为swap交换分区 mkfs.ext3 /dev/sda3 #将第三个分区格式化为ext3格式
三、 添加USB 扩展功能 ------- 4G dongle