参考 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 -b 4096 -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 # 完成
# 如果要设置为swap分区
mkswap /dev/sda1
Setting up swapspace version 1, size = 523235840 bytes
4. 重启后(让其自动mount), 查看文件系统, 如果df没有-T参数, 可以直接用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
[root@TIMEPLUG_CF37:/root]#mount rootfs on / type rootfs (rw) /dev/root on /rom type squashfs (ro,relatime) proc on /proc type proc (rw,noatime) sysfs on /sys type sysfs (rw,noatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime) /dev/mtdblock7 on /overlay type jffs2 (rw,noatime) overlayfs:/overlay on / type overlayfs (rw,noatime,lowerdir=/,upperdir=/overlay) tmpfs on /dev type tmpfs (rw,relatime,size=512k,mode=755) devpts on /dev/pts type devpts (rw,relatime,mode=600) /dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered) /dev/mtdblock6 on /mnt/mtdblock6 type squashfs (ro,relatime)
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
Update 2017-10-08: 使用unitek(优越者)某款2.5寸usb3.0硬盘盒挂载时出现错误导致被挂载为只读, 具体错误为
Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.904000] EXT4-fs (sda1): mounting ext3 file system using the ext4 subsystem Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.968000] sd 0:0:0:0: [sda] Invalid command failure Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.972000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 19.976000] Result: hostbyte=0x00 driverbyte=0x08 Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.980000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 19.984000] Sense Key : 0x5 [current] Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.988000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 19.992000] ASC=0x24 ASCQ=0x0 Thu Oct 5 18:57:15 2017 kern.info kernel: [ 19.992000] sd 0:0:0:0: [sda] CDB: Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 19.996000] cdb[0]=0x2a: 2a 08 00 00 38 48 00 00 08 00 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.000000] end_request: critical target error, dev sda, sector 14408 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.008000] Buffer I/O error on device sda1, logical block 1545 Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.016000] lost page write due to I/O error on sda1 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.020000] JBD2: Error -5 detected when updating journal superblock for sda1-8. Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.028000] EXT4-fs warning (device sda1): ext4_clear_journal_err:4637: Filesystem error recorded from previous mount: IO failure Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.040000] EXT4-fs warning (device sda1): ext4_clear_journal_err:4638: Marking fs in need of filesystem check. Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.056000] EXT4-fs (sda1): warning: mounting fs with errors, running e2fsck is recommended Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.068000] EXT4-fs (sda1): recovery complete Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.072000] sd 0:0:0:0: [sda] Invalid command failure Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.076000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.080000] Result: hostbyte=0x00 driverbyte=0x08 Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.084000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.088000] Sense Key : 0x5 [current] Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.092000] sd 0:0:0:0: [sda] Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.096000] ASC=0x24 ASCQ=0x0 Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.100000] sd 0:0:0:0: [sda] CDB: Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.100000] cdb[0]=0x2a: 2a 08 00 00 38 48 00 00 08 00 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.108000] end_request: critical target error, dev sda, sector 14408 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.112000] Buffer I/O error on device sda1, logical block 1545 Thu Oct 5 18:57:15 2017 kern.warn kernel: [ 20.120000] lost page write due to I/O error on sda1 Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.124000] JBD2: Error -5 detected when updating journal superblock for sda1-8. Thu Oct 5 18:57:15 2017 kern.err kernel: [ 20.132000] Aborting journal on device sda1-8. Thu Oct 5 18:57:15 2017 kern.info kernel: [ 20.136000] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts:
以及
Thu Oct 5 18:57:17 2017 kern.crit kernel: [ 22.264000] EXT4-fs error (device sda1): ext4_journal_check_start:56: Detected aborted journal Thu Oct 5 18:57:17 2017 kern.crit kernel: [ 22.272000] EXT4-fs (sda1): Remounting filesystem read-only Thu Oct 5 18:57:19 2017 daemon.err block: /dev/sda1 is already mounted on /mnt/sda1
在更换为其他硬盘盒(硬盘不变)后, 错误消失.