Welcome! Log In Create A New Profile

Advanced

Can openwrt be installed to and boot from USB?

Posted by pm4888 
Can openwrt be installed to and boot from USB?
April 28, 2022 10:41AM
For PogoE02 device.



Edited 1 time(s). Last edit at 04/28/2022 10:41AM by pm4888.
Re: Can openwrt be installed to and boot from USB?
April 28, 2022 05:05PM
That should be an easy job.

Format the usb drive, 1 partition, ext3/ext4 format

Just download openwwrt, extra the file system to the usb. Make any change if necessary.

Download / copy the kernel to the usb.

change the u-boot enviroment to boot from that usb.
Re: Can openwrt be installed to and boot from USB?
April 29, 2022 03:55PM
$ ssh root@192.168.1.x


BusyBox v1.33.2 (2022-04-16 12:59:34 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 21.02.3, r16554-1d4dea6d4f
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:~#

So I follow this post to get OpenWrt running in the ram with openwrt-21.02.3-kirkwood-cloudengines_pogoe02-initramfs-uImage. However I notice that the default kernel doesn't do usb storage or ext4 fs. Can you share more detail on how to install openwrt to usb storage?
Re: Can openwrt be installed to and boot from USB?
April 29, 2022 04:43PM
Is this why there are tutorials about installing to flash but not usb? Seems like one needs to roll own kernel at the very least to make this happen.

root@OpenWrt:~# cat /proc/filesystems 
nodev	sysfs
nodev	tmpfs
nodev	bdev
nodev	proc
nodev	cgroup
nodev	cgroup2
nodev	debugfs
nodev	sockfs
nodev	bpf
nodev	pipefs
nodev	ramfs
nodev	devpts
	squashfs
nodev	jffs2
nodev	overlay
nodev	mqueue
nodev	ubifs
root@OpenWrt:~# 

Re: Can openwrt be installed to and boot from USB?
April 30, 2022 01:44AM
An initramfs kernel doesn't need to support usb or ext4 in order to be booted from usb. It's the bootloader who reads it from usb, and starts it.
However, if you need to access the usb filesystem from your running OpenWrt, you can create a custom image here:
https://chef.libremesh.org/
You have to add at least kmod-fs-ext4 and kmod-usb-storage. More info can be found here.
But beware, any package added, is added to the internal ramfs inside the kernel inside the uImage. At some point it will outgrow the maximum size the bootloader can handle.
As far as I know there is no easy way to create an OpenWrt OS for a random device (which is not x86/amd64) where the rootfs is on an USB mass storage device. And why would you want? You could simply use Debian.
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 02:56AM
> And why would you want? You could
> simply use Debian.

+1

Distro serves different purposes. Use Debian as a NAS, use OpenWrt as a router.

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 08:19AM
Mijzelf Wrote:
-------------------------------------------------------
> An initramfs kernel doesn't need to support usb or
> ext4 in order to be booted from usb. It's the
> bootloader who reads it from usb, and starts it.
> However, if you need to access the usb filesystem
> from your running OpenWrt, you can create a custom
> image here:
> https://chef.libremesh.org/
> You have to add at least kmod-fs-ext4 and
> kmod-usb-storage. More info can be found
> here.
>
> But beware, any package added, is added to the
> internal ramfs inside the kernel inside the
> uImage. At some point it will outgrow the maximum
> size the bootloader can handle.
> As far as I know there is no easy way to create an
> OpenWrt OS for a random device (which is not
> x86/amd64) where the rootfs is on an USB mass
> storage device. And why would you want? You could
> simply use Debian.

So pogoplugv4 has the kmod-fs-ext4 built-in. Given the generous internal flash size(128M on Pogo E02) compared to most home routers, I'd say adding a few more modules(like in this case kmod-fs-ext4 and kmod-usb-storage) to default kernel build has some positive value and the only downside is it takes some extra space.
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/kirkwood/image/Makefile;h=60e8654ad3f818f4378e643e71b35e160d1c9e22;hb=HEAD#l125

But yeah great to discover the chef build website. I imagine this might work:
1. custom built sysupgrade with kmod-fs-ext4 and kmod-usb-storage support
2. mount my 64M usb flash
3. Extract custom built sysupgrade image: there are three files in it "CONTROL", "kernel", and "root". Extract the squashfs "root" to flash /, extract the "kernel" to flash /boot
4. Tune uboot env to boot from usb.

The only thing is I do not have real console access. I open the box yesterday but my console cables cannot fit and I don't have the cd audio cable mentioned here http://blog.qnology.com/2013/10/pogoplug-e02-v2-serial-connection.html. I'm not able to verify if anything breaks.

Yeah it's a personal choice. Debian is great I use it a lot. Openwrt is a better fit for me here for E02. Especially when I noticed yesterday how smooth E02 runs openwrt compared to my home gateway router netgear WNDR4300-1. And I never imagine my 64M usb stick can see the light of day again and here it is. And the reason to use usb is to reduce write to flash, same reason some rescue sets / to "ro" only.



Edited 1 time(s). Last edit at 04/30/2022 08:21AM by pm4888.
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 08:37AM
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/boot/uboot-kirkwood/patches/140-pogoplug_e02.patch;h=53ad98291ca123078167d8b1098327be1e8fa680;hb=HEAD
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/kirkwood/patches-5.10/110-pogo_e02.patch;h=fc384d3521f960c6add3bb155457412342891994;hb=HEAD

+CONFIG_MTDPARTS_DEFAULT="mtdparts=orion_nand:0xe0000@0x0(uboot),0x20000@0xe0000(uboot_env),0x100000@0x100000(second_stage_uboot),-@0x200000(ubi)"

Ok Openwrt for E02 has different MTD structure, but it is not a big deal when usb boot is used, right?



Edited 1 time(s). Last edit at 04/30/2022 08:38AM by pm4888.
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 08:58AM
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/boot/uboot-kirkwood/Makefile;h=d9cb10ce13affd100f71f81c7bc8389d9ee090a4;hb=HEAD

PKG_VERSION:=2020.04

What's the difference say between uboot for kirkwood and uboot for rockchip? Is it just the env variables settings, or the source code of uboot needs change to support each hw line of devices?
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 02:34PM
pm4888 Wrote:
-------------------------------------------------------
> Ok Openwrt for E02 has different MTD structure,
> but it is not a big deal when usb boot is used,
> right?
As long as you don't actually flash it, it doesn't matter.

> What's the difference say between uboot for kirkwood and uboot for rockchip?
Huge. uboot doesn't only load the kernel from somewhere, it also initializes the RAM (timing, voltage, ...). And the drivers for flash, usb and network are different for both SoCs.

> 1. custom built sysupgrade with kmod-fs-ext4 and
> kmod-usb-storage support
> 2. mount my 64M usb flash
> 3. Extract custom built sysupgrade image: there are
> three files in it "CONTROL", "kernel", and "root".
> Extract the squashfs "root" to flash /, extract the "kernel"
> to flash /boot
That won't work. The kernel modules for usb storage and ext4 are in the rootfs, and the kernel won't be able to mount the rootfs without them. It might be possible to create an initramfs with the modules inserted, and add a custom script which mounts another rootfs (extracted from a sysupgrade) and do a switch_root to the new rootfs. That is the trick most Linux distros do. Put all files needed to mount the rootfs in an initrd, and let initrd load by the bootloader. A possible problem is that the OpenWrt init scripts on the usb rootfs might freak out because they expect to be running from flash, and not from an usb mass storage. But it won't hurt to try.



Edited 1 time(s). Last edit at 04/30/2022 02:45PM by Mijzelf.
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 03:28PM
IIRC, OpenWrt already has a switchroot instruction.

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: Can openwrt be installed to and boot from USB?
April 30, 2022 05:33PM
Mijzelf Wrote:
-------------------------------------------------------
> pm4888 Wrote:
> -------------------------------------------------------
> > Ok Openwrt for E02 has different MTD structure,
> > but it is not a big deal when usb boot is used,
> > right?
> As long as you don't actually flash it, it doesn't
> matter.
>
> > What's the difference say between uboot for
> kirkwood and uboot for rockchip?
> Huge. uboot doesn't only load the kernel from
> somewhere, it also initializes the RAM (timing,
> voltage, ...). And the drivers for flash, usb and
> network are different for both SoCs.
>
> > 1. custom built sysupgrade with kmod-fs-ext4 and
>
> > kmod-usb-storage support
> > 2. mount my 64M usb flash
> > 3. Extract custom built sysupgrade image: there
> are
> > three files in it "CONTROL", "kernel", and
> "root".
> > Extract the squashfs "root" to flash /, extract
> the "kernel"
> > to flash /boot
> That won't work. The kernel modules for usb
> storage and ext4 are in the rootfs, and the kernel
> won't be able to mount the rootfs without them. It
> might be possible to create an initramfs with the
> modules inserted, and add a custom script which
> mounts another rootfs (extracted from a
> sysupgrade) and do a
> switch_root
> to the new rootfs. That is the trick most Linux
> distros do. Put all files needed to mount the
> rootfs in an initrd, and let initrd load by the
> bootloader. A possible problem is that the OpenWrt
> init scripts on the usb rootfs might freak out
> because they expect to be running from flash, and
> not from an usb mass storage. But it won't hurt to
> try.

Exactly as you point out, the chef build adds modules to rootfs instead of integrating them into kernel so it's no good. Typical chicken and egg.

What comes to your mind though init script might have issue with usb mass storage? I feel as long as the mount points are correct it should not care.
Re: Can openwrt be installed to and boot from USB?
May 02, 2022 01:41PM
> Exactly as you point out, the chef build adds modules to rootfs instead of integrating them into kernel so it's no good.
That is a consequence of OpenWrt. It's designed to run on devices which are sparse in memory and storage. So everything which is not needed to bring up a minimal functionality is added as a module. To add usb storage and ext4 support to the kernel, it would have to be compiled as a special for you alone.

> What comes to your mind though init script might have issue with usb mass storage?
> I feel as long as the mount points are correct it should not care.

Sorry, I don't know what you mean.
Re: Can openwrt be installed to and boot from USB?
May 02, 2022 04:01PM
Mijzelf Wrote:
-------------------------------------------------------
> > Exactly as you point out, the chef build adds
> modules to rootfs instead of integrating them into
> kernel so it's no good.
> That is a consequence of OpenWrt. It's designed to
> run on devices which are sparse in memory and
> storage. So everything which is not needed to
> bring up a minimal functionality is added as a
> module. To add usb storage and ext4 support to the
> kernel, it would have to be compiled as a special
> for you alone.

Yeah Pogo E02 is not exactly resource constrained. 128M flash is still more than a lot of other devices supported these days.
I did roll my own kernel with usb4/usb-storage but still was not able to make it work. Now that I have OpenWrt in NAND I think perhaps I missed to create the rootfs and rootfs_data partition? Not sure

> > What comes to your mind though init script might
> have issue with usb mass storage?
> > I feel as long as the mount points are correct
> it should not care.
>
> Sorry, I don't know what you mean.
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: