Skip to content

Instantly share code, notes, and snippets.

@sergey-dryabzhinsky
Last active May 19, 2016 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-dryabzhinsky/37fdb1bfefeacca92a7a6c845592581d to your computer and use it in GitHub Desktop.
Save sergey-dryabzhinsky/37fdb1bfefeacca92a7a6c845592581d to your computer and use it in GitHub Desktop.
OpenVZ container mount script with space quoting
#!/bin/bash
###
# More advanced on-mount script for OpenVZ container
# Based on https://openvz.org/Bind_mounts
#
# 1. Mount some directory inside container
# 2. Set quotas on that directory inside container
#
[ -f /etc/vz/vz.conf ] || exit 1
[ -f $VE_CONFFILE ] || exit 1
. /etc/vz/vz.conf
. ${VE_CONFFILE}
# Mount point in host hypervisor machine
SRC=/mnt/external-host-mp
# Mount point inside container
DST=/mnt/internal-vm-mp
if [ ! -e ${VE_ROOT}${DST} ]; then mkdir -p ${VE_ROOT}${DST}; fi
# Mount options are from 'man mount': noatime, relatime, ro, nosuid, noexec, etc.
mount -n -t simfs ${SRC} ${VE_ROOT}${DST} -o ${SRC},noatime,ro
# Do not need quotas? Then uncomment:
#exit 0
# Quota ID, make it real BIG number, to avoid crossing with container root VEID
QID=$((VEID+1000000))
# Check for existing
vzquota show $QID >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
# If not exists - create
# Double check for needed size - it must be in 1kb BLOCKS
BS=1024
# Size in GB
# Blocks soft limit
BSL=$((10*1024*1024*1024))
# Blocks hard limit - BSL + 10%
BHL=$((BSL/10*11))
# Inodes soft limit - 1/10 BSL
ISL=$((BSL/10))
# Inodes hard limit - 1/10 BHL
IHL=$((BHL/10))
# Size in blocks
BSL=$((BSL/BS))
BHL=$((BHL/BS))
# Quotas w/o exipation
vzquota init $QID -p ${VE_ROOT}${DST} -b $BSL -B $BHL -i $ISL -I $IHL -e 0 -n 0
fi
# Quotas ON after mount destination directory
vzquota on $QID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment