How to write to /rom

Hey all!
I wanted to write some firmware drivers on my router that I've been trying to make an openwrt image for.
Right now I am mucking about in manufacturer's firmware and wanted to check if I am able to write to /rom for it to survive factory reset.
Touching /rom:

root@OpenWrt:~# touch /rom test.sh
touch: /rom: Read-only file system

Tried mounting/unmounting /rom, but nothing came of that yet, other than unmounting it makes it dissappear from df and mount /rom /mnt -rw makes /dev/root mounted on /mnt .

root@OpenWrt:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 3584      3584         0 100% /rom
tmpfs                    60616       168     60448   0% /tmp
/dev/mtdblock5            9856      1424      8432  14% /overlay
overlayfs:/overlay        9856      1424      8432  14% /
tmpfs                      512         0       512   0% /dev
root@OpenWrt:~# mount /rom /mnt -rw
root@OpenWrt:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 3584      3584         0 100% /rom
tmpfs                    60616       168     60448   0% /tmp
/dev/mtdblock5            9856      1424      8432  14% /overlay
overlayfs:/overlay        9856      1424      8432  14% /
tmpfs                      512         0       512   0% /dev
/dev/root                 3584      3584         0 100% /mnt

After mounting it on /mnt the entire /rom appears in that directory, but what to do with that - i don't know.

Let me move this.to the For Developers category for you.

1 Like

Thanks, sorry about that. I feel like it's basic stuff that i am not understanding.

/rom is read-only squashfs filesystem. You can modify it with imagebuilder or imagebuilder hiding behind firmware-selector or asu/auc.
You can mount it in other place adding -o bind to mount options (but it is pristine in place where it stands)

4 Likes

I though imagebuilder was for creating custom firmware, not for editing already compiled stuff?

squashfs once created is immutable, you can add files at any point before that.

there's /overlay, that's usually where those extra "post flash" files go (in vanilla OpenWRT).

ROM = READ ONLY MEMORY
RAM = RANDOM ACCESS MEMORY

you cannot write to rom ... you can only read from it. Seems like you could use some more reading ...before trying to write anything.

3 Likes