One common use of this technique for me is to mount a shared SSD drive which is used by many OpenVZ containers. Since the SSD drive is mounted directly to the bare-metal OS for ie: /mnt/ssd.
Another purpose is to be able to have a common shared directory in the bare-metal server shared between many OpenVZ containers on that server. The shared directory can even be an NFS Server which means you can have a shared directory between many OpenVZ located in different hardware nodes! Now that is Cool!
Anyways this is the technique:
1. CREATE THE DESTINATION DIRECTORY
Login to the OpenVZ container where you will be mounting, create the directory and assign all permission. (in this example we will use /mnt/shared_dir as the destination directory path)
chmod 777 /mnt/shared_dir
2. CREATE .mount FILE
Login to shell of your Proxmox hardware node to create <vmid>.mount file.
(in this example you should replace <vmid> with your actual OpenVZ container ID)
(in this example you should replace <vmid> with your actual OpenVZ container ID)
(in this example we assume you are trying to share /mnt/ssd from your hardware node)
cd /etc/pve/openvz
nano <vmid>.mount
nano <vmid>.mount
Type in the following content in your <vmid>.mount file:
#!/bin/bash
. /etc/vz/vz.conf
. ${VE_CONFFILE}
SRC=/mnt/ssd
DST=/mnt/shared_dir
if [ ! -e ${VE_ROOT}${DST} ]; then mkdir -p ${VE_ROOT}${DST}; fi
mount -o noatime -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC}
3. RESTART THE OPENVZ CONTAINER and TEST
Once you restart your OpenVZ, log into it and issue the following command:
You should see a new row describing your newly mounted directory.
The mount command can also help you confirm it has been mounted.
No comments:
Post a Comment