VZ bind mounts (ve.mount ve.umount)

 

假設現在要把 Host 上的 /mnt/disk 掛到 VPS 1001 的 /mnt/disk 目錄上

首先建立檔案 /etc/vz/conf/1001.mount

內容如下:

#!/bin/bash

VEID=1001
VE_ROOT=/vz/root/$VEID

SRC=/mnt/vm/shardfolder
DST=/mnt/shardfolder

mount -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC}

chmod +x /etc/vz/conf/1001.mount

之後執行此 Script 或每次 VPS 1001 啟動時都會自動掛到相應的目錄上

 

之後在 vps 內會見到

mount

/dev/simfs on / type simfs (rw,noatime)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,relatime,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
/dev/simfs on /mnt/shardfolder type simfs (rw,relatime)

 

df -h

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/simfs            19433472   4481316  14952156  24% /
tmpfs                   308172         0    308172   0% /lib/init/rw
tmpfs                   308172         0    308172   0% /dev/shm
/dev/simfs            46137344  18019248  25774416  42% /mnt/shardfolder

 

其他有用的參數:

-r    read-only

-n    不修改 vps 內的 /etc/mtab

 


 

umount

 

#!/bin/bash
source /etc/vz/vz.conf
source ${VE_CONFFILE}

DST=/mnt/shardfolder

umount ${VE_ROOT}/$DST