Almacenamiento USB

Una vez obtenido el soporte USB Básico, usted querrá conectar un dispositivo de almacenamiento USB a su router, por ejemplo, una memoria USB, un disco duro USB, etc... Este artículo le dará los pasos y requerimientos para lograrlo..
Note que este artículo trata, principalmente, acerca de agregar espacio adicional a la memoria flash interna. Mover el root-fs a un espacio de almacenamiento externo se describe en el artículo extroot_configuration.

El proceso sigue el siguiente curso:

  1. Obtener soporte USB básico en su dispositivo potenciado por OpenWrt;
  2. Instalar los prerrequisitos para almacenamiento USB como se ve en below. Ahora se podrá reconocer por el sistema un dispositivo de almacenamiento USB conectado (i.e. un disco duro);
  3. Si no lo ha hecho previamente, particionar el dispositivo y crear los sistemas de archivos que quiere (Vea Storage para informarce acerca de cómo lograr esto desde dentro de OpenWrt). El dispositivo en sí mismo y sus particiones deberían estar disponibles inmediatamente como Device files dentro de /dev/. Por ejemplo /dev/sda como el dispositivo, con /dev/sda1, /dev/sda2, ... , como las particiones. O, en caso de no estar particionado ccon una tabla de particiones y tener un único sistema de archivos, puede accederse directamente dentro de i.e. /dev/sda. Los dispositivos subsecuentes que agregue serán /dev/sdb, /dev/sdc y así sucesivamente. Asegúrese de que los requerimientos del sistema de archivos se cumplen al instalar los paquetes de kernel correctos para soportar los sistemas de archivo que requiere específicamente (ver Storage);
  4. Los sistemas de archivos podrán ser montados y accedidos, ver Storage. Opcionalmente, usted puede configurar montaje automático al arranque usando /etc/config/fstab y puede configurarlo como root file system using extroot.

When your USB device is properly recognised by the system, using the proper driver kernel packages listed in Basic USB support, the following packages facilitate USB storage support:

  • kmod-usb-storage required ... Kernel support for USB Mass Storage devices.
  • kmod-fs-<file_system> required ... the file system you formatted your partition in. Common examples include kmod-fs-ext4, kmod-fs-hfs, kmod-fs-hfsplus, kmod-fs-msdos, kmod-fs-ntfs, kmod-fs-reiserfs and kmod-fs-xfs.
  • kmod-usb-storage-extras optional ... Kernel support for some more drivers, such as for SmartMedia card readers.
  • block-mount recommended & required (if using fstab UCI configuration or luci Mount Points) ... Scripts used to mount and check block devices (filesystems and swap) and hotplug capability (recognition when device is plugged in).
  • kmod-scsi-core Any mass storage is a generic SCSI device.
Before the Attitude Adjustment release, other optional packages included: block-hotplug for USB recognition upon plug-in and block-extroot required for rootfs on external storage. In r26314 the three opkg packages block-mount, block-extroot and block-hotplug have been merged into a single package block-mount.
  • e2fsprogs additional This package contains essential ext2/ext3/ext4 filesystem utilities for formatting and checking for errors on ext2/ext3/ext4 filesystems like mkfs.ext3, mkfs.ext4, fsck and other core utilities.

The following will install USB storage support, assuming USB works already, install ext4 file system support and mount a connected USB drive, pre-partitioned with a Linux swap partition and an ext4 partition.

opkg update
opkg install kmod-usb-storage block-mount kmod-fs-ext4
mkswap /dev/sda1
swapon /dev/sda1
mkdir -p /mnt/share
mount -t ext4 /dev/sda2 /mnt/share -o rw,sync

Note that partitions are usually auto detected, so this should work as well using default settings:

  mount /dev/sda2 /mnt/share

Another example is how to use an external usb stick with a FAT32 partition (but we'll keep ext4 support also). See also Storage.

opkg update
opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
mkdir -p /mnt/usb
mount -t vfat /dev/sda1 /mnt/usb

You may create an empty file to indicate that the disk is not plugged in so that you don't put files directly onto NAND by doing

umount /mnt/usb   #make sure the disk isn't mounted before doing this
touch /mnt/usb/USB_DISK_NOT_PRESENT
chmod 555 /mnt/usb 
chmod 444 /mnt/usb/USB_DISK_NOT_PRESENT

This will prevent only processes not running as root from writing onto NAND (see this discussion). You can of course also use this file in your own scripts.

The good news first: OpenWrt can use encrypted disks almost out-of-the-box.

The bad news is, there are some things to keep in mind.


Devices with 32 MB memory may run short of free memory. Symptoms can be that LUCI is displaying the Login page instead of the actual target page or that the out-of-memory killer starts killing tasks, so strange failures happen. Monitor the memory, e,g. using the free command.

I/O performance

Decryption and encryption may slow down the system. cryptsetup benchmark will show some numbers that can be compare for different platform. Unfortunately, only the hash algorithms work, the crypto algorithm tests currently (15.05, rampis) fail with

Required kernel crypto interface not available.
Ensure you have algif_skcipher kernel module loaded.

FIXME: find out why this fails and how to fix it. LUKS works fine, so it should work... See also the article about Cryptographic hardware accelerators for suggestions that may improve the situation. However, in the worst case there is too much load for the main core(s). Monitor the load, e,g. using the uptime command, details of the output are explained in this article

Using Linux hard disk encryption with LUKS is straight forward:

  1. Install required packages:
    opkg install cryptsetup lvm2 kmod-crypto-aes kmod-crypto-misc kmod-crypto-xts kmod-crypto-iv kmod-crypto-cbc kmod-crypto-hash kmod-dm
  2. Create necessary config files: Most of the kmod-crypto-* packages create file in /etc/modules.d folder that automatically installs provided modules at boot time. However kmod-crypto-misc containing sha256 module (among others) is an exception to this, hence we need to create such a file manually:
    echo sha256_generic >/etc/modules.d/11-crypto-misc
  3. Mounting your encrypted partition: Replace /dev/encrypted_partition with a path to the device file of your encrypted partition and /mnt/mountpoit with your desired mount point:
    cryptsetup luksOpen /dev/encrypted_partition usbstorage_luks && mount /dev/mapper/usbstorage_luks /mnt/mountpoint
  4. Umounting:
    umount /mnt/mountpoint && cryptsetup luksClose usbstorage_luks

Please refer to the existing documentations, e.g.

<none yet>

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: 2019/08/26 16:37
  • by vgaetera