Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
store_games_on_a_nas [2022/01/30 09:18] – added warning about using passwords in NASes ataristore_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
Line 2: Line 2:
  
 Instead of using the internal storage or an external USB key/hard drive to store your userdata (games, saves, configuration, etc.), you can use a NAS (Network Attached Storage) instead. Instead of using the internal storage or an external USB key/hard drive to store your userdata (games, saves, configuration, etc.), you can use a NAS (Network Attached Storage) instead.
-Of course you can also use your NAS as a backup target for all of your userdata and games for desaster recovery of your Batocera system as described below, just in case of...well...you name it. 
  
 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 =====
Line 17: Line 22:
  
 There are the pre-defined keywords you can use: There are the pre-defined keywords you can use:
-  * For the whole user data directory''SHARE'' + 
-  * For the roms directory''ROMS'' +^ Keyword ^ Description ^ 
-  * For the bios directory''BIOS'' +| ''SHARE''For the whole user data directory. | 
-  * For the saves directory''SAVES'' +''ROMS'' For the ''roms'' directory. | 
-  * For custom menu background music''MUSIC'' +''BIOS'' For the ''bios'' directory. | 
-  * For custom bezels''DECORATIONS'' +''SAVES'' For the ''saves'' directory. | 
-  * For screenshots taken in game or with ''batocera-screenshot'', ''SCREENSHOTS'' +''MUSIC'' For custom menu background music. | 
-  * For themes, ''THEMES'' +''DECORATIONS'' For custom bezels. | 
-  * For cheats databases, ''CHEATS'' +''SCREENSHOTS'' For screenshots taken in game or with ''batocera-screenshot''. | 
-  * For sounds, ''SOUNDS'' (v32 and above) +''THEMES'' | For themes. | 
-  For magazine and videos''LIBRARY'' +''CHEATS'' For cheat databases. | 
-  * For the boot splash, ''SPLASH''+''SOUNDS'' | For sounds (**v32** and above). | 
 +| ''LIBRARY''For magazine and videos. | 
 +''SPLASH'' For the boot splash. |
  
 You can add any combination of the above (except ''SHARE'' as that includes everything) by adding additional lines. You can add any combination of the above (except ''SHARE'' as that includes everything) by adding additional lines.
Line 38: Line 45:
 ==== For Samba ==== ==== For Samba ====
  
-''%%@[IP-address]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%''+''%%@[IP-address/hostname]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%''
  
 Then add the @ symbol, the IP address/hostname of the device with the share, the : character, the name of the share followed by a /, then the path to the directory (using Unix syntax / instead of \), another : character and then any additional options required for the share separated by a comma (,) (guest shares need only '':guest'' as an option, password protected shares need '':username=[your-username],password=[your-password]''). Syntax: Then add the @ symbol, the IP address/hostname of the device with the share, the : character, the name of the share followed by a /, then the path to the directory (using Unix syntax / instead of \), another : character and then any additional options required for the share separated by a comma (,) (guest shares need only '':guest'' as an option, password protected shares need '':username=[your-username],password=[your-password]''). Syntax:
  
-''%%sharenetwork_[smb-or-nfs][0-9]=[keyword]@[IP-address]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%''+''%%sharenetwork_[smb-or-nfs][0-9]=[keyword]@[IP-address/hostname]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%''
  
 ==== For NFS ==== ==== For NFS ====
