I'm dealing with an embedded device running Linux. The manufacturers of this device have it set up so that it loads the root filesystem as readonly.

From /etc/mtab:

rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0

This means that I'm unable to modify any files within /etc, such as to add a new user.

I've tried remounting the root directory:

mount -o remount,rw -t squashfs /dev/root /

but I just get an error

mount: cannot remount block device /dev/root read-write, is write-protected

I looked up this error and people were saying to use blockdev. The system doesn't have blockdev installed, so I cross compiled it and copied it across. Then I ran

blockdev --setrw rootfs

but again I got an error:

blockdev: cannot open rootfs: No such file or directory

Is it possible to make /etc writeable if it's not already? I have root access to the system, but I'm not able to access the filesystem 'offline', all changes have to be done via Bash commands.


squashfs is a read-only compressed file system. It has no provision to make modification to it once it's been created. So you couldn't write to it even if the underlying block device could be made writeable. You'd need to create a new squashfs image of the whole filesystem with your modifications and burn it to the storage device where that file system is stored, which would be problematic to do from the live system.

Another option is to mount a different file system on /etc. It could be via a union mount if supported by the kernel, which merges two file systems together typically with one file system recording only the changes to a base read-only file system.

Check for support for AUFS_FS or OVERLAY_FS in the kernel config.

For instance to union-mount a directory in /tmp (hopefully writeable though possibly on tmpfs in memory (so not persistent across a reboot) in your case if the system has no permanent writeable storage)

mkdir -p /tmp/etc/work /tmp/etc/upper
mount -t overlay \
      -o lowerdir=/etc,upperdir=/tmp/etc/upper,workdir=/tmp/etc/work \
       overlay /etc

Then /etc will be writeable and modifications you make to it will actually be stored in /tmp/etc/upper.

Alternatively, if it's only a few file you want to modify, you could bind-mount them (yes you can mount on any file, not only directories) from a version stored in a writable file systems:

cp /etc/passwd /tmp
mount --bind /tmp/passwd /etc/passwd

Then /etc/passwd would be writeable. Of course you can also do that for the whole of /etc instead. (cp -a /etc /tmp && mount --bind /tmp/etc /etc).

  • Some embedded systems can override files in /etc at boot time based on certain setting in nvram. Thus, to change a file in /etc you'd set a "magic" system variable, commit it to nvram, then reload the configuration or reboot. The vast majority of home routers work like that. But the exact mechanisms and commands are system-specific. – Satō Katsura Sep 29 '16 at 14:25
  • Perfect! The device doesn't support overlay mounts, but binding custom files over files in /etc worked very well! Thanks for your help. – Joshua Walsh Sep 29 '16 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.