openWRT boot /dev/loop0 /overlay question

Hi guys,

A quick question: I was going through the mount output of an openWRT device, and I noticed this:

root@OpenWrt:/# mount
/dev/loop0 on /overlay type ext4 (rw,noatime)

root@OpenWrt:/# cat /sys/class/block/loop0/loop/backing_file
root@OpenWrt:/# cat /sys/class/block/loop0/loop/offset

Correct me if I'm wrong, but it seems the /overlay partition is mounted through a loopbackdevice, that takes its backing file from a direct raw partition.
I never tried this before and didn't know it worked, but as far as I understand the only benefit of doing this (vs just doing a simple mount) is that you can skip the partition table on the device and force the start of some filesystem at a specific offset.

Is this what this is used for? (to remain flexible somehow in case the partition table/mtd mapping/whatever is not setup correctly?) Or are there other shenanigans going on under the hood for which this method was devised?

I quickly tried to find the relevant code that actually sets up the mapping, but didn't immediately find it. Perhaps someone could point me to the relevant location?

Thanks for your feedback!



Maybe an update, this using-loop0-for-overlayfs doesn't seem to be a generic feature.
On another board it looks like this:

root@OpenWrt:/# mount
/dev/mtdblock14 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)


(which makes.. more sense I guess)

The board with the loopback mount is a layerscape target in SD-build mode. (it appends the overlayfs(ext4) directly after the squashfs and puts them all in the same partition for some reason).

1 Like

There are some platforms, like octeon or x86 with MMC and it'd be reasonable to expect them to use a separate partition for overlay, but they actually create an loop with offset over the main partition.

  1. What it the reason for loop?
  2. How this can be changed or configurable? I've not found where offset is calculated and loop is created.
  3. Is it possible to customize overlay at imagebuilder time?