Linking or importing existing photo files to Synology Photos folder without duplicating space on BTRFS
Aug 30, 2024
5 min read
If you, like me, have a Synology NAS and use Synology Photos to manage your photos, you might have faced the problem of adding existing photo files to Synology Photos from another folder in your NAS (different and outside of your Synology Photos folder) without actually coping or duplicating them, which will took more disk space. In this article, I'll show you exactly that, but you will need a volume with the BTRFS file system.
Context, what was my problem I was trying to solve
I recently returned from a long trip to England and Scotland. I took tons of photos with my camera, as did my girlfriend with her phone. Back at home, I wanted to create a macro album of all the photos we took in Synology Photos, that is what we use at home for our memories together. They were thousands of photos (+5000!), and they were in tons of different folders. I like to separate photos I took with my camera in folders by day and location/activity, all inside my user's Synology Photos folder. The photos my girlfriend took with her phone are in her MobileBackup
folder within her user space. I took a few photos with my phone too, and they are in my own MobileBackup
folder.
We could manually select the photos and add them to a shared album, and even when you can select multiple photos from a folder to add to an album at once, you must select all of them folder by folder. You cannot select a folder and add all photos there to an album. So as I had a lot of folders with photos because of how I organize the ones took with the camera, it was a tedious process. And also, I have set Synology Photos to show RAW files from the camera, but I didn't those to appear in the macro album, so I would need to manually discriminate RAW files from JPEGs manually for thousands of photos, which is inviable.
So I decided to create a conditional album and select the folders in which I have all my camera photos, plus my MobileBackup
folder and my girlfriend's MobileBackup
folder, and filter it to do not include RAW files. And here is where the problem arises: I could not access my girlfriend's MobileBackup
folder from my user space. Also, my girlfriend, that has a much simpler setup than me (all photos being .heic
and being in the same folder, so could multi-select and add at once), could not manually add her photos to the album, as conditional albums doesn't allow manually adding photos.
So after a lot of Google searches to know what could I do to fix this problem, I found this Reddit post.
What didn't work
My initial idea, as a long time Linux nerd and user, was to use symlinks to link her files to my user space, that I should be able to read as we share a linux user group for that. But Synology Photos doesn't follow symlinks, so that didn't work.
As I saw in the Reddit post from Arnout, he tried also a bid mount. This achieves something similar, but requires the mount to be set up at boot every time (in /etc/fstab
or in some boot scripts such as rc.local
). This is not as clean, but can be used as a sort of a hack to fool applications which otherwise would not want to follow symlinks). However, this didn't work neither.
This leaves us with two possible solutions: hard links and BTRFS CoW (reflink), which are filesystem-specific features.
The solution
I also had a BTRFS volume, so I decided to try the reflink method. What this does is that it "duplicates" the file, but it doesn't actually duplicate the data, it just creates a new metadata entry for the file, and the data is shared between the two files. Once one of the files get modified, then an actual copy is made and they stop sharing data. This is a feature of BTRFS, and it is called Copy-on-Write (CoW). This is the same feature that allows you to take snapshots of your filesystem without actually duplicating the data.
To achieve this, we can just use the cp
command:
cp --reflink=always -R /volume1/teammap/oldbackupfolder /volume1/photo/oldpictures
In my case, what I did was:
cp --reflink=always -R \
/volume1/homes/girlfriend/Photos/MobileBackup/iPhone/2024/08/ \
/volume1/homes/myuser/Photos/Girlfriend_UK_Trip
Then, I was able to select Girlfriend_UK_Trip
folder to the conditional album, and all photos were there, without actually duplicating the space taken.
Caveats
There a few caveats to know here:
- This only works with BTRFS volumes. If you don't have a BTRFS volume, you can't use this method. However, hard links might work, but I didn't test it.
- Files need to be on the same volume. If you want to link files from different volumes, you will need to use a different method.
- This won't be useful if files are being modified constantly, or might be modified in the future. If you modify one of the files in the original folder, the CoW in the photos folder will not get the changes, and it will occupy new extra space, as the data is not shared anymore.
If this is something you can live with, then you can use this method to link or import existing photo files to Synology Photos folder without duplicating space on BTRFS. Otherwise, it might be worthy to study other solutions, such as a shared folder between users.
Now what?
That's all. Thanks for reading this article! If you, like me, are in love with your Synology NAS, you might find interesting other articles I wrote for it. Check them out!