首页 > 代码库 > OpenWrt中对USB文件系统的操作, 以及读写性能测试
OpenWrt中对USB文件系统的操作, 以及读写性能测试
参考 http://h-wrt.com/en/doc/flash
1. 查看usb存储在启动日志中的信息
# dmesg [ 5.720000] usbcore: registered new interface driver usbfs [ 5.730000] usbcore: registered new interface driver hub [ 5.740000] usbcore: registered new device driver usb [ 5.740000] ehci_hcd: USB 2.0 ‘Enhanced‘ Host Controller (EHCI) Driver [ 5.750000] ehci-platform: EHCI generic platform driver [ 5.760000] ehci-platform ehci-platform: EHCI Host Controller [ 5.760000] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1 [ 5.770000] ehci-platform ehci-platform: irq 3, io mem 0x1b000000 [ 5.800000] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00 [ 5.800000] hub 1-0:1.0: USB hub found [ 5.810000] hub 1-0:1.0: 2 ports detected [ 5.810000] ohci_hcd: USB 1.1 ‘Open‘ Host Controller (OHCI) Driver [ 5.820000] ohci-platform: OHCI generic platform driver [ 5.820000] ohci-platform ohci-platform: Generic Platform OHCI controller [ 5.830000] ohci-platform ohci-platform: new USB bus registered, assigned bus number 2 [ 5.840000] ohci-platform ohci-platform: irq 14, io mem 0x1c000000 [ 5.910000] hub 2-0:1.0: USB hub found [ 5.910000] hub 2-0:1.0: 2 ports detected [ 6.140000] usb 1-1: new high-speed USB device number 2 using ehci-platform [ 6.720000] init: - preinit - [ 7.250000] ar71xx: pll_reg 0xb8050010: 0x11110000 [ 7.250000] eth0: link up (1000Mbps/Full duplex) [ 7.270000] random: procd urandom read with 11 bits of entropy available [ 10.540000] jffs2: notice: (383) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found. [ 10.570000] mount_root: loading kmods from internal overlay [ 11.460000] SCSI subsystem initialized [ 11.460000] uhci_hcd: USB Universal Host Controller Interface driver [ 11.470000] usb-storage 1-1:1.0: USB Mass Storage device detected [ 11.480000] scsi host0: usb-storage 1-1:1.0 [ 11.490000] usbcore: registered new interface driver usb-storage [ 11.740000] block: attempting to load /tmp/jffs_cfg/upper/etc/config/fstab [ 11.760000] block: extroot: not configured [ 11.760000] mount_root: switching to jffs2 overlay [ 11.800000] eth0: link down [ 11.820000] procd: - early - [ 11.820000] procd: - watchdog - [ 12.490000] scsi 0:0:0:0: Direct-Access Generic- SD/MMC 1.00 PQ: 0 ANSI: 0 CCS [ 12.560000] procd: - ubus - [ 13.170000] sd 0:0:0:0: [sda] 30220288 512-byte logical blocks: (15.4 GB/14.4 GiB) [ 13.200000] sd 0:0:0:0: [sda] Write Protect is off [ 13.200000] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00 [ 13.200000] sd 0:0:0:0: [sda] No Caching mode page found [ 13.210000] sd 0:0:0:0: [sda] Assuming drive cache: write through [ 13.240000] sda: sda1 [ 13.250000] sd 0:0:0:0: [sda] Attached SCSI removable disk
2. 用fdisk对usb storage进行分区
root@WNDR3800:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. # 查看磁盘信息 Command (m for help): p Disk /dev/sda: 14.4 GiB, 15472787456 bytes, 30220288 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x00000000 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 30220287 30212096 14.4G 7 HPFS/NTFS/exFAT # 删除分区 Command (m for help): d Selected partition 1 Partition 1 has been deleted. # 创建新分区, 直接回车, 回车 Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-30220287, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-30220287, default 30220287): Created a new partition 1 of type ‘Linux‘ and of size 14.4 GiB. # 保存 Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Device or resource busy The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8). # 重启 root@WNDR3800:~# reboot
3. 使用ext4格式化
# 查看命令参数 root@WNDR3800:~# mkfs.ext4 Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-C cluster-size] [-i bytes-per-inode] [-I inode-size] [-J journal-options] [-G flex-group-size] [-N number-of-inodes] [-m reserved-blocks-percentage] [-o creator-os] [-g blocks-per-group] [-L volume-label] [-M last-mounted-directory] [-O feature[,...]] [-r fs-revision] [-E extended-option[,...]] [-t fs-type] [-T usage-type ] [-U UUID] [-jnqvDFKSV] device [blocks-count] # 格式化 root@WNDR3800:~# mkfs.ext4 -L Ext4U01 /dev/sda1 mke2fs 1.42.12 (29-Aug-2014) Creating filesystem with 3777280 4k blocks and 944704 inodes Filesystem UUID: 355a69cf-7a07-4752-a97d-f81a6956c786 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: 2/116 done # 完成
4. 重启后(让其自动mount), 查看文件系统
root@WNDR3800:~# df -h -T Filesystem Type Size Used Available Use% Mounted on rootfs rootfs 12.1M 3.5M 8.6M 29% / /dev/root squashfs 2.3M 2.3M 0 100% /rom tmpfs tmpfs 61.5M 264.0K 61.3M 0% /tmp /dev/mtdblock5 jffs2 12.1M 3.5M 8.6M 29% /overlay overlayfs:/overlay overlay 12.1M 3.5M 8.6M 29% / tmpfs tmpfs 512.0K 0 512.0K 0% /dev /dev/sda1 ext4 14.1G 36.0M 13.3G 0% /mnt/sda1
5. 性能测试. 需要hdparm, 如果没有的话, 通过opkg install hdparm安装
root@WNDR3800:~# hdparm -Tt /dev/sda /dev/sda: Timing cached reads: 256 MB in 2.01 seconds = 127.67 MB/sec Timing buffered disk reads: 44 MB in 3.09 seconds = 14.24 MB/sec
以及dd
root@WNDR3800:/mnt/sda1# time dd count=128 bs=1M if=/dev/zero of=test.test 128+0 records in 128+0 records out real 0m 28.65s user 0m 0.00s sys 0m 0.74s
计算大致的写入为 128/28.64=4.47MB/s
OpenWrt中对USB文件系统的操作, 以及读写性能测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。