Mounting SMB Share from VM Automatically Once VM is Started

shuggsy

New Member
Nov 23, 2022
2
0
1
I've been setting up Proxmox VE (thanks for such a great tool!) on my home server and have hit a wall with some resource sharing/mounting. I tried searching around and did not find anything really addressing this issue. That makes me somewhat worried I am going about this the wrong way, but all advice is appreciated!

What I want to do is have my media container (ubuntu 22.04 LXC running Jellyfin) access media on my NAS storage (shared via an SMB share from a VM running TrueNAS Scale on the same machine).

As far as I understand it, I need to mount the SMB share on the host (ie. Proxmox) and then provide that as a mount point to the Jellyfin LXC. I can do this running console commands on the host once everything is up and then manually starting the Jellyfin LXC, but I would like to have all this mounted up automatically whenever the box gets rebooted. This is just on a home server and at present I'm rebooting it semi-regularly as I fiddle around with things.

I tried putting an entry in /etc/fstab and that worked if I tried mounting everything (via mount -a or similar once the machine we up. However, this fails at boot. This made sense after I saw the error as the TrueNAS VM - and the SMB server running on it - would not have been running when the machine was first booting.

I then tried a hookscript. The example hookscript has a "post-start" section that seemed appropriate for this. I added a system call to run a mount console command once in the post-start phase but this also failed. The command works if I simply run it on the console of the host. The error message given was mount error(11): Resource temporarily unavailable. I _think_ this is because the SMB server had not had time to start even though the VM had started and reached the "post-start" phase, but I am not sure.

I then tried adding a sleep of 10 seconds in the hookscript in an attempt to let the VM start the SMB server (assuming that is the problem) but this did not resolve the issue. Similarly, a sleep of 30 seconds did not resolve the issue. DMESG reports:
[17099.139705] CIFS: Attempting to mount \\<server IP>\data-share [17100.959676] CIFS: VFS: \\<server IP> Send error in SessSetup = -11 [17100.959694] CIFS: VFS: cifs_mount failed w/return code = -11

Any help or ideas of how I can automate the mounting of an SMB share once the TrueNAS VM and SMB server has come online would be greatly appreciated! Or perhaps I'm asking the wrong questions and going about this entirely the wrong way. Any advice is appreciated!

Thanks!
 
Quick follow-up to this. I did get the auto-mounting working successfully although the solution I found doesn't feel as elegant as it seems like it should be.

Rather than tie mounting the SMB share to the TrueNAS VM, I tied it to the Jellyfin CT. I again used a hookscript. I removed the hookscript from the TrueNAS VM and added it to the Jellyfin CT. I modified the hookscript to try the mount during the "pre-start" phase of the Jellyfin CT so it will ensure the SMB share is appropriately mounted before starting the Jellyfin CT. I also modified the startup order so that the TrueNAS VM starts first and the Jellyfin CT starts second. Additionally, I added a 120 second startup delay to the TrueNAS VM so Proxmox will wait two minutes before trying to start the Jellyfin CT. I have no need to rush the startup of Jellyfin - I'm more concerned that the TrueNAS VM has appropriate time to get the SMB server started. I could likely pull this delay in through some empirical testing but I'll save that for another day.

There's more that I could add to the hookscript to explicitly test that the mount succeeded and maybe abort the CT startup if not, but so far at least the mount command succeeds. Similarly, removing the mount if no needed for Jellyfin or other containers is also possible to do in the cleanup of the CTs/VMs, but I haven't set that up.
 
Quick follow-up to this. I did get the auto-mounting working successfully although the solution I found doesn't feel as elegant as it seems like it should be.

Rather than tie mounting the SMB share to the TrueNAS VM, I tied it to the Jellyfin CT. I again used a hookscript. I removed the hookscript from the TrueNAS VM and added it to the Jellyfin CT. I modified the hookscript to try the mount during the "pre-start" phase of the Jellyfin CT so it will ensure the SMB share is appropriately mounted before starting the Jellyfin CT. I also modified the startup order so that the TrueNAS VM starts first and the Jellyfin CT starts second. Additionally, I added a 120 second startup delay to the TrueNAS VM so Proxmox will wait two minutes before trying to start the Jellyfin CT. I have no need to rush the startup of Jellyfin - I'm more concerned that the TrueNAS VM has appropriate time to get the SMB server started. I could likely pull this delay in through some empirical testing but I'll save that for another day.

There's more that I could add to the hookscript to explicitly test that the mount succeeded and maybe abort the CT startup if not, but so far at least the mount command succeeds. Similarly, removing the mount if no needed for Jellyfin or other containers is also possible to do in the cleanup of the CTs/VMs, but I haven't set that up.
For that purposes I am using autofs. It mounts and unmounts shares on-demand.
 
Quick follow-up to this. I did get the auto-mounting working successfully although the solution I found doesn't feel as elegant as it seems like it should be.

Rather than tie mounting the SMB share to the TrueNAS VM, I tied it to the Jellyfin CT. I again used a hookscript. I removed the hookscript from the TrueNAS VM and added it to the Jellyfin CT. I modified the hookscript to try the mount during the "pre-start" phase of the Jellyfin CT so it will ensure the SMB share is appropriately mounted before starting the Jellyfin CT. I also modified the startup order so that the TrueNAS VM starts first and the Jellyfin CT starts second. Additionally, I added a 120 second startup delay to the TrueNAS VM so Proxmox will wait two minutes before trying to start the Jellyfin CT. I have no need to rush the startup of Jellyfin - I'm more concerned that the TrueNAS VM has appropriate time to get the SMB server started. I could likely pull this delay in through some empirical testing but I'll save that for another day.

There's more that I could add to the hookscript to explicitly test that the mount succeeded and maybe abort the CT startup if not, but so far at least the mount command succeeds. Similarly, removing the mount if no needed for Jellyfin or other containers is also possible to do in the cleanup of the CTs/VMs, but I haven't set that up.
any chance of sharing your script?
I have the same problem
Thanks
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!