Jump to: [navigation](https://pve.proxmox.com/wiki/LXC_Bind_Mounts#mw-head), [search](https://pve.proxmox.com/wiki/LXC_Bind_Mounts#p-search)
說明
------------------------------------------------------
Bind mounts 允許從 Proxmox VE host 的 container 裡 可以存取 Host實體主機 的 目錄(directory),或 storage volume.有許多種不同的用途:
- guest 可以存取 Host 的 家目錄
- guest 可以存取 USB 裝置目錄
- guest 可以存取 NFS 的目錄
要注意的是,在 LXC 上要連接的分享目錄必需是在 Host 上已經掛載連接的才可以. 為了安全性起見, PVE 不允許 LXC 直接掛載其它主機上的 NFS .
假設 編號為 100 的 LXC 容器 要存取 實體機裡的目錄:
- /target 是虛擬機中的目錄
- /mnt/pve/freenas 是已經掛載的 NFS 目錄.
現在需要把下列的參數加到 虛擬機 /etc/pve/lxc/100.conf 的設定檔裡:
```
mp0: /target/test,mp=/target
mp1: /mnt/pve/freenas,mp=/mnt/pve/freenas
```
mp0 ---> PVE 主機上的目錄 ,
mp ---> LXC 虛擬機上要掛載的目錄 (不用手動建立,掛載後會自動建立. 若事先建立,系統會將原來的目錄遮蔽.)
實作:在 LXC 虛擬機 vmid 201 的設定檔 /etc/pve/lxc/201.conf 裡加入最後一行的內容
mp0: /mnt/cifs\_share/ftp,mp=/var/www/www.hbes.chc.edu.tw/ftp
我們要將 pve 實體機裡的目錄 /mnt/cifs\_share/ftp (可以是自行建立的目錄,或是以 nfs 掛載的目錄,或是以 autofs 掛載的目錄)
掛載到 LXC 虛擬機 vmid 201 裡面的 /var/www/www.hbes.chc.edu.tw/ftp 這個目錄 (這個目錄系統會自動建立)

再將 LXC ( container ) 虛擬機重新開機,並登入虛擬機 :(檢查是否有正確掛載)
```
pct enter vmid ----> 這樣就直接進入 虛擬機,真方便
mount | egrep '(target|freenas)' ----> 查看是否已經將 Host的目錄 掛載 到 虛擬機裡面
/dev/dm-0 on /target type ext4 (rw,relatime,errors=remount-ro,data=ordered) ----> 結果
freenas.local:/mnt/TranstecThrough/exported
```
實作:
在實體機以指令 pct enter 201 直接進入 虛擬機 (或以 ssh 登入該虛擬機也可以)
再以 mount 指令查看 掛載的 目錄

Manual method
------------------------------------------------------------------
- This works as of 2015-09-13 using lxc-pve: 1.1.3-1 .
- add this to the .conf file in /etc/pve/lxc
```
lxc.mount.entry: /host/folder container/folder none bind,create=dir,optional 0 0
```
**Note:** Do not put a '/' before the container target
**Note:** This adds an entry to "/var/lib/lxc/<containerID>/config" in the correct format. Do not edit "/var/lib/lxc/<containerID>/config" manually as that is overwritten on container boot.
Bind mounts and backup
------------------------------------------------------------------------------------
Note that bind mounts are not going to be included when you backup the container by default. You need to set the backup flag to include them.
```
mp0: /target/test,mp=/target,backup=1
```