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==
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 17

  • @jameso7826
    @jameso7826 25 วันที่ผ่านมา +1

    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

    • @Automation-Avenue
      @Automation-Avenue  25 วันที่ผ่านมา +1

      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

  • @codescholar7345
    @codescholar7345 17 วันที่ผ่านมา

    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!

  • @cozmickitty7730
    @cozmickitty7730 28 วันที่ผ่านมา +2

    Most frustrating thing for me(newb) is passing devices/data to containers. This is helpful, thanks

    • @Automation-Avenue
      @Automation-Avenue  25 วันที่ผ่านมา

      I agree, it takes a while to get used to.
      Thank you for watching!
      Marek

  • @dermagdermag7642
    @dermagdermag7642 10 วันที่ผ่านมา +2

    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!

    • @Automation-Avenue
      @Automation-Avenue  10 วันที่ผ่านมา +1

      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

  • @safwaniiiiiiz
    @safwaniiiiiiz 27 วันที่ผ่านมา +1

    Thank you so much sir, Really helpful topic

    • @Automation-Avenue
      @Automation-Avenue  25 วันที่ผ่านมา

      I am glad I can help! Thank you for your comment !
      Marek

  • @neilharris
    @neilharris 16 วันที่ผ่านมา

    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

  • @kristof9497
    @kristof9497 27 วันที่ผ่านมา

    Thanks.

  • @monish05m
    @monish05m 21 วันที่ผ่านมา

    Just add mounting options to fstab in host and bind mount that location to lxc container.

    • @Automation-Avenue
      @Automation-Avenue  20 วันที่ผ่านมา

      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!

  • @Jungl3B0b
    @Jungl3B0b วันที่ผ่านมา

    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?

    • @Automation-Avenue
      @Automation-Avenue  19 ชั่วโมงที่ผ่านมา +1

      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

  • @Automation-Avenue
    @Automation-Avenue  25 วันที่ผ่านมา +2

    ***************************
    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