There are hard discs, which are considered block devices, and there is flash memory. There are two basic types of flash memory: NOR flash and NAND flash.
If the flash chip (no matter what type) is connected directly with the SoC and has to be addressed directly by Linux, we call it "raw flash".
If there is an additional controller chip between flash chip and the SoC, we call it "FTL (Flash Translation Layer) flash". Embedded systems almost exclusively use "raw flash", while SDDs and also USB memory sticks, almost exclusively use FTL flash!
ExtRoot: How it works
Obviously there are two possible ways to do things:
- we can pivot the
/overlayto the USB disk (you could call this external overlay or pivot-overlay) - we can pivot the entire
/ (read: root)to the USB disk (you could call this external root or pivot-root)
Note: extroot started as the external overlay thus the external root was called pivot-root only in order to distinguish between the two implementations. To avoid misunderstandings you should always use pivot-overlay and pivot-root respectively. extroot comprises both methods.
Note: The shitty bootloaders the OEMs delight us with, are the only reason why we cannot put everything (including the Kernel) on the USB hard drive! Especially uboot is very well capable of handling diverse file systems, but uboot most often lacks the necessary hardware drivers. While uboot is under GPLv2 and the Linux Kernel is also GPLv2 it is possible to port code, so implementing such functionality is not that big of a deal, but the OEMs are obviously not inclined to give us such luxury and who is going to do that for free? The OEM bootloader of the dockstar is actually NOT capable of booting from USB, only the version provided by Jeff Doozan is! Hello, FOSS |
Source Code
The extroot functionality is provided by the block-mount package. It contains of a set of shell scripts: →https://dev.openwrt.org/browser/trunk/package/block-mount/files
Considerations
In order to use a / located on a USB device, the Linux kernel requires modules for the USB-circuitry (kmod-usb-core and kmod-usb2), modules for storage devices connected over USB (kmod-usb-storage) and modules for the file system (kmod-fs-ext4). And once you have a kernel with all that functionality build-in, you still need to tell init to mount that particular filesystem on the USB disk as /. Tricky without having a filesystem at all.
- Older versions of ExtRoot required to include the kernel modules in the SquashFS (or include them into the Kernel) and also a configuration. Then you would change the
/etc/config/fstab, which was located on the JFFS2 and this would make ExtRoot work. - Newer versions allow you to install everything on the JFFS2-partition, an OpenWrt firmware image file doesn't have to be build specifically with extroot in mind any longer.
First using SquashFS and then chroot, would make init not PID 1, which is bad.
Explanations
The external rootfs is done as an overlay of the boot root filesystem. The boot root filesystem will be mounted read-only on /rom, and the external rootfs device will be mounted read-write on /overlay. The root (/) filesystem will be a overlayfs overlay of /overlay over /rom, and mounted on root (/) (obviously).
During the boot process, the configuration used to mount the external rootfs is done as follows: → process.boot
Sequence pivot overlay
- IF NOT SquashFS, root is remounted rw on
/ - IF SquashFS, JFFS2 is mounted rw on
/tmp/overlay - IF
/tmp/overlay/etc/config/fstabexists we use it as the configuration file, otherwise we use/etc/config/fstab(if it exists) - Fork
- Backfire: we search for a
mountsection in thefstab-file with the optionis_rootfsset to true, and mount it on /overlay, if we find it - Attitude Adjustment: in trunk we prefer to look for a
mountsection in thefstab-file with the target/overlay
- we unmount
/tmp/overlayagain and/or remount root (/) read only - we pivot the root so that that
/overlayon top of/romis now root, and old root is on/rom
Sequence pivot root
- IF NOT SquashFS, root is remounted rw on
/ - IF SquashFS, JFFS2 is mounted rw on
/tmp/overlay - IF
/tmp/overlay/etc/config/fstabexists we use it as the configuration file, otherwise we use/etc/config/fstab(if it exists) - we search for a
mountsection in thefstab-file with target set to/and mount it on /rom - we pivot the root to that what was
romis now root and old root is on/rom
History
- added with R19880
Merge
For all block-extroot revisions, determines whether this filesystem is a rootfs for use with block-extroot. If it is a rootfs and block-extroot is installed, then during preinit, this filesystem will be mounted on /overlay and used as the root overlay (like jffs2 on a normal squashfs boot, only with this filesystem). target is ignored for the purposes of a rootfs mount, however when doing the squashfs mount (e.g. a fallback, or on firstboot), it will be used as usual (see extroot).
overlay filesystem
doc/howto/extroot/extroot.theory.txt · Last modified: 2012/07/27 19:49 by 70d7a4f46
This text is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
