Skip to content

Example usage 'overlayfs' using

    cd /tmp

Create the necessary directories.

    mkdir -p ~/tmp/lower ~/tmp/upper ~/tmp/overlay ~/tmp/workdir

Lets create a fake block device to hold our "lower" filesystem.

dd if=/dev/zero of=lower-fs.assets bs=4096 count=102400
dd if=/dev/zero of=upper-fs.assets bs=4096 count=102400

Give this block device an ext4 filesystem.

mkfs -t ext4 lower-fs.assets
mkfs -t ext4 upper-fs.assets

Mount the filesystem we just created and give it a file.

sudo mount lower-fs.assets ~/tmp/lower
sudo chown $USER:$USER ~/tmp/lower
echo "hello world" >> ~/tmp/lower/lower-file.txt

Remount the lower filesystem as read only just for giggles.

sudo mount -o remount,ro lower-fs.assets /tmp/lower

Mount the upper filesystem

sudo mount upper-fs.assets /tmp/upper
sudo chown $USER:$USER /tmp/upper

Create the workdir in the upper filesystem and the directory in the upper filesystem that will act as the upper directory (they both have to be in the same filesystem)

mkdir /tmp/upper/upper
mkdir /tmp/upper/workdir

Create our overlayfs mount

sudo mount -t overlay -o lowerdir=~/tmp/lower,upperdir=~/tmp/upper,workdir=~/tmp/workdir my-overlay-mount merge

Example usage 'unionfs'

Create needed directories.

mkdir -p ~/tmp/top ~/tmp/lower

Mount in user space 2 directories into directory 'merge'

unionfs-fuse -o cow top=RW:lower=RO merge