Bookmark

Using a USB Storage Device with OpenWrt: Drivers, Partitions, and Automount

I use OpenWrt's USB storage page when I need an HDD, SSD, or flash drive for data, Samba/NAS, or a general file store. If the goal is extending the overlay to install more packages, this is not the whole extroot procedure; I keep the two goals separate.[25]

Warning: Formatting deletes data from the partition. Before running mkfs.*, confirm the correct /dev/sda1 or equivalent device and keep a separate backup.[25]

1. Install and verify USB drivers

Refresh package indexes, install storage support, and add UAS if the device needs it:[25]

1
2
3
4
opkg update
opkg install kmod-usb-storage
opkg install kmod-usb-storage-uas
opkg install usbutils

Connect the USB device and inspect it:[25]

1
lsusb -t

A usable result can show a root_hub with an xhci-mtk/ehci driver and a Class=Mass Storage line using usb-storage or usb-storage-uas. I want to see a driver name and no error in the USB chain; otherwise I revisit driver installation or reboot before trying again.[25]

2. Confirm the disk and partitions

Keep the drive connected and list block devices:[25]

1
ls -l /dev/sd*

The result should include a disk such as /dev/sda or /dev/sdb, plus a partition if the disk is already partitioned:[25]

1
2
brw-------    1 root     root        8,   0 Oct 30 12:49 /dev/sda
brw-------    1 root     root        8,   1 Oct 30 12:49 /dev/sda1

Install the tools for UUID/filesystem information:[25]

1
2
3
4
opkg install block-mount
# for exFAT you also need libblkid
opkg install libblkid
block info | grep "/dev/sd"

For example:[25]

1
/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" TYPE="ext4"

If no disk appears, recheck the USB driver and reboot. With multiple devices, /dev/sdb1, /dev/sdc1, and so on belong to later disks; never substitute the example /dev/sda1 for the actual output.[25]

3. Create a partition with gdisk

Do this only when the previous step shows no partition such as /dev/sda1:[25]

1
2
opkg install gdisk
gdisk /dev/sda

Inside the interactive gdisk prompt:[25]

  1. Enter n to create a partition.[25]
  2. Keep the suggested defaults for number, starting sector, size, and Hex code when appropriate.[25]
  3. Enter w to write the changes.[25]
  4. Enter Y to confirm.[25]
  5. Record the new partition name for the format step.[25]

The documentation recommends a single partition for the following how-to; ? opens gdisk help.[25]

4. Install a filesystem and format it

The filesystem driver is required even when a partition was formatted elsewhere. For EXT4 on a USB hard disk:[25]

1
2
3
opkg install e2fsprogs
opkg install kmod-fs-ext4
mkfs.ext4 /dev/sda1

For exFAT:[25]

1
opkg install kmod-fs-exfat

For F2FS on an SSD or thumb drive:[25]

1
2
3
opkg install f2fs-tools
opkg install kmod-fs-f2fs
mkfs.f2fs /dev/sda1

/dev/sda1 is only an example. Substitute the partition identified earlier and check the backup before formatting. For NTFS, use the appropriate NTFS driver/procedure rather than running mkfs.ext4 over existing data.[25]

5. Create an automount entry

Generate an fstab entry from the block device, enable the mount, and optionally enable filesystem checks at boot:[25]

1
2
3
4
5
6
7
block detect | uci import fstab
uci set fstab.@mount[-1].enabled='1'
uci commit fstab

# Optional filesystem check on boot
uci set fstab.@global[0].check_fs='1'
uci commit fstab

Reboot to test it, then inspect the configuration:[25]

1
uci show fstab

I want to see enabled='1', a target such as /mnt/sda1, and the expected UUID. Check the mount point:[25]

1
2
3
ls -l /mnt/sda1
block info
service fstab boot

A confirming result can include:[25]

1
2
3
4
fstab.@mount[0].target='/mnt/sda1'
fstab.@mount[0].uuid='49c35b1f-a503-45b1-a953-56707bb84968'
fstab.@mount[0].enabled='1'
/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"

6. Optional NAS disk spindown

Option A: hdparm

hdparm stores a SATA timer on the disk itself; many older USB2 adapters do not support it, while some USB3 SATA adapters do. Install it and try a ten-minute timer:[25]

1
2
opkg update && opkg install hdparm
hdparm -S 120 /dev/sda2

If the command fails, the adapter or drive may not support this spindown command. 0 disables the timeout; 1240 specify five-second multiples from 5 seconds to 20 minutes; 241251 specify 30-minute units from 30 minutes to 5.5 hours.[25]

To apply it again at boot, the page gives this /etc/rc.local example:[25]

1
2
3
4
# set timeout to put the drive into idle (low-power) mode
/sbin/hdparm -S 120 /dev/sda2

exit 0

Option B: hd-idle with LuCI

hd-idle is an OpenWrt service that sends a live spindown command when its idle counter reaches zero. Install its LuCI integration:[25]

1
opkg update && opkg install luci-app-hd-idle

Open Services → HDD Idle to enable and configure it. For the CLI-only package:[25]

1
opkg update && opkg install hd-idle

Edit /etc/config/hd-idle, then enable and start the service:[25]

1
service hd-idle enable && service hd-idle start

The main hd-idle options are disk (default sda), enabled (default 0), idle_time_unit (default minutes), and idle_time_interval (default 10). Replace sda with the actual device identifier; do not assume the example /dev/sda2 matches the real layout.[25]

Final checks and limits

After mounting, read and write a non-critical test file and check logs if the disk disappears after reboot. The USB bus, filesystem, drive, power supply, and adapter all affect the result; this page configures storage but does not prove that every adapter supports UAS or spindown.[25]

Source

Original source: [Using storage devices]1, published/updated 2025-09-30.[25]

Sources

[25] https://openwrt.org/docs/guide-user/storage/usb-drives — OpenWrt Wiki: Using storage devices


0 Bình luận

Góp Ý / Bình Luận / Đánh giá