So I have been meaning to finish up this series for a while now, but other things got in the way (which hopefully I can post on here soon). In the mean time, there are numerous tutorials on-line now about how to set a Pi up as a home file server, so I think I will defer to those instead of wasting more bits on the Internet. However, I would like to point out some things I have done that has resulted in my Pi setup being nice and stable.
This biggest thing to do when using the SD card as the root file system for the Pi is to minimize the number of writes to it. This will help keep it lasting longer and avoid any file system corruption. One thing you can do is modify your /etc/fstab and use the noatime family of attributes. The default of most Pi distributions is ext3/4, so this should work for you. First find your entry in the /etc/fstab for your /. In mine below, you can see it’s /dev/mmcblk0p2:
proc /proc proc defaults 0 0 /dev/mmcblk0p2 / ext4 defaults 0 1 /dev/mmcblk0p1 /boot/ vfat defaults 0 2 /dev/md0 /mnt/filestore xfs defaults,nofail 0 2
Change line 2 so that it reads like this:
/dev/mmcblk0p2 / ext4 defaults,noatime,nodiratime 0
This will stop the file system from modifying itself each time a directory or file is accessed.
As you can see from my fstab, I also have my RAID partition on the enclosure set to xfs and I use the nofail attribute. This is very important since your enclosure may not be fully spun up and ready by the time your Pi tries to mount it. If it’s not there, the Pi will hang (forever in my case since it will cause the kernel to panic).
I also run mariadb and postgresql with postgis on the Pi3, however I have them set to not autostart by running:
systemctl disable mysqld systemctl disable postgresql
I could leave them running since I’ve lowered their memory requirements, but choose to only have things running on the Pi 3 whenever I need it to make sure I don’t run out of memory.
I put their respective data directories on the NAS and then made a soft link under /var by running;
ln -s /mnt/filestore/data/mysql /var/lib/mysql ln -s /mnt/filestore/data/postgresql /var/lib/postgresql
You could edit their config files to change the location, but for me I have found it is easier to simply use soft links. Plus, since the servers are not set to start a boot, I do not have to worry about any errors every time the Pi restarts.
I also run recoll on the Pi as I have collected several hundred gigabytes of papers and ebooks over the years. Recoll is a nice utility that provides a semantic search ability. By default, recoll and run your file system and system itself into the ground if you let it. I made a few tweaks so that would play nice whenever I run it periodically on the Pi. The first thing I did was move the ~/.recoll directory to the NAS and create a soft link by running
ln -s /mnt/filestore/data recoll .recoll
Again, the goal is to reduce the number of file system access to the SD card itself. Secondly, I created the .recoll/recoll.conf file with the following contents:
topdirs = /mnt/filestore/data/Documents /mnt/filestore/data/ebooks /mnt/filestore/data/Programming filtermaxseconds 60 thrQSizes = -1 -1 -1
The filtermaxseconds parameter tells recoll to stop indexing a file if the filter runs for a whole minute. The thrQSizes option has recoll use a single thread. While this makes it slower, it makes things run much better on the Pi while still allowing other services to run.
If you want to run other services, keep in mind that if they do a lot of I/O, you should move them to your external drive and use a soft link to redirect like I did above. Doing so will help to greatly extend the life of your SD card and keep you from having to reimage it.