Automatically bind mount NFS/SMB/CIFS share to Proxmox LXC container after reboot with bash script
ฝัง
- เผยแพร่เมื่อ 2 ส.ค. 2024
- We will write a bash script and create a cron job that will automatically mount bind our NAS shares (NFS/SMB/CIFS) running on Proxmox VM to unprivileged LXC containers (also on Proxmox) after reboot.
Please also see previous video:
• Bind mount NAS (CIFS/S...
where we configured that share and LXC container connectivity.
***********
mount.sh script:
#!/usr/bin/env bash
qm start 202
until [ "$(qm status 202 | awk '{print $2}')" == "running" ];
do
sleep 2
done
sleep 20
mount -t cifs -o user=smbuser,password=marekpass //192.168.1.202/MiniPC /mnt/minipc
sleep 20
lxc-start -n 203
**********
crontab -e:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot /usr/bin/bash /opt/scripts/mount.sh
*********
0:00 bind mount that works after reboot
14:00 writing bash script
19:35 creating cron job
Thank you for watching !
marek@automation-avenue.com
==28== - วิทยาศาสตร์และเทคโนโลยี
Very informative, I like the style of your video
I would suggest for anyone that comes here and follows your steps to ls the mount from outside the mount directory during testing. That way you avoid blocking the mount from happening by having that directory locked by your terminal.
i.e:
ls -la /mnt/minipc
instead of
cd /mnt/minipc
ls -la
It's a great advise ! Well - what can I say - my video PROVES that YOUR way is the way to run that command :)
Thank you for watching and for taking the time to comment !
Marek
Bind to container can be done in the GUI too by adding mount point to resources. Thanks the the previous video, I needed it’s solution yesterday!
Most frustrating thing for me(newb) is passing devices/data to containers. This is helpful, thanks
I agree, it takes a while to get used to.
Thank you for watching!
Marek
Great video and very helpful - thanks!
Could you maybe tell / show how to amend the script to mount / unmount an external HDD when starting the PLEX/Jellyfin container? This way you would not need to have an external HDD attached to the Homeserver all the time to watch a movie every now and then.. This would be super helpful - I did not find any tutorials how to do this.. Thanks!
Hi! If you need to mount your disk only when you need to use it then I would check` autofs` tool rather than standard mount which is very limited for that specific use case.
Please see more here: help.ubuntu.com/community/Autofs
Hope that helps !
Thanks for watching - Marek
Thank you so much sir, Really helpful topic
I am glad I can help! Thank you for your comment !
Marek
Hi, i have followed the instructions, but when i try to connect to the share it is Read Only. is there anyway to make this writable
Thanks.
You're welcome !
Just add mounting options to fstab in host and bind mount that location to lxc container.
Can you elaborate? How that would work after reboot when the VM needs to be started first and be fully up and running before you mount anything? I know there are some other possibilities, I am aware you can achieve something similar with autofs, but not sure how you can do that with simple entry in fstab file as I tried and it simply doesnt work so please let me know.
Thank you for your comment!
First of all: Big Thanks to this 2 videos. I have 2 thinks I'm struggeling with.
1) you wrote ...dev/null... in the cronjob but not in your video description.
Does this mean you don't need it or is it just missing in the description?
and the big second one.
For me it does not work because of:
-bash: /opt/scripts/mount.sh: No such file or directory
but its there.....
Someone got a hint for me?
Hi
Yes sorry, only after publishing the video I realized that you cant use angled brackets in the description, so I had to drop that portion of config but yes - it should not have any influence on the script itself, it was just a simple redirection.
You might also be interested in the new video I have just released - Bind mounts vs Volumes - what are they? What's the difference between them? Link below:
th-cam.com/video/keINzeYs_lc/w-d-xo.html
Kind regards
Marek
***************************
mount.sh script:
#!/usr/bin/env bash
qm start 202
until [ "$(qm status 202 | awk '{print $2}')" == "running" ];
do
sleep 2
done
sleep 20
mount -t cifs -o user=smbuser,password=marekpass //192.168.1.202/MiniPC /mnt/minipc
sleep 20
lxc-start -n 203
**************************
crontab -e:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot /usr/bin/bash /opt/scripts/mount.sh