| Both sides previous revision Previous revision Next revision | Previous revision |
| store_games_on_a_nas [2022/06/30 03:40] – table to make it easier to parse atari | store_games_on_a_nas [2024/01/29 20:17] (current) – instructions for mounting network-based /userdata folders that are dependent on an established VPN or Tailscale connection cs |
|---|
| |
| Recommended watching: [[https://www.youtube.com/watch?v=w0tVE24Wmh4|Batocera Nation's advanced features volume 4.]] | Recommended watching: [[https://www.youtube.com/watch?v=w0tVE24Wmh4|Batocera Nation's advanced features volume 4.]] |
| | |
| | <WRAP center round important> |
| | Batocera repeatedly checks for a network connection on boot, and if none is present then it will automatically fall back to using internal storage. It is not possible to switch the location of your userdata without rebooting. If using NAS on a device which has a switch to turn on or off Wi-Fi, keep this fact in mind, as turning off the Wi-Fi will effectively wipe the userdata folder from Batocera's perspective. |
| | |
| | In general, if using Batocera on a portable device it's not recommended to use a local NAS for its storage anyway due to the instability of its Wi-Fi. [[:syncthing|Syncthing]] offers a much more secure method of syncing data between portable devices. |
| | </WRAP> |
| |
| ===== Syntax ===== | ===== Syntax ===== |
| sharenetwork_nfs2=SAVES@192.168.0.1:/mnt/Documents/batocera/saves | sharenetwork_nfs2=SAVES@192.168.0.1:/mnt/Documents/batocera/saves |
| sharenetwork_nfs3=BIOS@192.168.0.1:/mnt/Documents/batocera/bios | sharenetwork_nfs3=BIOS@192.168.0.1:/mnt/Documents/batocera/bios |
| | </code> |
| | |
| | ===== Mounting network shares behind a VPN or Tailscale network ===== |
| | === Background === |
| | Mounting a shared folder on a server that requires a VPN or Tailscale connection to be established first is troublesome due to the Batocera boot initialization process. While Batocera does provide [[:launch_a_script|various options]] for you to execute a custom script throughout the boot process, none of them are suitable due to several factors. The setup procedure in the [[:vpn_client|VPN/Tailscale documentation]] is great for setting up things like multiplayer, but too late for mounting Batocera core folders. |
| | |
| | __Basic boot process flow:__\\ |
| | 1. /boot/boot-custom.sh - At this stage, the system's network has not been initialized yet, therefore a VPN or Tailscale connection cannot be established.\\ |
| | 2. /etc/init.d/S07network - This is where the network is initialized.\\ |
| | 3. /etc/init.d/S11share - This is where the /userdata is initialized.\\ |
| | 4. /boot/postshare.sh - Executed right after /userdata initialization completed. By this point it is too late, and any attempts to mount a VPN/Tailscale network share will fail because those services haven't been initialized yet.\\ |
| | 5. /userdata/system/custom.sh - This script is the suggested place for VPN/Tailscale initialization according to the docs, but it's also past the /userdata mounting stage.\\ |
| | |
| | From the above, we can see that the VPN/Tailscale client will need to be initialized somewhere between steps 2 and 3. |
| | |
| | === Workaround === |
| | There is a [[:store_games_on_a_nas#samba_windows_manually_mounted_shares|sharenetwork_cmd# feature]] that allows you to craft a custom mounting command, however, since it accepts any arbitrary shell command we can repurpose it to initialize our VPN/Tailscale client. |
| | |
| | First, setup and test the VPN/Tailscale client according to the [[:vpn_client|docs]]. Once you have successfully confirmed that everything is working, disable ''custom.sh'' or comment out the lines relevant to VPN/Tailscale. Those clients are going to be initialized elsewhere. |
| | |
| | The final result of my configuration looks something like the below. Note that in my example, I am using Tailscale and mounting NFS folders, although this should be adaptable for any combination of VPN/Tailscale and SMB/NFS. Also, in my example, I am incorporating an [[:vpn_client#my_vpn_works_fine_on_my_pc_but_not_on_my_raspberry_pi_other_sbc|ARM-build fix]] where the /dev/net folder needs to be created in addition to a "sleep 2s" command because I have observed that the Tailscale daemon sometimes does not finish initializing before the Tailscale client asks it to bring up the network. Adjust these items according to your setup. |
| | <code> |
| | sharedevice=NETWORK |
| | sharenetwork_cmd1=eval if [ ! -d /dev/net ]; then mkdir -p /dev/net; mknod /dev/net/tun c 10 200; chmod 600 /dev/net/tun; fi && /userdata/tailscale/tailscaled -state /userdata/tailscale/state > /userdata/tailscale/tailscaled.log 2>&1 & sleep 2s; /userdata/tailscale/tailscale up --accept-routes |
| | sharenetwork_nfs1=ROMS@100.0.0.1:/mnt/Documents/batocera/roms |
| | sharenetwork_nfs2=SAVES@100.0.0.1:/mnt/Documents/batocera/saves |
| | sharenetwork_nfs3=BIOS@100.0.0.1:/mnt/Documents/batocera/bios |
| </code> | </code> |
| |
| /media/games/batocera 192.168.0.1(rw,sync,all_squash,anonuid=1000,anongid=1000,no_subtree_check) | /media/games/batocera 192.168.0.1(rw,sync,all_squash,anonuid=1000,anongid=1000,no_subtree_check) |
| </code> | </code> |
| | |
| | ===== Troubleshooting ===== |
| | |
| | Logs for share mounting specifically can be found at ''/tmp/mountDevicesOrNetwork.err'' after booting. If a network share is failing to be booted, Batocera will retry the connection a few times before falling back on internal storage. |
| |