Network Mounting OctoPrint Data from a NAS
Previously, I described my ‘Ultimate’ OctoPrint setup, and part of that setup process including remounting a lot of OctoPrint folders to locations on my NAS. This setup worked well until I added OctoLapse, and wanted to backup folders not part of the folder path configuration in OctoPrint. To solve this, I used a different approach entirely, using symbolic links instead of a bunch of network mounts to cleanly and easily relocate OctoPrint data to network storage. In this post, I’ll go through this process, without the length of my previous project (which included setup of all of my plugins, building the LED hardware, etc in addition to the network mount blerb).
Video⌗
The corresponding video for this tutorial is below. Click the thumbnail to view it on Youtube.
Installing Software⌗
I started with OctoPi, the Raspberry Pi distribution for OctoPrint. I imaged it on an SD card, booted up the Pi, and ran through the OctoPrint setup and updates. After that, I SSH into the Pi (default username is pi, password raspberry) to configure the netowrk mounts.
The required software to install is autofs. We should do an apt update
and apt upgrade
while we are at it, since the OctoPi distribution is not updated regularly and instead relies on OctoPrint to keep itself (but not necessarily the OS) up to date. At the current point in time OctoPi is still built on Raspberry Pi OS Buster instead of Bullseye, and you will get a warning that the repository has gone from ‘stable’ to ‘oldstable’. Accept the warning and continue.
#Just to be safe, run upgrade and update to make sure we are up to date
sudo apt update
sudo apt upgrade
#Install autofs
sudo apt install autofs
#Check to make sure it runs at boot, the install should have already done this.
sudo systemctl enable autofs
Configure Autofs Mounts⌗
Since I wrote the last blog on this topic, I’ve found that it’s easeiest to mount a single directory from the server, and use symbolic links to point to the sub directories. So, the autofs configuration is pretty simple.
First, edit /etc/auto.master
and add the following line, which points to a yet to be created shares file, and says any shares within that file are mounted relative to /:
/- /etc/auto.smb.shares --timeout 15 browse
Second, create the file (sudo nano /etc/auto.smb.shares
) and add the new share we want to auto mount (copy this line and modify it as necessary):
/mnt/printer -fstype=cifs,rw,username=<user>,password=<password>,noperm,dir_mode=0777,file_mode=0777 ://server/share/directory
Key details here:
/mnt/printer
is the location we are mounting the share on the local system- Replace
<user>
and<password>
with the authentication information you’ve setup on your NAS for this share noperm
,dir_mode
,file_mode
mean that permissions are ignored on the local system. The NAS still enforces file permissions on its side. I found these options are needed for Octolapse to work correctly, since it often tries to chmod files in the timelapse folder for no apparent reason, and without the local system ignoring permissions, Octolapse will often fail to chmod files as it does not own them.- Obviously,
server
andshare
are dependent on your NAS. IP addresses and DNS names also work here for server.
Finally, create the directory at the mount point:
sudo mkdir /mnt/printer
And restart autofs so it reloads the configuration files
sudo systemctl restart autofs
Relocating OctoPrint Directories to the Network⌗
I’ve setup a subsection with the commands for each folder. You can copy/paste whichever sets you need. Run these as user pi. If you are running on a new installation or otherwise don’t want to copy out the existing data, you can omit the rsync step, which copies data out of the old location before deleting it.
Also, you should not share the same printer directory between multiple printers. You should create a different folder on your NAS for each printer, and then create the folder structure underneath that mount point.
Watched⌗
#Create new directory
mkdir /mnt/printer/watched
#Go to location
cd ~/.octoprint
#Delete old directory, watched should be empty already
rm -r watched
#Make link to new directory
ln -s /mnt/printer/watched
Timelapse and Timelapse Temp⌗
This is a good candidate for network mounting.
#Create new directories
mkdir /mnt/printer/timelapse
mkdir /mnt/printer/timelase/tmp
#Go to location
cd ~/.octoprint
#Copy data to new location
rsync -r --progress timelapse/ /mnt/printer/timelapse
#Delete old directory
rm -r timelapse
#Make link to new directory
ln -s /mnt/printer/timelapse
Uploads⌗
If you network mount this directory, do not edit it, let OctoPrint manage it on its own.
#Create new directory
mkdir /mnt/printer/uploads
#Go to location
cd ~/.octoprint
#Copy data to new location
rsync -r uploads/ /mnt/printer/uploads
#Delete old directory
rm -r uploads
#Make link to new directory
ln -s /mnt/printer/uploads
Logs⌗
I’d generally recommend against relocating this folder to the network share, since you won’t get logs at all if the network share is inaccessible (autofs makes the directory inaccessible if it fails to mount). If you really want to reduce SD wear, you could mount the logs directory as a tmpfs or use folder2ram (which creates a tmpfs which is read from the SD card on boot, and written back on clean shutdown). It all depends on how you want to store your logs and what failure conditions you are most concerned about.
#Create new directory
mkdir /mnt/printer/logs
#Go to location
cd ~/.octoprint
#Copy data to new location
rsync -r logs/ /mnt/printer/logs
#Delete old directory
rm -r logs
#Make link to new directory
ln -s /mnt/printer/logs
Backup⌗
You should absolutely mount this folder on the network, to keep your backups safe from SD card failure.
#Create new directory
mkdir /mnt/printer/backup
#Go to location
cd ~/.octoprint/data
#Copy data to new location
rsync -r --progress backup/ /mnt/printer/backup
#Delete old directory
rm -r backup
#Make link to new directory
ln -s /mnt/printer/backup
Octolapse Temp⌗
Note that Octolapse timelapses still go in the timelapse folder after they are rendered, which you can redirect using the normal timelapse commands above. However, the temp folder is in a different location.
#tmp was already created above, no need to create another
#no need to copy tmp either, since it's temporary
cd ~/.octoprint/data/octolapse
#Delete old directory
rm -r tmp
#Make link to new directory
ln -s /mnt/printer/timelapse/tmp