Quick Start for Adding a USB drive

The Goal: This guide describes how to add a single USB stick or drive to your OpenWrt device. The result will be a USB drive with an ext4 file system and mounted at /mnt/sdXX (where sdXX is the name of the USB).

This is all you'll need for most purposes, however, there are plenty of options described below.

  • Your device/router itself must have at least 8 MB Flash. Lower capacity devices will not be able to hold the required packages.
  • You can add a USB drive of any capacity.
  • This procedure WILL ERASE THE USB DRIVE (unless you stop at step 5 and just want to mount a preformated drive). Copy any data you care about to another destination.
  • This quickstart requires you to ssh into the router.

1. Use your laptop/desktop computer to format your USB device. Use the default name and format options. This prepares the USB drive for the process below, which will erase those settings (again). Warning: This initial formatting will erase the entire USB drive.

2. SSH into the router and enter the following commands into the SSH window. More...

3. Get the required packages: More...

opkg update && opkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb-storage kmod-usb2 kmod-usb3

4. Enter ls -al /dev/sd* to show the name of all attached USB devices. The list may be empty if there are no USB devices. More...

5. Insert the USB drive into your router. Enter ls -al /dev/sd* again, and this time you should see a new /dev/sdXX device. sdXX is the device name of your new USB device. More...

    root@OpenWrt:~# ls -al /dev/sd*
    brw-------    1 root     root        8,   0 Feb  4 15:13 /dev/sda
    brw-------    1 root     root        8,   1 Feb  4 14:06 /dev/sda1

6. Make an ext4 filesystem on the USB device using the device name you just discovered. Note: Be certain you enter the proper device name - this step will completely erase the device. More...

mkfs.ext4 /dev/sda1

7. Create the fstab config file based on all the block devices found. More...

block detect | uci import fstab

8. Update the fstab config file to mount all drives at startup. More...

uci set fstab.@mount[0].enabled='1' && uci set fstab.@global[0].anon_mount='1' && uci commit fstab

9. Mount the device. More...

/etc/init.d/fstab boot

10. You're done! This procedure has mounted the drive at /mnt/sdXX (whatever the device name was.) The drive is ready to save data at that part of the filesystem.

More information about this procedure and about USB drives:

  • You can change the mount point in the web interface, in SystemMount Points menu.
  • The full USB Drive tutorial has much more about USB drives.
  • If you have a memory limited router (say with 4MBytes Flash internal storage), and want to be able to install more packages, you should instead read the Extroot Configuration page.
  • For NTFS disks, refer to Writable NTFS
  • Look at the fstab documentation to configure from the command line
  • This Forum article also has a lot of background information: https://forum.openwrt.org/t/more-on-usb-drive-installation/30695/2
  • If you just want to temporarily mount the drive (say, for testing), you can simply enter: mkdir /tmp/MyDrive; mount /dev/sda1 /tmp/MyDrive Note that, as of OpenWRT v18, the Ext4 file system will be autodetected. After finishing the test reading/writing the drive: umount /tmp/MyDrive
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2021/03/07 13:11
  • by richb-hanover