如何将 azure 文件共享挂载到 linux vm 上的现有目录

How to mount azure file share to existing directory on linux vm

我在 /etc/elasticsearch 的 Ubuntu 16.04 LTS 虚拟机上有一个现有目录。我还在天蓝色中创建了一个文件共享。当挂载点是一个新目录时,我能够成功地将文件共享挂载到 VM。但是,当我尝试将文件共享装载到包含数据的现有目录 /etc/elasticsearch 时,现有目录的数据会被文件共享的内容完全覆盖。这导致我丢失了以前存在于 /etc/elasticsearch 中的数据,这显然是我不想要的。除了 /etc/elasticsearch.

中的现有数据之外,我还想添加文件共享

这是我尝试过的:

if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir /etc/smbcredentials
fi
if [ ! -f "/etc/smbcredentials/credentials.cred" ]; then
sudo bash -c 'echo "username=username" >> /etc/smbcredentials/credentials.cred'
sudo bash -c 'echo "password=password" >> /etc/smbcredentials/credentials.cred'
fi
sudo chmod 600 /etc/smbcredentials/credentials.cred

sudo bash -c 'echo "//pathtofileshare/analysis /etc/elasticsearch cifs nofail,vers=3.0,credentials=/etc/smbcredentials/credentials.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
sudo mount -t cifs //pathtofileshare/analysis /etc/elasticsearch -o vers=3.0,credentials=/etc/smbcredentials/credentials.cred,dir_mode=0777,file_mode=0777,serverino

Link to file share documentation

非常感谢您的帮助

我不认为这是个问题,这就是 Linux 挂载的工作方式

http://man7.org/linux/man-pages/man8/mount.8.html

The previous contents (if any) and owner and mode of dir become invisible, and as long as this filesystem remains mounted, the pathname dir refers to the root of the filesystem on device.