Line 48: Line 55:
 ''%%@[IP-address]:[/absolute/path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' ''%%@[IP-address]:[/absolute/path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%''
  
-Examples below.+Examples are [[#samba/windows_share_examples|below]]. If you don't know the exact address to your share already, check the [[#discover_network_share_names|discover network share names section below]].
  
 <WRAP center round important> <WRAP center round important>
Line 55: Line 62:
  
 ===== Samba/Windows share examples ===== ===== Samba/Windows share examples =====
 +
 Windows shares can use identification or a guest account to connect. Windows shares can use identification or a guest account to connect.
  
Line 62: Line 70:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_smb1=SHARE@192.168.0.1:Documents/batocera:guest+sharenetwork_smb1=SHARE@192.168.0.1:Documents/batocera:guest
 </code> </code>
  
Line 69: Line 77:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest+sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest
 </code> </code>
  
Line 84: Line 92:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:username=john,password=wayne+sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:username=john,password=wayne
 </code> </code>
  
Line 91: Line 99:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest +sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest 
-  sharenetwork_smb2=SAVES@192.168.0.1:Documents/batocera/saves:guest +sharenetwork_smb2=SAVES@192.168.0.1:Documents/batocera/saves:guest 
-  sharenetwork_smb3=BIOS@192.168.0.1:Documents/batocera/bios:guest+sharenetwork_smb3=BIOS@192.168.0.1:Documents/batocera/bios:guest
 </code> </code>
  
Line 118: Line 126:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_nfs1=SHARE@192.168.0.1:/mnt/Documents/batocera+sharenetwork_nfs1=SHARE@192.168.0.1:/mnt/Documents/batocera
 </code> </code>
  
Line 125: Line 133:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms:vers=4+sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms:vers=4
 </code> </code>
  
Line 132: Line 140:
  
 <code> <code>
-  sharedevice=NETWORK +sharedevice=NETWORK 
-  sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms +sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms 
-  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>
  
Line 158: Line 193:
 Kodi can be used to see //and// access network shares. You may need [[#discover_network_share_names|your network share's name]] in order to do this. Open Kodi, then navigate to **Files** (a.k.a. **Enter files section**) -> **Files** -> **Add media...** (by default, **Add videos...**) -> **Browse** -> **Add network location...**. Kodi can be used to see //and// access network shares. You may need [[#discover_network_share_names|your network share's name]] in order to do this. Open Kodi, then navigate to **Files** (a.k.a. **Enter files section**) -> **Files** -> **Add media...** (by default, **Add videos...**) -> **Browse** -> **Add network location...**.
  
-{{:screenshot-2022.01.28-15h16.44.png?600|}} {{:screenshot-2022.01.28-15h16.51.png?600|}} {{:screenshot-2022.01.28-15h16.56.png?600|}} {{:screenshot-2022.01.28-15h17.01.png?600|}}+{{:screenshot-2022.01.28-15h16.44.png?720|}} {{:screenshot-2022.01.28-15h16.51.png?720|}} {{:screenshot-2022.01.28-15h16.56.png?720|}} {{:screenshot-2022.01.28-15h17.01.png?720|}}
  
 From here, enter the network share name (and your username and password if you don't have guest/anonymous access enabled on your NAS): From here, enter the network share name (and your username and password if you don't have guest/anonymous access enabled on your NAS):
  
-{{:screenshot-2022.01.28-15h17.57.png?600|}}+{{:screenshot-2022.01.28-15h17.57.png?720|}}
  
 <WRAP center round tip> <WRAP center round tip>
 In the case that you don't know the name of the networked device (or one isn't available because your router has hostnames disabled/a very strict firewall) it is still possible to discover the IP address of the networked device from here. In the case that you don't know the name of the networked device (or one isn't available because your router has hostnames disabled/a very strict firewall) it is still possible to discover the IP address of the networked device from here.
  
-Instead of going to **Add network location...**, instead go to **Zeroconf browser**. You will be shown a list of all devices. Select the one you wish to use, and if a username/password is require you will be prompted for one. After that, continue following the steps as usual, replacing the share name with the IP address you will be shown.+Instead of going to **Add network location...**, instead go to **Zeroconf browser**. You will be shown a list of all devices. Select the one you wish to use, and if a username/password is required you will be prompted for one. After that, continue following the steps as usual, replacing the share name with the IP address you will be shown.
 </WRAP> </WRAP>
  
 Your share will be added to the list of browseable devices, navigate to it (in this example, ''%%smb://RASPBERRYPI%%'') and then navigate to the folder you intend to use for Batocera. Your share will be added to the list of browseable devices, navigate to it (in this example, ''%%smb://RASPBERRYPI%%'') and then navigate to the folder you intend to use for Batocera.
  
-{{:screenshot-2022.01.28-15h18.17.png?600|}} {{:screenshot-2022.01.28-15h18.23.png?600|}} {{:screenshot-2022.01.28-15h18.42.png?600|}}+{{:screenshot-2022.01.28-15h18.17.png?720|}} {{:screenshot-2022.01.28-15h18.23.png?720|}} {{:screenshot-2022.01.28-15h18.42.png?720|}}
  
-Note down the file path stated at the bottom of the window, this is the path that should be used when configuring your NAS. eg. Kodi's path ''%%smb://RASPBERRYPI/samsung1tb/Emulation/roms%%'' contains the share using the Samba (smb) protocol with the share name ''RASPBERRYPI'' with the path being ''samsung1tb/Emulation/roms''. The correct configuration lines for ''batocera-boot.conf'' would be:+Note down the file path stated at the bottom of the window, this is the path that should be used when configuring your NAS. eg. Kodi's path ''%%smb://RASPBERRYPI/samsung1tb/Emulation/roms%%'' contains the share using the Samba (smb) protocol with the hostname ''RASPBERRYPI'' with the share name ''samsung1tb'' and the path being ''samsung1tb/Emulation/roms''. The correct configuration lines for ''batocera-boot.conf'' would be:
  
 <code> <code>
Line 200: Line 235:
 === NFS and root permissions === === NFS and root permissions ===
  
-Batocera has a unique ''root'' user, so all files accessed on the share are from the ''root'' user, which can conflict with how your other NFS clients access files. +Batocera has a unique ''root'' user, so all files accessed on the share are from the ''root'' user, which can conflict with how other NFS clients access files. You should check how the file permissions are declared on your NFS server. A common way to make sure your file permissions are managed correctly is to map the file rights to the UID of the user that will access these files locally. Typically, if your NFS shares are defined in ''/etc/exports'' and you want to give access to a user with UID/GID of 1000, you can make it with:
-You should check how the file permissions are declared on your NFS server, but a common way to make sure your file permissions are managed correctly is to map the file rights to the UID of the user that will access these files locally. Typically, if your NFS shares are defined in ''/etc/exports'' and you want to give access to a user with UID/GID of 1000, you can make it with:+
  
 <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.
  
  • store_games_on_a_nas.1643534338.txt.gz
  • Last modified: 4 years ago
  • by atari