Overlay FS support (how to enable overlay for new device)

@perumal: Please use "Preformatted text </>" for logs, scripts, configs and general console output.
grafik

Hi @jow

I am trying to figure out how to append the magic 4 byte "0xDE 0xAD 0xC0 0xDE" after squashfs. Still I don't have a clue. Can you please guide me??

Thank you very much,
By Perumal

@jow, Source code point out is appreciated. So far to my investigation, JFFS2 marker (0x1985) should be written by driver itself. But, I couldn't find where this implementation is done in driver source code.

  • Perumal

Hi All,

The expected marker sequence 0x1985 (JFFS2) is not found in /dev/mtdblock3. So, Overlay is mounted in /tmp/root. Hence all configurations loaded in overlay are lost in next reboot.

As suggested by @jow, I tried to add following line in Makefile.

$(call prepare_generic_squashfs,$(KDIR)/root.$(1))

# pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
define prepare_generic_squashfs
	$(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
endef

This invokes "padjffs2" utility with parameters "4k, 8k, 16k, 64k, 128k, 256k". Still, I am receiving this error:
[ 18.460000] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000000: 0xfba6 instead

Can anybody help me to debug this issue?? All I need is to make Overlay persistent, It should not be erased in next reboot.

Thanks,
Perumal

Did you append the deadc0de marker to the end of the padded squashfs?

My appologies, seems the deadc0de approach is outdated and not used anymore :slight_smile: Did you simply try erasing the entire mtd partition before writing the squashfs image? As far as I know the JFFS2 driver will autoformat the MTD partition if it only consists of erased blocks.

Hi @jow

How do I accomplish this? Some guidance is appreciated!

And @jow, I need to know that Am I on right track for this overlay getting mounted in /tmp/root (erased on reboot) issue? Or I need to debug some thing else instead of code debugging.

Thanks,
Perumal

@jow
sorry for hijacking this, I want to make a new target, a NAS, based on kirkwood and I created an image using an ext2fs boot partition, and a squashfs partition (sdx1 and sdx2) the rest of the flash (or HDD) is empty.
on startup I get this

[    2.303939] VFS: Mounted root (squashfs filesystem) readonly on device 8:18.
[    2.487048] init: Console is alive
[    2.490606] init: - watchdog -
[    2.577500] init: - preinit -
[    6.109702] mount_root: loading kmods from internal overlay
[    6.437834] block: attempting to load /etc/config/fstab
[    6.443204] block: unable to load configuration (fstab: Entry not found)
[    6.449999] block: no usable configuration
[    6.455736] mount_root: no usable overlay filesystem found, using tmpfs overlay

the usb drive has plenty of space left on it, or the hard drives, do I miss some package ?

I have block-mount e2fsprogs f2fs-tools partx-utils installed in rootffs

Regards

@lucize,

Do you receive this error??

[ 18.460000] jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000000: 0xfba6 instead

Rgds,
Perumal

no, because I try to boot from usb pen drive or sata hdd, the device has no flash device on it and the image generation includes only the bootpartiton (ext2) and rootfs partition(squashfs), the image is not padded with anything else

regards

@lucize Can post your "df -Th" output?

df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
/dev/root            squashfs        2.0M      2.0M         0 100% /rom
tmpfs                tmpfs         123.6M     68.0K    123.6M   0% /tmp
tmpfs                tmpfs         123.6M     40.0K    123.6M   0% /tmp/root
overlayfs:/tmp/root  overlay       123.6M     40.0K    123.6M   0% /
tmpfs                tmpfs         512.0K         0    512.0K   0% /dev

block info

/dev/sdb1: UUID="4f31ca0e-1154-4f82-a032-ee78c8e4ec79" VERSION="1.0" TYPE="ext2"
/dev/sdb2: UUID="7d979d18-424e8d50-29933880-d28b7d6a" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"

@lucize,

Your overlay is mounted on /tmp/root. Hence any changes made to overlay will get erased on next reboot. It is because JFFS2 markers not found in /dev/mtdblockx. You can check source code “chaos_calmer\build_dir\target-mips_mips32_uClibc-0.9.33.2\fstools-2015-09-15\mount_root.c” for the following error.

[ 6.455736] mount_root: no usable overlay filesystem found, using tmpfs overlay

Please revert back If I am getting anything wrong.

Regards,
Perumal

the device doesn't have /dev/mtdblockx, it is booting from usb or hdd (/dev/sdx), the generation of the image is taken as example from sunxi, that's why I said I hijack this thread. from what I observer on sunxi, x86, brcm2708, the first boot should see the space left on device and create/format an overlay partition (ext4 or f2fs) automatically but I don't know thy is not doing it

Regards

Ok.. Sorry! I misunderstand.

no problem!
when I had problems with jffs2, I booted from an image with tools and I force erased that partition, did you tried that ?

That depends on your board and how you flash the squashfs image now. Either erase it using some uboot command or simply pad your squashfs to the entire size of your mtd partition, so that the tail of the file consists of only zeroes (or 0xff bytes for NOR flash).

dd if=/dev/zero bs=$eraseblocksize count=$number_of_blocks | tr '\0' '\377' > padded-image.bin
dd if=/path/to/squashfs.img of=padded-image.bin conv=notrunc

Then write padded-image.bin to your MTD partition.

Hi @jow,

I have successfully erased mtd partition using following steps,

root@OpenWrt:/# nanddump /dev/mtd3 -f /tmp/mtd3.img
root@OpenWrt:/# flash_eraseall -j /dev/mtd3
Erasing 128 Kibyte @ 6b00000 - 100% complete.Cleanmarker written at 6ae0000.
root@OpenWrt:/# nandwrite /dev/mtd3 /tmp/mtd3.img
Writing at 0x00000000
Writing at 0x00020000
Writing at 0x00040000
.
.
.
Writing at 0x06aa0000
Writing at 0x06ac0000
Writing at 0x06ae0000
root@OpenWrt:/# firstboot
This will erase all settings and remove any installed packages. Are you sure? [N/y]
y
dev/mtdblock3 is not mounted
/dev/mtdblock3 will be erased on next mount
root@OpenWrt:/# reboot

After that /dev/mtdblock3 is detected as JFFS2 successfully.

root@OpenWrt:/# df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
rootfs               rootfs        107.0M      4.2M    102.8M   4% /
/dev/root            squashfs        6.3M      6.3M         0 100% /rom
tmpfs                tmpfs         124.8M     60.0K    124.8M   0% /tmp
tmpfs                tmpfs         124.8M     60.0K    124.8M   0% /tmp/root
tmpfs                tmpfs         512.0K         0    512.0K   0% /dev
/dev/mtdblock3       jffs2         107.0M      4.2M    102.8M   4% /overlay
overlayfs:/overlay   overlay       107.0M      4.2M    102.8M   4% / 

Still I am facing one issue. This error comes up when booting device.

[ 8.000000] mount_root: no usable overlay filesystem found, using tmpfs overlay

People are suggesting to use "nandwrite" instead of "dd" to write images. In my Makefile, I have following 'dd' command. I doubt, Due to this JFFS2 marker might be get dumped wrongly.

I will give a shot on using NANDWRITE instead of DD command in Makefile. I would like to get a suggestion before doing this. Pls share your comments!

dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync

Thanks in Advance,
By Perumal

Hi All,

I am trying to understand how contents of directory "/overlay/upper" is preserved over reboot in Openwrt. As far as I understand, Openwrt should preserve contents of "/overlay/upper", As JFFS2 is a persistent file system.

@jow, Can you please give me some hints on this? Changes done in "/overlay/upper" is lost after reboot (i.e: created a file: /overlay/upper/test.txt).

root@OpenWrt:/# df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
rootfs               rootfs        107.0M      4.2M    102.8M   4% /
/dev/root            squashfs        6.3M      6.3M         0 100% /rom
tmpfs                tmpfs         124.8M     60.0K    124.8M   0% /tmp
tmpfs                tmpfs         124.8M     60.0K    124.8M   0% /tmp/root
tmpfs                tmpfs         512.0K         0    512.0K   0% /dev
/dev/mtdblock3       jffs2         107.0M      4.2M    102.8M   4% /overlay
overlayfs:/overlay   overlay       107.0M      4.2M    102.8M   4% / 

root@OpenWrt:/# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /tmp/root type tmpfs (rw,noatime,mode=755)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
/dev/mtdblock3 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

Thanks,
Perumal