none
New-SmbGlobalMapping samba share for docker is not mounted after host reboot

    Frage

  • Hi,

    How can I persist the

    $creds = Get-Credential 
    New-SmbGlobalMapping -RemotePath \\contosofileserver\share1 -Credential $creds -LocalPath G:

    commands i used to mount a share for the docker containters?
    After every reboot the share is no longer available.
    Apparently no "persistent" parameter is present in the powershell commandlet.

    Thank you
    Francesco

    Freitag, 18. Mai 2018 15:52

Alle Antworten

  • Hi,

    "When using SMB global mapping for containers, all users on the container host can access the remote share. Any application running on the container host will also have access to the mapped remote share."

    And it needs to use the credentials to authenticate with the remote SMB server.  In general when a computer restarts, the cache will usually clear, so that you loose, and may need to recreate again.

    https://blogs.msdn.microsoft.com/clustering/2017/08/10/container-storage-support-with-cluster-shared-volumes-csv-storage-spaces-direct-s2d-smb-global-mapping/

    https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-storage

    In the blog, The commands, "$creds = Get-Credentials" means this command gets a credential object and saves it in the $Creds variable.

    Maybe you could choose to use the specific user name and password, not try the Credentials so that after reboot it could directly to  authenticate  the user and the password.

    There's another forum post about this issue below:

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/35a2d657-c57d-47a1-a670-f2ac51f00ca8/smb-global-mapping-windows-2016-1709-and-server-restarts?forum=winserverfiles

    Kind regards,
    Leon


    Blog: https://thesystemcenterblog.com  LinkedIn:   

    Freitag, 18. Mai 2018 18:35
  • I can use a specific username and password, but how/where do I save the credentials and how do I make the share persistent after reboots?
    Dienstag, 22. Mai 2018 10:37
  • In the blog mentioned above they use the following command to do the mapping:

    $creds = Get-Credentials
    
    New-SmbGlobalMapping -RemotePath \\contosofileserver\share1 -Credential $creds -LocalPath G:

    And instead of using the $creds variable you would put a username and password.

    Kind regards,
    Leon


    Blog: https://thesystemcenterblog.com  LinkedIn:   

    Dienstag, 22. Mai 2018 12:41
  • Thank you, I could read your previous answer as I could read the same answer copypasted in the other thread you linked, but it adds nothing to the topic. Stop copypasting the same answer just to get points please, i get that I have to use hard-coded user and password instead of getting them from the user.

    As you don't seem to know how to do what you said yourself, I created a powershell script so that username and password can be statically read from somewhere other than the user input.

    $user = "domain\username"
    $passFile = "c:\file_with_secured_password.txt"
    $pass = Get-Content $passFile | ConvertTo-SecureString
    $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
    New-SmbGlobalMapping -RemotePath \\host\share -Credential $creds -LocalPath E:

    this works if you manually run the script, but the share is not restored after a reboot unless you run the script again. Having the script run in a scheduled task does not ensure that the share will be mounted before any service starts, so it is worth nothing.

    Anybody has any idea how to make it persistent across reboots?


    Mittwoch, 23. Mai 2018 08:18
  • As far as I know the only way would be to create a task schedule like you mentioned.

    The service you are talking about, could it be changed to delayed start so that the samba share could have time to be mounted before the service runs? Or then maybe create a dependency for the service.


    Kind regards,
    Leon


    Blog: https://thesystemcenterblog.com  LinkedIn:   

    Mittwoch, 23. Mai 2018 08:35
  • Thank you,

    the service is the docker engine. I can probably set it as delayed but it won't ensure that a slow-mounting share will start before. I could probably do this:

    1. remove the docker service from autostart
    2. use a windows service wrapper to run a powershell script
    3. put the mount command at the beginning of the script
    4. put the docker start command line at the end of the script
    5. set the wrapped script service as autostart


    Mittwoch, 23. Mai 2018 09:42
  • The solution you provided sounds like it could work indeed, tell us how it goes!


    Kind regards,
    Leon


    Blog: https://thesystemcenterblog.com  LinkedIn:   

    Mittwoch, 23. Mai 2018 14:28