A Guide for Auto-Mounting Azure Storage Network Drive for Linux Server with Start-up Script

Sometimes when you deploying a VMSS, you need to make sure all the setting is set in your custom image, basically, VMSS will need to mount a shared network drive for multiple instance purpose.

You can view this blog to see how to get use of Linux Start-up script to enable auto-mounting Azure Storage network drive.

StepsProcedures
1Mounting the network drive for first time ONLY:   Linux Mount Point Name: shopify     sudo mkdir /mnt/shopify if [ ! -d “/etc/smbcredentials” ]; then sudo mkdir /etc/smbcredentials fi if [ ! -f “/etc/smbcredentials/shopifstorage.cred” ]; then     sudo bash -c ‘echo “username=shopifstorage” >> /etc/smbcredentials/shopifstorage.cred’     sudo bash -c ‘echo “password=O/IzHVrZFcu5R1lANy/A8PUNfVMBxxcgdgsdrgru0eCAEBnpuBvW9inp1gCoUtehAevqZOON5zU7IDw6xXPVS65m6g==” >> /etc/smbcredentials/shopifstorage.cred’ fi sudo chmod 600 /etc/smbcredentials/shopifstorage.cred   sudo bash -c ‘echo “//shopifstorage.file.core.windows.net/shopify /mnt/shopify cifs nofail,vers=3.0,credentials=/etc/smbcredentials/shopifstorage.cred,dir_mode=0777,file_mode=0777,serverino” >> /etc/fstab’ sudo mount -t cifs //shopifstorage.file.core.windows.net/shopify /mnt/shopify -o vers=3.0,credentials=/etc/smbcredentials/shopifstorage.cred,dir_mode=0777,file_mode=0777,serverino    
2Un-Mounting the network drive:   Linux Mount Point Name: shopify   umount /mnt/shopify  
3Verify the mount point whether is unmount by using the following command:   df -h  
StepsProcedures
1Create the custom start-up script named “start-up.sh” in path “/etc/init.d/start-up.sh”   Sample Command: sudo nano /etc/init.d/start-up.sh    
2Linux Mount Point Name: shopify Edit the start-up service script content with the following:   #!/bin/bash   sudo bash -c ‘echo “//shopifstorage.file.core.windows.net/shopify /mnt/shopify cifs nofail,vers=3.0,credentials=/etc/smbcredentials/shopifstorage.cred,dir_mode=0777,file_mode=0777,serverino” >> /etc/fstab’ sudo mount -t cifs //shopifstorage.file.core.windows.net/shopify /mnt/shopify -o vers=3.0,credentials=/etc/smbcredentials/shopifstorage.cred,dir_mode=0777,file_mode=0777,serverino    
3Save and exit the script  
4Modify the permission for the start-up script   sudo chmod +x /etc/init.d/start-up.sh    
StepsProcedures
1Edit the start-up service of the start-up script   sudo nano /etc/systemd/system/my-startup.service  
2Edit the start-up service script content with the following:   [Unit]
Description=Mount Network Drive     [Service]
ExecStart=/etc/init.d/start-up.sh     [Install]
WantedBy=multi-user.target    
3Check the current status for the start-up service of the start-up script   systemctl status my-startup.service    
4Enable the start-up service of the start-up script   sudo systemctl enable my-startup.service    
Eric Chan
| + posts

Microsoft MVP
SOS Group Limited

Leave a comment

SOS Group Limited © 2022. All Rights Reserved.