1

I try a simple overlay example by mounting: sudo mount -t overlay -o lowerdir=/tmp/lower,upperdir=/tmp/upper/upper, workdir=/tmp/upper/workdir none /tmp/overlay

(I run the full script from example in : https://blog.programster.org/overlayfs)

The mount is successful:

/tmp/lower-fs.img on /tmp/lower type ext4 (ro)
/tmp/upper-fs.img on /tmp/upper type ext4 (rw)
none on /tmp/overlay type overlay 
(rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/workdir)

Yet, I get error on trying to write into the readonly and overlayed area:

 echo "hello world" >> /tmp/lower/lower-file.txt
 bash: /tmp/lower/lower-file.txt: Read-only file system

I use the following kernel:

$ uname -a
Linux user-VirtualBox 4.4.50-040450-generic #201702181144 SMP Sat Feb 18 
 16:45:38 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Thanks for any idea

0

You need to write to the overlay mount. The command you pasted is trying to write directly to the lower layer, which is indeed mounted read-only...

Use this instead, it should work:

$ echo "hello world" >> /tmp/overlay/lower-file.txt

Note that you'll see the contents of the lower layer in your /tmp/overlay mount, but any modifications you make will go to the upper layer (under the hood), while you'll get a merged view of the layers under your overlay mount point, which is the one you're supposed to access.

  • thanks very much, but I thought the idea of overlay is that if we try to write to the readonly area, it will still succeed. and if it fails , it won't help. – ransh Aug 15 '18 at 8:14
  • @ransh Not quite... The idea of overlayfs is that you get a new mount that is a merge of your readonly area (lower layer) with a readwrite/scratch area on top (upper layer), so that you can get a new mount (the overlay one) where you can find all the files in your readonly area, but that you can still modify. Does that clear it up? – filbranden Aug 15 '18 at 8:17
  • @ransh From the blog post you mentioned: "Now you can still write to lower-file.txt in the overlay filesystem even though it only appears because it is in the lower filesystem. This is because any changes you make are actually made in the upper filesystem." In other words, /tmp/overlay is merging the two of them, shows you the contents of the readonly lower layer, but if you modify anything, that goes into the writable upper layer. – filbranden Aug 15 '18 at 8:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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