I am trying to aggregate two mount points in to a single directory so that it will combine the files from both in to a single mountpoint. I am doing some tests with overlayfs and have been able to create the merged mountpoint, but the issue comes when I delete files from this merged directory.
I understand that overlayfs has an upper and a lower filesystem and that if you delete something from the lower that it creates a "whiteout" on the upper filesystem that basically just hides the file from the lower from "shining through" to the merged layer. The file still occupies space on the lower filesystem; it's just not presented as available.
My question is: how do I delete a file from both the upper and lower filesystems and reclaim the space used by the deleted file, and not just hide it? I can manually delete the file from the merged directory and then from the lower directory (is this a bad thing to do?) but
df -ha still shows the merged directory as taking up space:
none 6.8G 1.9G 4.6G 30% /var/www/merged /dev/loop0 380M 2.3M 354M 1% /mnt/lower1 /dev/loop1 380M 2.3M 354M 1% /mnt/lower2 /dev/loop2 380M 2.3M 354M 1% /mnt/upper none 380M 2.3M 354M 1% /mnt/merged
What's the correct way to delete files from an overlayfs filesystem and properly report an accurate disk usage?