overlayfs merge upper to lower possibility

Moderator: Forum moderators

Post Reply
ozsouth
Posts: 1660
Joined: Sun Jul 12, 2020 2:38 am
Location: S.E. Australia
Has thanked: 251 times
Been thanked: 748 times

overlayfs merge upper to lower possibility

Post by ozsouth »

I saw this & thought it could be used as a sort of pupmode 13:

(From: https://unix.stackexchange.com/question ... ect=1&lq=1)

Merge changes to upper filesystem to lower filesystem in Linux Overlay (OverlayFS) mount

==Explanation==

... use Btrfs snapshots to merge the upper and lower directories. A Btrfs subvolume works almost exactly like a directory, but we snapshot (clone) a subvolume and it takes no extra disk space. Then rsync the contents of the Overlayfs to the snapshot, and it will only use as much disk space as doubling the upper directory. After rsync is complete, then the original lower and upper directories can be discarded, and replaced by the new snapshot and a new (empty) upper directory.

==Steps==

1. Create a Btrfs subvolume as the lower directory (after some days or weeks, when you're ready to merge, then go to step 2)
2. Take a (writable) snapshot of the lower directory.
3. While the Overlayfs is mounted, use rsync to synchronize all changes from the Overlayfs to the snapshot.
4. Unmount the Overlayfs.
5. Delete the lower directory
6. Replace the previous lowerdir with the new snapshot.
7. Delete the upper directory.
8. Recreate a new (empty) upper directory.
9. Remount the Overlayfs filesystem.

==Steps as terminal commands (untested!)==

1# btrfs subvolume create lowerdir
2# btrfs subvolume snapshot lowerdir lowerdir_new
3# rsync --delete -a overlayfs lowerdir_new
4# umount overlayfs
5# btrfs subvolume delete lowerdir
6# mv lowerdir_new lowerdir
7# rm -rf upperdir
8# mkdir upperdir
9# mount -o lowerdir

A Btrfs snapshot IS a new subvolume, so this process can be repeated unlimited times.

Post Reply

Return to “Filesystem”