On 22.02.2024 10:01, Christian Brauner wrote:
On Thu, Feb 22, 2024 at 07:19:00AM +0100, Rafał Miłecki wrote:
Hi,
I'm trying to use overlay to create temporary virtual root filesystem.
I need a copy of / with custom files on top of it.
To achieve that I used a simple mount like this:
mount -t overlay overlay -o lowerdir=/,upperdir=/tmp/ov/upper,workdir=/tmp/ov/work /tmp/ov/virtual
In /tmp/ov/virtual/ I can see my main filesystem and I can make temporary
changes to it. Almost perfect!
The problem are mounts. I have some standard ones:
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)
They are not visible in my virtual root:
# ls -l /tmp/ov/proc/
# ls -l /tmp/ov/sys/
# ls -l /tmp/ov/tmp/
(all empty)
Would that be possible to make overlayfs follow such mounts in lowerdir?
No, this doesn't work:
* overlayfs does clone mounts recursively
* procfs can't be used as a lower layer
So they would need to be bind-mounted on top of these locations.
Can I bind mount /tmp/ to my temporary virtual root and still make use
or overlay to don't touch underlaying system?
If I do:
mount -o bind /tmp /tmp/ov/virtual/tmp
then writing anything to /tmp/ov/virtual/tmp/ would affect original tmp.