Extroot configurations

I've read the whole article: https://openwrt.org/docs/guide-user/additional-software/extroot_configuration

The article shows how to config external root by editing /etc/config/fstab. Still there are several things which make me confuse:

  1. Why do I need to build my own custom image if my device has 4MiB of flash storage? If it is because the space is too low to install required packages, then building an image with these packages pre-installed may exceed 4MiB, too.
  2. The file /etc/config/fstab does not exist by default. How can OpenWrt overlay rootfs_data partition over rootfs? Where are such settings defined?
  3. This is the code to mount external storage as overlay, taken from the article above. I do not see the code do anything, other than mounting a partition from the USB stick to the directory /overlay on next boot. Mounting a random partition to a random directory does not explain the overlaying process. Does that directory have something special?
DEVICE="/dev/sda1"
eval $(block info "${DEVICE}" | grep -o -e "UUID=\S*")
uci -q delete fstab.overlay
uci set fstab.overlay="mount"
uci set fstab.overlay.uuid="${UUID}"
uci set fstab.overlay.target="/overlay"
uci commit fstab
  1. The article also states that we need to "transfer the content of the current overlay inside the external drive". Does it mean the old rootfs_data partition is not not used at all? In other word, is the new overlayed root file system the combination of (rootfs + /dev/sda1) or (rootfs + rootfs_data + /dev/sda1)?
mount /dev/sda1 /mnt
cp -a -f /overlay/. /mnt
umount /mnt

P.S: Is it necessary to write cp -a -f /overlay/. /mnt. I think this is the same thing: cp -a -f /overlay /mnt

Yes.

Indeed.

4 MB flash (or 32 MB RAM) are insufficient by now, if you need to make it fit somehow, you have to make hard decision of what to remove. extroot can't really save these devices, as you need to invest space to gain space - that works to some extent (the hard way), but you're still plagued by severe RAM shortage.

1 Like

With no documentation about the topic, I have to study this on my own once again. Without using extroot, by typing the mount command, I get these 2 lines:

/dev/mtdblock6 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

So after further investigation and several hours testing, here is the result:

  • The SquashFS image is mount at / to create an initial root file system.
  • OpenWrt mounts the JFFS2 partition at /overlay and it always reads upper/etc/config/fstab from the JFFS2 partition at boot, regardless of extroot status. So even if we are using extroot with a separate fstab on the external partition, a simple change in the fstab on the JFFS2 partition will take effect on next boot, e.g: we can unmount the external partition and use JFFS2 partition.
  • If the file defines no partition to be mounted at /overlay, then OpenWrt continues to merge / as lowerdir and /overlay/upper as upperdir into a single union mount at /, hiding the old /. The SquashFS image may need a bind mount at /rom, and the JFFS2 partition also needs one at /overlay (of the new root file system).
  • If we manually mount the JFFS2 partition to somewhere else, leaving nothing at /overlay, it won't work and the JFFS2 partition shall be mounted back to /overlay, so there always be an upper layer to be overlaid on the SquashFS image. To mount the JFFS2 partition elsewhere, there have to be something mounted at /overlay (the order of mount sections in /etc/config/fstab does not matter).
  • If an external partition is mounted at /overlay, it will be used as the upper layer of the union mount, leaving the JFFS2 partition unused. If we do not copy existing content from the JFFS2 over, OpenWrt starts anew and creates default configuration files on the empty external partition.
  • The interesting thing is, if we start with an empty external partition, OpenWrt still creates a mount section inside the new upper/etc/config/fstab to mount the external partition on next boot. It is totally unnecessary, because OpenWrt has read the fstab file from the JFFS2 partition to mount it. I tried to delete the upper/etc/config/fstab file from the external partition, and everything worked fine. Now only 1 question remains: do both fstab files take effects and which one has precedence over the other?
  • And when we unplug the USB stick, OpenWrt still reads the upper/etc/config/fstab from the JFFS2 partition at boot. Of course it can no longer mount the external partition, so it mounts the JFFS2 partition to /overlay as a fallback. We now have a fully functional system like it was just before setting up extroot. :slight_smile:

P.S: To answer my 1st question, the reason we need to build a custom image for 4MiB device is that the SquashFS image packs things "tighter" than manually installing them into the JFFS2 partition. Also a note for newbies: the default packages in the Image Builder is not the same as those in the pre-built default image of the device -- it lacks LuCI and several other packages compared to the default pre-built image.

1 Like