1

I am trying to mount wrapfs on top of / in order to intercept all file access on a CentOS 7.4 running on VirtualBox. Simply running mount -t wrapfs / / doesn't do the job and nothing goes through wrapfs.

An email chain suggests using pivot_root. Here is my unsuccessful attempt:

# df -T
Filesystem              Type      1K-blocks      Used  Available Use% Mounted on
/dev/mapper/centos-root xfs        27245572  10640700   16604872  40% /
devtmpfs                devtmpfs    1925092         0    1925092   0% /dev
tmpfs                   tmpfs       1940872         0    1940872   0% /dev/shm
tmpfs                   tmpfs       1940872      8944    1931928   1% /run
tmpfs                   tmpfs       1940872         0    1940872   0% /sys/fs/cgroup
/dev/sda1               xfs         1038336    181844     856492  18% /boot
VB-share                vboxsf   1942808572 658135288 1284673284  34% /media/sf_VB-share
tmpfs                   tmpfs        388176        24     388152   1% /run/user/1000
/dev/sr1                iso9660       57064     57064          0 100% /run/media/bahram/VBox_GAs_5.2.26

# mkdir /newroot
# mkdir /oldroot
# mount /dev/mapper/centos-root /newroot
# mount -t wrapfs /newroot /newroot
# mount --make-rprivate /
# pivot_root /newroot/ /newroot/oldroot/

Result:

  • In the current terminal all file access goes through wrapfs.

  • Running # mount will result: mount: failed to read mtab: No such file or directory.

  • I cannot open any new terminals!

Next, I tried a similar process with unshare -m

mkdir /newroot
mkdir /oldroot
mount /dev/mapper/centos-root /newroot
mount -t wrapfs /newroot /newroot
unshare -m 
pivot_root /newroot/ /newroot/oldroot/
exec chroot .

Result:

Only the current terminal activities goes through wrapfs. Running # mount will result: mount: failed to read mtab: No such file or directory.

Question:

What is the right way of mounting wrapfs on top of / so every file access goes through wrapfs?

Your Answer

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

Browse other questions tagged or ask your own question.