OpenWrt/USB

OpenWrt/USB

USB 需要的内核模块:

kmod-usb2
kmod-usb-pci
kmod-usb3
kmod-usb-storage
kmod-usb-storage-uas // 部分 scsi usb 硬盘需要的驱动
kmod-fs-ext4 // ext4 支持
kmod-fs-f2fs // f2fs 支持。f2fs 文件系统为 SSD / flash 存储优化,适合于U盘/TF卡

软件包:

opkg install usbutils # lsusb -t
opkg install blockd # with block-mount. block info | grep "/dev/sd"
opkg install fdisk gdisk # gdisk: gpt disk partition tool
opkg install e2fsprogs # mkfs.* tools

挂载 usb 设备

lsusb -t

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/1p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/2p, 480M
    |__ Port 1: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M

Bus…”-Lines represent the host chip. Here, the “Driver” will be xhci for USB3.0, ehci for USB2.0 and uhci or ohci for USB1.1.

Lines with “Class=Mass Storage” represent connected USB devices. Here the “Driver” is either "usb-storage" for storage of type Bulk only Transport or "usb-storage-uas" for storage of type USB_Attached_SCSI

ls -l /dev/sd*
block info | grep "/dev/sd" # 有时usb存储不出现在 block info

如果 “Class=Mass Storage” 行的 Driver= 后面显示为空,或者找不到 /dev/sd* 块设备,可能因为 usb 硬盘供电不足等原因(dmesg 里有时能看到错误)。

确认硬盘识别后,用 fdisk / gdisk / mkfs.[ext4|f2fs|fat] / mount 对 /dev/sd* 进行分区 / 格式化 / 挂载即可。

Automount

# Generate a config entry for the fstab file:
block detect | uci import fstab
# Now enable automount on that config entry:
uci set fstab.@mount[-1].enabled='1'
uci commit fstab
# Optionally enable autocheck of the file system each time the OpenWrt device powers up:
uci set fstab.@global[0].check_fs='1'
uci commit fstab
# Reboot your OpenWrt device (to verify that automount works)
# After the reboot, check your results: Run
uci show fstab
fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].check_fs='0'
fstab.@global[0].delay_root='5'
fstab.@mount[0]=mount
fstab.@mount[0].target='/mnt/sda1'
fstab.@mount[0].uuid='49c35b1f-a503-45b1-a953-56707bb84968'
fstab.@mount[0].enabled='1'

Check the “enabled” entry. It should be '1'.

ls -l /mnt/sda1
/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"
service fstab boot

Last update: 2020-06-06 12:46:37 UTC