Proxmox bind mount for OpenVZ – mount storage in a container

Proxmox bind mount for OpenVZ – mount storage in a container

Category : How-to

Get Social!

proxmox logo gradYou can allocate storage to an OpenVZ container during creation, when the container is offline and even when the container is active. The main problem with this is that it is not shared, and has to be on the same storage which the container was created on.

You can mount any folder which is available to the host operating system in any container. You can also mount the same storage in multiple containers.

Before you begin, make sure the storage is mounted and usable on the host file system. For this example, we are going to use a disk which is mounted on the host at /mnt/binaries.

On the host, locate where your OpenVZ container config files are stored. On a standard Proxmox installation, this is /etc/vz/conf/. 

cd /etc/vz/conf/

Create a file with the naming convention [VMID].mount. This will be the file which is executed each time the container is started as part of the boot process. This example will assume the container is using VMID 270.

vi 270.mount

Add the below content to this file making the two changes; [HOST FOLDER] should be replace with the location on the host to use for storage in the container and [GUEST FOLDER] which will be the folder on the guest container where the storage will be available. The location on both the physical host and virtual guest must exist when the container is started. 

#!/bin/bash
. /etc/vz/vz.conf
. ${VE_CONFFILE}
SRC1=[HOST FOLDER]
DST1=[GUEST FOLDER]

mount -n -t simfs ${SRC1} ${VE_ROOT}${DST1} -o ${SRC1}

The below example makes /mnt/binaries on the host available at /mnt/vm_binaries on the guest.

#!/bin/bash
. /etc/vz/vz.conf
. ${VE_CONFFILE}
SRC1=/mnt/binaries
DST1=/mnt/vz_binaries

mount -n -t simfs ${SRC1} ${VE_ROOT}${DST1} -o ${SRC1}

To create multiple bind mounts, edit the below example.

#!/bin/bash
. /etc/vz/vz.conf
. ${VE_CONFFILE}
SRC1=/mnt/binaries
DST1=/mnt/vz_binaries
SRC2=/mnt/homes
DST2=/homes
SRC3=/mnt/backups
DST3=/mnt/vz_backups

mount -n -t simfs ${SRC1} ${VE_ROOT}${DST1} -o ${SRC1}
mount -n -t simfs ${SRC2} ${VE_ROOT}${DST2} -o ${SRC2}
mount -n -t simfs ${SRC3} ${VE_ROOT}${DST3} -o ${SRC3}

If you have many mounts something more elegant could be created however, generally speaking, only a few mount points are required per guest meaning that this brutish script is perfectly adequate.

These settings will require a restart of your container as the scripts are only applied on container start up.


6 Comments

Amrac

3-Apr-2014 at 3:10 pm

Thanks, that was very useful :)

Marcin C.

8-Apr-2015 at 9:03 pm

That’s what I needed. Thanks for that. Very, very useful thing. Cheers!

Paul Mack

17-Jul-2015 at 12:49 am

What about backups? I noticed that these files are not include in the backup of the containers as well as the mount point contents.

    james.coyle

    17-Jul-2015 at 7:09 am

    That’s true – these files are not included in the backup, partly I suspect because they would no longer be portable and self contained as they rely on the underlying target to be available. As for backing up the content, you’d want to do this on whatever service holds the underlying data, rather than inside the container.

BigBen

29-Jan-2016 at 5:07 pm

Im Proxmox Version 4 funktioniert diese Methode leider nicht mehr.

Nick DeMarco

1-Jul-2021 at 2:11 pm

BigBen, translated to English:
Unfortunately, this method no longer works in Proxmox version 4

Proxmox 4 replaced the OpenVZ virtualization platform to LXC. This article is no longer relevant and should at least be edited at the head with a note.

Leave a Reply

Visit our advertisers

Quick Poll

Do you use GlusterFS in your workplace?

Visit our advertisers