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.
opkg install kmod-usb-storage
opkg install usbutils
/: 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
In step 3, 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.
ls -l /dev/sd*
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.
opkg install block-mount
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.
opkg install gdisk
This triggers an interactive dialogue: Use the suggested defaults for the partition creation (number, starting sector, size, Hex code)
and then confirm your choice with
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.
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!
opkg install e2fsprogs opkg install kmod-fs-ext4 mkfs.ext4 /dev/sda1
opkg install f2fs-tools opkg install kmod-fs-f2fs mkfs.f2fs /dev/sda1
Automount ensures that the external disk partition is automatically made available for usage when booting the OpenWrt device
block detect | uci import fstab
uci set fstab.@mount[-1].enabled='1' uci commit fstab
uci set fstab.@global.check_fs='1' uci commit fstab
uci show fstab
to see something like this
fstab.@global=global fstab.@global.anon_swap='0' fstab.@global.anon_mount='0' fstab.@global.auto_swap='1' fstab.@global.auto_mount='1' fstab.@global.check_fs='0' fstab.@global.delay_root='5' fstab.@mount=mount fstab.@mount.target='/mnt/sda1' fstab.@mount.uuid='49c35b1f-a503-45b1-a953-56707bb84968' fstab.@mount.enabled='0'
ls -l /mnt/sda1
The result will be:
... /dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"
service fstab boot
Optional step for hard disks.
If you want to use OpenWrt as a permanent NAS, you might want to spin down the harddisk motor during times of inactivity. Either because you want to have it quiet in your room during nighttime or to increase lifetime of the harddisk (e.g. when using a home-edition harddisk (instead of a 24×7-datacenter edition).
There are different options, to automatically spin down the motor of the attached harddisk after a certain time of inactivity. Both require installing optional packages on OpenWrt.
1. Option: hdparm
This tool permanently saves a spindown timer on the harddisk itself, using standardized SATA disk commands (the harddisk will then remember that spindown-timer value, even if turned off, even after a restart and even if attached to a different device). Its actually just a command line interface for a built-in harddisk function. So no OpenWrt service has to be 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. But fortunately most USB3.0-SATA-cases seem to support the required SATA command. To install the package
opkg update && opkg install hdparm
E.g. to set a reasonable idle timeout of 20 minutes on the harddisk, use:
hdparm -S 240 /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.
2. Option: hd-idle (With LuCi integration)
This is a service than runs in the background of the OpenWrt device and maintains its own idletimeout counter. Once the defined timeout counter reaches 0, it will send a “live” spindow SATA command to the disk. Unlike the permanent spindown command from hdparm, a lot more USB2.0-SATA cases seem to support this “spindown-now” SATA command.
To install the package that even has LuCi frontend integration:
opkg update && opkg install luci-app-hd-idle
To configure it, use the “Services” menu of the LuCi web GUI of your device.