1

The commands below should be creating a root overlay, such that any modifications to root will appear in /tmp/upper

However as you can see it does not appear to be working. Can anyone suggest what I am doing wrong?

I am following the syntax here: https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

thanks

ubuntu@ip-10-0-0-48:~$ sudo su
root@ip-10-0-0-48:/home/ubuntu# cd /tmp
root@ip-10-0-0-48:/tmp# mkdir upper
root@ip-10-0-0-48:/tmp# mkdir workdir
root@ip-10-0-0-48:/tmp# mount -t overlay overlay -olowerdir=/,upperdir=/tmp/upper,workdir=/tmp/workdir  /
root@ip-10-0-0-48:/tmp# touch /floob
root@ip-10-0-0-48:/tmp# ls /
bin  boot  dev  etc  floob  home  initrd.img  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var  vmlinuz  x
root@ip-10-0-0-48:/tmp# ls /tmp/upper/
root@ip-10-0-0-48:/tmp#
Duke Dougal
  • 1,025
  • 4
  • 18
  • 28
  • You are asking the same question as this one. Where did you get the idea that mounting to / will succeed? Certainly not from the referenced document. You can mount elsewhere and chroot. – techraf Dec 13 '16 at 07:40
  • @techraf You can certainly mount an overlayfs filesystem to /. It's a pretty common scenario. – Gilles 'SO- stop being evil' Dec 13 '16 at 22:59
  • But I'm not sure if you can do it directly. You may have to mount it on a subdirectory and chroot into it. At least that's what overlayroot does. – Gilles 'SO- stop being evil' Dec 13 '16 at 23:06
  • @Gilles Ok, so what happens to current processes, open files? They suddenly switch to the overlay-mounted root? Regarding your second comment, you are repeating my words ("month elsewhere"). I am confused now. – techraf Dec 13 '16 at 23:16
  • @techraf Open files keep using the lower filesystem, no matter how you do it. That's why an overlay root is usually established from by the initramfs. – Gilles 'SO- stop being evil' Dec 13 '16 at 23:24
  • @Gilles I'm not getting English. I asked OP for the source and then wrote "You can mount elsewhere and chroot" and you responded with "You may have to mount it on a subdirectory and chroot into it." These two sentences are exactly the same (aren't they?). What was your intention? – techraf Dec 13 '16 at 23:29

1 Answers1

0

In the end I just created a bunch of overlays, one for each of the top level directories that I was interested in.

The point of the exercise was to isolate changes made during package installation and this seems to do it well enough for the most part.

#/bin/bash
array=( lib home opt bin boot var etc usr srv lib64 root sbin  )
mkdir -p /ovl
cd /ovl
rm -rf /ovl/overlay
rm -rf /ovl/workdir
mkdir -p /ovl/overlay
mkdir -p /ovl/workdir

for i in "${array[@]}"
do
  mkdir -p /ovl/overlay/${i}
  mkdir -p /ovl/workdir/${i}
  mount -t overlay overlay -o lowerdir=/${i},upperdir=/ovl/overlay/${i},workdir=/ovl/workdir/${i} /${i}
done
Duke Dougal
  • 1,025
  • 4
  • 18
  • 28