Skip to content

Instantly share code, notes, and snippets.

@N-Coder
Last active November 20, 2017 15:47
Show Gist options
  • Save N-Coder/d5ec5356a12d8ee7a9069188e15f75ce to your computer and use it in GitHub Desktop.
Save N-Coder/d5ec5356a12d8ee7a9069188e15f75ce to your computer and use it in GitHub Desktop.
Overlay writable overlayFS on top of read-only Stud.IP FUSE
#!/bin/bash
# Allow root access to FUSE devices mounted with -o allow_root option
# see https://blog.oxplot.com/allow-root-access-fuse-mount/
echo "user_allow_other" >> /etc/fuse.conf
cd ~user/studip
# Start studip-fuse in background and mount at ~user/studip/lower
studip-fuse --user user12 --format "{semester-lexical}/{course}/{type}/{short-path}/{name}" --mount ./lower --allowroot &
# Create sibling directories for overlayFS
mkdir upper work merged
# Mount overlayFS kernel driver,
# - using "lower" directory from studip-fuse as read-only lower layer,
# - writing changes to regular "upper" directory,
# - storing config in regular "work" directory,
# - and providing access to the merged directory tree (i.e. mounted) under "merged".
# see https://wiki.archlinux.org/index.php/Overlay_filesystem
mount -vt overlay overlay -o lowerdir=lower,upperdir=upper,workdir=work,redirect_dir=on merged
@N-Coder
Copy link
Author

N-Coder commented Nov 18, 2017

In order to get updates from Stud.IP, restart the fuse driver and run something like the following script to find files that were overwritten in the overlayFS while also being updated online :

rsync --recursive --times --update (--existing) --backup --suffix=$(date +"%F_%R") --itemize-changes -vh lower merged

One could use a further script to process the output of a dry-run of the rsync, renaming the files in upper which would otherwise be renamed for backup in merged.
The copy and create operations can be ignored, as the original file path now is no longer present in upper, and thus the updated file from lower 'shines' through again.
This approach doesn't handle overlayFS whiteouts (deletions) and renames correctly, though.

@N-Coder
Copy link
Author

N-Coder commented Nov 18, 2017

To unmount:

fusermount -u lower
sudo umount merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment