//Tip:// The Quick Start for installing a USB drive solves the very common case of installing a single USB drive onto your OpenWrt device. People do this to use Samba or other programs that need to store data on an external drive. The remainder of this page provides much more information about USB devices and drivers.
Many supported devices have ports to connect storage devices, most common are USB, or Sata.
This article will describe how to configure your device to use such storage devices for storage or for sharing. If you want to expand your firmware's space (to install more packages) please read the article about Extroot configuration.
To configure external disk space, follow the procedures of this page:
This step ensures that required USB storage drivers are properly installed.
xhci for USB3.0, ehci for USB2.0 and uhci or ohci for USB1.1.usb-storage for storage of type Bulk only Transport or usb-storage-uas for storage of type USB_Attached_SCSIIn step 5, verify that the output prints no error and has at least one output line for root_hub and Mass Storage and that each Driver= lists a driver name. If not, then refer to the Installing USB Drivers for more suggestions on drivers.
This optional verification step can be used, to check that the OS can properly detect a connected external drive.
Ensure your USB disk/stick is stick connected
Run in a command line:
ls -l /dev/sd*
This should now show a list of block devices known to the OS
brw------- 1 root root 8, 0 Oct 30 12:49 /dev/sda
brw------- 1 root root 8, 1 Oct 30 12:49 /dev/sda1
This should print at least a connected disk like "/dev/sda" or "/dev/sdb". If no disk at all is listed, recheck USB driver installation and reboot your OpenWrt device once.
Install the block tool to get more info about existing partitions
opkg install block-mount
for exFAT you also need libblkid
opkg install libblkid
Run the block tool:
block info | grep "/dev/sd"
and you should see output like this, if your disk already has partitions:
/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" TYPE="ext4"
If a disk already has existing partitions, they get listed as /dev/sda1, /dev/sda2 ,/dev/sda3 and so on.
If we had connected more than one storage device we would have also a /dev/sdb1 (first partition of second device), /dev/sdc1 (first partition of third device) and so on.
if the previous chapter did not list any existing partitions (like "/dev/sda1", "/dev/sda2", "/dev/sdb1"...), you have to create a partition first for further storage usage.
To do so, install gdisk:
opkg install gdisk
Start gdisk with the disk name identified in the previous chapter:
gdisk /dev/sda
In the interactive gdisk menu, create a partition with gdisk command
n
This triggers an interactive dialogue: Use the suggested defaults for the partition creation (number, starting sector, size, Hex code)
When done, confirm the changes with gdisk interactive command
w
and then confirm your choice with
Y
Keep a note of the created partition name for the next step
Refer to the gdisk help text (write "?") in case you need additional help. Stick to a single partition, to stay aligned to the following HowTo.
To use a partition for data storage, it needs to be formatted with a file system.
To use a filesystem on a partition, you need to install the file-system-driver. Thus you need to make this step e.g.
opkg install kmod-fs-exfat
even if you don't create a new partition.
The following is the most simplest (and recommended) default configuration for OpenWrt file system usage.
For advanced users, there are further optional file system options available.
WARNING: This step deletes existing data in that partition. Ensure you have a backup of important files before starting!
Automount ensures that the external disk partition is automatically made available for usage when booting the OpenWrt device
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
to see something like this
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'.
Note the "target" entry. This is the file path, where your attached USB storage drive can be accessed from now on. E.g. you can now list files from your external disk:
ls -l /mnt/sda1
Run the following command, to verify that the disk is properly mounted at this path
block info
The result will be:
...
/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"
Your external storage is now ready for further usage:
service fstab boot
If you want to use OpenWrt as a permanent NAS, you should spin down the drive during times of inactivity. This may be to have it quiet, reduce power consumption, and increase life of a harddisk (e.g. especially if using a home-edition harddisk (instead of a 24x7-datacenter drive).
There are several optional packages available to automatically spin down an attached disk after a certain time of inactivity.
1. Option: hdparm
Using standard SATA commands this tool permanently saves a spindown timer on the harddisk itself. The harddisk will then maintain that spindown-timer value, even if turned off, even after a restart and even if attached to a different device. As this is simply a command line for a built-in harddisk function no service will run in the background for this and 'hdparm' could even be uninstalled after setting this parameter. Unfortunately many older USB2.0 PATA/SATA adapters do not support the required SATA command, although even decade-old harddisks do support it. Fortunately most USB3.0 SATA drives seem to support this command. To install the package:
opkg update && opkg install hdparm
To set a reasonable idle timeout of 10 minutes on the harddisk:
hdparm -S 120 /dev/sda2
Of course you can always change the timeout or disable auto-spindown again later on. Depending on your harddisk, the value may be active until the next reset or permanently stored on the harddisk. The harddisk firmware itself manages the spindown timeout, not a OpenWrt service. For persistent changes use /etc/rc.local file, like:
# set timeout to put the drive into idle (low-power) mode
/sbin/hdparm -S 120 /dev/sda2
exit 0
2. Option: hd-idle with LuCi integration
hd-idle is a service than runs in the background of OpenWrt and maintains its own idle timeout. Once the defined timeout counter reaches 0, it will send a "live" spindown SATA command to the disk. Unlike the permanent spindown command from hdparm, a lot more USB2.0 SATA drives seem to support this "spindown-now" SATA command.
To install the package with LuCi web GUI integration:
opkg update && opkg install luci-app-hd-idle
To enable and configure it, in LuCI go to the Services -> HDD Idle page.
To install only the CLI package (without LuCi):
opkg update && opkg install hd-idle
To configure it, edit the /etc/config/hd-idle and then autostart and run the hd-idle service service hd-idle enable && service hd-idle start.
Options to configure:
| Name | Type | Default | Description |
|---|---|---|---|
disk |
string | sda |
Replace sda with your device's identifier |
enabled |
boolean | 0 |
Enable hd-idle operation |
idle_time_unit |
string | minutes |
The unit of time used in the idle_time_interval option |
idle_time_interval |
integer | 10 |
How much idle time before spindown |