Using a differencing, aka overlay, aka union, file-system with commit capability

filesystemsflash-memorymountusb

I work in two PCs and I sync all my files from my primary PC to a USB flash memory. In my second PC, I mount the USB flash memory to the same path to work on my files as I were on my primary PC.

Now for the sake of performance and flash memory lifetime, I need to use any type of differencing, aka overlay, aka union, file-system (like unionfs or aufs) to let me use the USB flash disk as read-only and write changes to a temp directory and at the end allows me to write the changes back to the USB flash at once.

Any help?
Any hope?

Update:

Thanks for all your answers and comments. I am interested in Linux and my question is: Does any of the above file-systems allow committing the writes to the lower file-systems when required? If yes, how?

Best Answer

There is a new dm target called "snapshot-merge".

If you format your USB flash memory as a LVM physical volume, and then locate your desired filesystem atop it in a logical volume, you can

  1. Activate a volume group containing your USB flash memory and another LVM physical volume on a local disk.
  2. Create a snapshot of the logical volume on the local disk.
  3. Mount the snapshot, do whatever you want with it, then umount it.
  4. Merge the snapshot back to the origin.

This should achieve close to what you've asked for, although it requires a scratch block device rather than a temporary directory.


Substitute the parts enclosed in {braces} as appropriate.

# Initial setup of the USB drive.
pvcreate /dev/{USB}
vgcreate {removable} /dev/{USB}
lvcreate -n {base} -l 100%PVS {removable} /dev/{USB}
mkfs -t {fs} {...} /dev/mapper/{removable}-{base}
# Initial setup of the scratch device.
pvcreate /dev/{SCRATCH}
# Mounting the device.
vgextend {removable} /dev/{SCRATCH}
lvcreate -s -n {snap} -l 100%ORIGIN /dev/mapper/{removable}-{base} /dev/{SCRATCH}
mount -t {fs} -o {...} /dev/mapper/{removable}-{snap} {MOUNTPOINT}
# Unmounting the device.
umount {MOUNTPOINT}
lvconvert --merge /dev/mapper/{removable}-{snap}
vgreduce {removable} /dev/{SCRATCH}
vgchange -a n {removable}

Untested, but all the LVM commands have manpages so you should be able to figure things out from here. You might need a vgscan invocation in there somewhere, if the volume group doesn't get automatically detected when you plug the USB drive in.

Related Question