Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:storage:usb-drives [2018/08/08 16:11] – Link to page with more suggestions on usb drivers perdocs:guide-user:storage:usb-drives [2022/04/10 09:15] – hdparm rc.local autostart ivanmara
Line 3: Line 3:
 <WRAP box> <WRAP box>
 //Tip:// The **[[docs:guide-user:storage:usb-drives-quickstart|Quick Start for installing a USB drive]]**  //Tip:// The **[[docs:guide-user:storage:usb-drives-quickstart|Quick Start for installing a USB drive]]** 
-solves the very common case of installing a single USB drive onto your LEDE device.+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. 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. The remainder of this page provides much more information about USB devices and drivers.
Line 24: Line 24:
  
   - Start by refreshing the list of available software packages:<code>opkg update</code>   - Start by refreshing the list of available software packages:<code>opkg update</code>
-  - The typical LEDE package already has core USB device drivers installed (if your device has USB ports at all), but might not yet have an USB storage device driver installed. Install this storage driver first (if it is already installed, the following command will just say "is already installed": <code>opkg install kmod-usb-storage</code>+  - The typical OpenWrt package already has core USB device drivers installed (if your device has USB ports at all), but might not yet have an USB storage device driver installed. Install this storage driver first (if it is already installed, the following command will just say "is already installed": <code>opkg install kmod-usb-storage</code> 
 +  - Some USB storage devices may require the UAS driver: <code>opkg install kmod-usb-storage-uas</code>
   - To check, if the whole USB driver chain is working correctly, install the optional **usbutils** package:<code>opkg install usbutils</code>   - To check, if the whole USB driver chain is working correctly, install the optional **usbutils** package:<code>opkg install usbutils</code>
   - Now connect your USB disk/stick and list your connected devices with a command from these **usbutils**: <code>lsusb -t</code>   - Now connect your USB disk/stick and list your connected devices with a command from these **usbutils**: <code>lsusb -t</code>
Line 32: Line 33:
     |__ Port 1: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M     |__ Port 1: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M
 </code> </code>
-  * "Bus..."-Lines represent the host chip. Here, the "Driver" will be xhcifor USB3.0, "ehcifor USB2.0 and "uhcior "ohcifor USB1.1. +  * "Bus..."-Lines represent the host chip. Here, the "Driver" will be ''xhci'' for USB3.0, ''ehci'' for USB2.0 and ''uhci'' or ''ohci'' for USB1.1. 
-  * Lines with "Class=Mass Storage" represent connected USB devices. Here the "Driver" is either "usb-storagefor storage of type [[https://en.wikipedia.org/wiki/USB_mass_storage_device_class|Bulk only Transport]] or "usb-storage-uasfor storage of type [[https://en.wikipedia.org/wiki/USB_Attached_SCSI|USB_Attached_SCSI]] +  * Lines with "Class=Mass Storage" represent connected USB devices. Here the "Driver" is either ''usb-storage'' for storage of type [[wp>USB_mass_storage_device_class|Bulk only Transport]] or ''usb-storage-uas'' for storage of type [[wp>USB_Attached_SCSI|USB_Attached_SCSI]] 
  
-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  [[docs:guide-user:storage:usb-installing|the Installing USB Drivers]] for more suggestions on drivers or the [[docs:guide-user:storage:usb-troubleshooting|the USB troubleshooting guide]]+In 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 [[docs:guide-user:storage:usb-installing|the Installing USB Drivers]] for more suggestions on drivers.
  
 ===== Verify that the OS recognizes the attached disk and partitions ===== ===== Verify that the OS recognizes the attached disk and partitions =====
Line 43: Line 44:
   - Run in a command line:<code>ls -l /dev/sd*</code>   - Run in a command line:<code>ls -l /dev/sd*</code>
   - This should now show a list of block devices known to the OS<code>brw-------    1 root     root        8,   0 Oct 30 12:49 /dev/sda   - This should now show a list of block devices known to the OS<code>brw-------    1 root     root        8,   0 Oct 30 12:49 /dev/sda
-brw-------    1 root     root        8,   1 Oct 30 12:49 /dev/sda1</code>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 LEDE device once. +brw-------    1 root     root        8,   1 Oct 30 12:49 /dev/sda1</code>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<code>opkg install block-mount</code>+  - Install the **block** tool to get more info about existing partitions<code>opkg install block-mount</code> for exFAT you also need libblkid <code>opkg install libblkid</code>
   - Run the **block** tool:<code>block info | grep "/dev/sd"</code>and you should see output like this, if your disk already has partitions:<code>/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" TYPE="ext4"</code>   - Run the **block** tool:<code>block info | grep "/dev/sd"</code>and you should see output like this, if your disk already has partitions:<code>/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" TYPE="ext4"</code>
  
Line 64: Line 65:
 To use a partition for data storage, it needs to be formatted with a file system. 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 LEDE file system usage.\\+The following is the most simplest (and recommended) default configuration for OpenWrt file system usage.\\
 For advanced users, there are [[docs:guide-user:storage:filesystems-and-partitions|further optional file system options available]]. For advanced users, there are [[docs:guide-user:storage:filesystems-and-partitions|further optional file system options available]].
  
Line 73: Line 74:
 opkg install kmod-fs-ext4 opkg install kmod-fs-ext4
 mkfs.ext4 /dev/sda1</code> mkfs.ext4 /dev/sda1</code>
 +  * For USB drives formatted as NTFS see [[docs:guide-user:storage:filesystems-and-partitions#setup_ntfs|Filesystems]] and [[docs:guide-user:storage:writable_ntfs|Writable NTFS]]
   * For SSD drives and thumb drives,  install F2FS file system and use F2FS to format the partition (in this example '/dev/sda1'): <code>opkg install f2fs-tools   * For SSD drives and thumb drives,  install F2FS file system and use F2FS to format the partition (in this example '/dev/sda1'): <code>opkg install f2fs-tools
 opkg install kmod-fs-f2fs opkg install kmod-fs-f2fs
Line 79: Line 81:
  
 ===== Automount the partition ===== ===== Automount the partition =====
-Automount ensures that the external disk partition is automatically made available for usage when booting the LEDE device+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:<code>block detect > /etc/config/fstab</code> +  - Generate a config entry for the fstab file:<code>block detect | uci import fstab</code> 
-  - Now enable automount on that config entry:<code>uci set fstab.@mount[0].enabled='1' +  - Now enable automount on that config entry:<code>uci set fstab.@mount[-1].enabled='1' 
-uci commit</code> +uci commit fstab</code> 
-  - Optionally enable autocheck of the file system each time the LEDE device powers up:<code>uci set fstab.@global[0].check_fs='1' +  - Optionally enable autocheck of the file system each time the OpenWrt device powers up:<code>uci set fstab.@global[0].check_fs='1' 
-uci commit</code> +uci commit fstab</code> 
-  - Reboot your LEDE device (to verify that automount works)+  - Reboot your OpenWrt device (to verify that automount works)
   - After the reboot, check your results: Run <code>uci show fstab</code>to see something like this<code>fstab.@global[0]=global   - After the reboot, check your results: Run <code>uci show fstab</code>to see something like this<code>fstab.@global[0]=global
 fstab.@global[0].anon_swap='0' fstab.@global[0].anon_swap='0'
Line 97: Line 99:
 fstab.@mount[0].target='/mnt/sda1' fstab.@mount[0].target='/mnt/sda1'
 fstab.@mount[0].uuid='49c35b1f-a503-45b1-a953-56707bb84968' fstab.@mount[0].uuid='49c35b1f-a503-45b1-a953-56707bb84968'
-fstab.@mount[0].enabled='0'</code>+fstab.@mount[0].enabled='1'</code> 
 +  - 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:<code>ls -l /mnt/sda1</code>   - 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:<code>ls -l /mnt/sda1</code>
   - Run the following command, to verify that the disk is properly mounted at this path<code>block info</code>The result will be:<code>...   - Run the following command, to verify that the disk is properly mounted at this path<code>block info</code>The result will be:<code>...
 /dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"</code> /dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" MOUNT="/mnt/sda1" TYPE="ext4"</code>
-  - Your external storage is now ready for further usage +  - Your external storage is now ready for further usage:<code> 
-   +service fstab boot</code>
 ===== Optional: Idle spindown timeout on disks for NAS usage ===== ===== Optional: Idle spindown timeout on disks for NAS usage =====
 Optional step for hard disks. Optional step for hard disks.
  
-If you want to use LEDE 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 24x7-datacenter edition).+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 24x7-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 LEDE.+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**\\ **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).  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. Its actually just a command line interface for a built-in harddisk function.
-So no LEDE 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.+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 To install the package
 <code> <code>
Line 130: Line 132:
  
 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. 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 LEDE service.+The harddisk firmware itself manages the spindown timeout, not a OpenWrt service. For persistent changes use ''/etc/rc.local'' file, like: 
 +<code bash> 
 +# set timeout to put the drive into idle (low-power) mode 
 +/sbin/hdparm -S 240 /dev/sda2 
 + 
 +exit 0 
 +</code> 
  
  
 **2. Option: hd-idle (With LuCi integration)** \\ **2. Option: hd-idle (With LuCi integration)** \\
-This is a service than runs in the background of the LEDE 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.+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: To install the package that even has LuCi frontend integration:
Line 141: Line 150:
 </code> </code>
 To configure it, use the "Services" menu of the LuCi web GUI of your device. To configure it, use the "Services" menu of the LuCi web GUI of your device.
 +
 +\\
 +To install the CLI package (without LuCi):
 +<code>
 +opkg update && opkg install hd-idle
 +</code>
 +To configure it, you can edit the ''/etc/config/hd-idle'' file 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 |
 +:!: Notice that you have to enable it since it isn't by default.
  • Last modified: 2023/03/30 21:01
  • by stokito