Many useful programs such as squid, Samba, YAMon, etc. require the use of external storage. The easiest way to do this on modern routers is to connect a USB stick (or USB hard drive) to the router.
In my case, I "just want to connect my new 4GByte USB stick to my LEDE router" so I can use some of the software named above.
It would be an enormous service to the entire LEDE community for someone who knows how all this stuff works to create a simple HOWTO page on the www.lede-project.org wiki.
Requirements:
LEDE 17.01.0 or newer firmware
Router with at least 32MBytes of RAM and 64MBytes Flash (no swap needed, plenty of space for packages)
USB device of unknown filesystem and sufficient capacity (say, 1Gbyte or more)
Format the new storage for ext4
Mount the new storage in /opt
Written for a novice (that is, "Just do step1, step2, step3... and you're done")
Non-requirements:
The "USB Storage" HOWTO needs to focus on the items above, and doesn't have to address any of the factors below. In fact, the HOWTO shouldn't talk about these - they add complexity with no value to the issue at hand:
Don't worry about pre-LEDE software. We're all using LEDE. All the existing guides on the OpenWrt site have long sections about ancient software. There's no way to evaluate which of these apply to modern firmware.
Don't worry about filesystems that aren't ext4. We just want to wipe the data on the stick, and then use it with LEDE. Talking about other formats simply clouds the issue.
Don't worry about a LuCI package. It would be great to have a GUI that does this, but requiring SSH is fine.
Don't worry about options. We've already chosen LEDE firmware and a particular USB stick. We just want to install and use it, and don't care about alternatives. (If there are choices, the procedure should choose the sensible defaults that always work.)
The "crucial part" of extroot (at least for me) is when /etc/config/fstab is created for the fisrt time.
I din't know why, but after rebooting fstab doesn't contain the overlay mount point so in order to overcome this, I copy the contents of fstab before rebooting and after rebooting, paste them again in fstab.
You may also need (if not installed by default):
kmod-nls-base
kmod-nls-cp437
kmod-nls-iso8859-1
kmod-nls-utf8
Steps to follow:
Use the cfdisk command to create an ext4 partition on /dev/sda
Create the filesystem
mkfs.ext4 /dev/sda1
Prepare your external storage root overlay
mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt
Create fstab
block detect > /etc/config/fstab;
sed -i s/option$'\t'enabled$'\t''0'/option$'\t'enabled$'\t''1'/ /etc/config/fstab;
sed -i s#/mnt/sda1#/overlay# /etc/config/fstab;
cat /etc/config/fstab;
Copy the fstab contents temporarily to a file
Reboot
Edit fstab and paste the contents you have previously copied in the temporary file (if the contents are the same, there is no need for that). Also add "option fstype". The file should look like this:
Reboot again and check with df command or alternatively in LuCI (System -> Mount Points) that everything is ok with the overlay and the rest of the partition table.
Normally you are done.
P.S: You probably won't need a swap partition but in the rare case you will, you can also install swap-utils and create a second partition using the cfdisk command which will be the swap. Also create the filesystem using "mkswap /dev/sda2" and follow the rest of the guide.
I am of the opinion that the released images should include USB functionality for those that have it, which is virtually every device made in the last 2 years. It should really just work, and I think very few who uses a precompiled binary would object. You do not have to use it.
It's the first thing I have installed on all my devices (sans 1 AP). It's a frequent request in the posts and source of new user pain. I expect the USB feature did not exist when the functional framework of features was developed. Even if it did, early on it may have made sense not to include this due to space limitations for packages. The LEDE (and OpenWrt) base image has not changed to keep up with modern hardware features and it seems like anything with 16mb or more of flash should not be an issue. OK, bring on the dissenters.
I created a Playground Page for USB Storage with my notes which summarizes a number of articles and my installation notes. It's 2 years old. It creates USB share for a basic data device with no users, it does not cover exroot. It is OpenWrt based, but I had no issue installing all this on my HooToo TM-02 (8GB) under LEDE 17.01.0, but the unit is now the AP referred to above. Hopefully someone can utilize this as an accelerator to build a new LEDE tool.
As I recall, fstab is not auto created and one gets a message about block mount not supported (not sure its been a while).
If you missed it or it is wrong/unclear then tell what you don't understand or how to improve it, or you can use it as a base for a simplified how-to if you so wish.
It is based on the openWRT extroot article but It's all tested personally and working in LEDE.
I am of the opinion that the released images should include USB functionality for those that have it
The release images have USB/Sata/whatever support built-in, so the USB/Sata/whatever controller is functional.
I mean kmod-usb2 and kmod-usb-ohci kmod-usb-ehci (and/or a kmod for usb 3 that I don't remember).
But kmod-usb-storage and filesystem drivers aren't usually included as USB can be used to connect whatever (USB relays/power switches or sound or whatever). I would personally add them too if the device isn't using 4MB flash, but I've seen some opposition when people tried to merge new devices with that support included.
While most devices with Sata do have at least ext4 filesystem compiled in the kernel, and work for storage ootb because that's the only thing Sata can do.
@bobafetthotmail What's missing from the LEDE wiki is a single page with the procedure for installing an external storage device. (The page you cite tells about installing new packages on an external storage device. I don't want to do that - I want to use squid/YAMon/Samba/something else. So that page doesn't appear to be relevant to me.)
@RangerZ - I agree that USB support should be part of the mainline LEDE/OpenWrt distribution. Maybe we can prototype what should be available by default.
I wonder if our Resident USB Experts (@RangerZ, @angelos, @bobafetthotmail, anyone else?) might collaborate to write a HOWTO with a single goal: installing a USB storage device on LEDE. The steps should cover:
All the points of the original post: use a modern router, firmware, and USB stick, with enough RAM/Flash to hold all the packages that might be necessary, and format and mount the media in a known directory.
One file system that will work for all these uses, no swap partition required
Consider how much the current Samba, YAMon, squid, packages on external file storage, and other utility's instructions would need to change to use this default USB configuration (hopefully, not much)
Again, if it is not placed in a convenient spot or has an unclear name or has other issues please post it, and you can also use it as a base for a quicker tutorial.
This is a good start, but I'm going to challenge you (and the other readers) to make it even shorter, with the single-minded goal of mounting a USB stick/drive on LEDE. (I would take a crack at it, but don't understand how this stuff works - yet.)
Don't worry about minimizing Flash/RAM space (we already said the router has at least 32/64 MBytes RAM/Flash). Don't worry about different formats/partitions/etc. Most people are looking for a single partition that can be used on LEDE, so just make intelligent default choices. The steps might tell the reader to:
Done! The new storage is available at xxxx in the filesystem
If there are any places problems might crop up, send readers to the Troubleshooting section, that explains options, etc. Don't clutter the 1-2-3 steps with alternatives. Many thanks!
This is a good start, but I’m going to challenge you (and the other readers) to make it even shorter, with the single-minded goal of mounting a USB stick/drive on LEDE.
I can make a "quickstart" kind of thing, where I skip all checks and provide a blob of copy-paste shell code for automated partitioning/formatting.
But I'd rather keep the current longer guide too that does checks and explains and links around for those that actually care about understanding what they are doing.
I'm assuming ext4 filesystem (it's fine also for USB drives), and that the USB drive does not need to be re-partitioned, just re-formatted (which is the case for most data drives and thumb drives).
I tried the procedure, and had to install two other packages (kmod-usb3, kmod-usb-storage) before the procedure worked.
I took the liberty of making an editorial pass over the instructions, and adding those two packages. Please check that I've left a working procedure. Thanks again.
It's correct, just that on most devices the kmod-usb drivers are already installed.
And yeah, starting and enabling the fstab service is better than making a mount -a like I do.
I tried the procedure, and had to install two other packages (kmod-usb3, kmod-usb-storage) before the procedure worked.
Ok, thanks for testing. kmod-usb3 (and kmod-usb2) should be installed by default in devices that have USB 3.0 ports or (usb 2.0). Can you tell me what device is that so I can send a PR to add that package in its default list?
I added the kmod-usb2 too for the sake of having this work also when there are devices with USB 2.0 that lack the driver.
My goal was a procedure that would work on all LEDE devices, so including packages to support USB 2.0 & USB 3.0 would be important.
Am I correct that opkg installing a package that's not required (or is already present) has no effect, except perhaps to consume a bit more Flash memory?