Following my guide Open Virtuozzo [OpenVZ] installation manual for CentOS/RHEL, In this guide, I will teach you How to add a ploop device to an existing OpenVZ container.

Requirements:

A CentOS/RHEL machine installed with OpenVZ.

Let’s Begin:

Apart from the creation of the container_id.mount and container_id.umount files, where ever you see $VE_ID , replace it with your own Container’s id, for example: 203.

Find the relevant space needed

In my case, I used lvcreate in order to create a new logical volume on the physical server like so:

lvcreate -L 100G vg_vmhost -n lv_1

Check that the logical volume has been created successfully by running lvdisplay like so:

[root@openvz250 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_vmhost/lv_1
  LV Name                lv_1
  VG Name                vg_vmhost
  LV UUID                UCbB2o-IUwp-oLDe-yacY-dMkk-TsjM-LDRB1i
  LV Write Access        read/write
  LV Creation host, time openvz250.local, 2014-07-02 12:25:47 +0300
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

Format it with ext4:

mkfs.ext4 /dev/vg_vmhost/lv_1

Create a local mount point:

mkdir –p /disk1/$VE_ID

Run:

ploop init -s 100G -f ploop1 -v 2 /disk1/$VE_ID/additional_disk_image -t ext4

Stop the container:

vzctl stop $VE_ID

Create /etc/vz/conf/$VE_ID.mount (example: /etc/vz/conf/203.mount):

#!/bin/bash 
ploop mount -m /vz/root/$VEID/mnt  /disk1/$VEID/DiskDescriptor.xml

And create /etc/vz/conf/$VE_ID.umount (example: /etc/vz/conf/203.umount):

#!/bin/bash 
ploop umount /disk1/$VEID/DiskDescriptor.xml
exit 0

Make the conf files executables:

chmod +x /etc/vz/conf/$VE_ID.mount /etc/vz/conf/$VE_ID.umount

Start the container:

vzctl start $VE_ID

there could be some errors, so just restart the container:

vzctl restart $VE_ID

Enter container and check that the new ploop disk is mounted correctly and add the mount to the /etc/fstab file on the OpenVZ host

vzctl enter $VE_ID
# df -H

Example:

[root@openvz250 ~]# vzctl enter 203
entered into CT 203
[root@container /]# df -H

Filesystem         Size  Used Avail Use% Mounted on
/dev/ploop37641p1  9.0G  1.8G  6.7G  21% /
/dev/ploop23556p1  106G  197M  101G   1% /mnt
none               4.3G  4.1k  4.3G   1% /dev
none               4.3G     0  4.3G   0% /dev/shm

This is the ploop drive I’ve added: /dev/ploop23556p1 106G 197M 101G 1% /mnt

[root@openvz250 ~]# df -H
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/vg_vmhost-lv_root   16G  1.1G   14G   8% /
tmpfs                           68G     0   68G   0% /dev/shm
/dev/sda1                      508M   56M  426M  12% /boot
/dev/mapper/vg_vmhost-vz_root  106G  4.6G   96G   5% /vz
/dev/mapper/vg_vmhost-lv_1     106G  330M  100G   1% /disk1

This is the mount point I created: /dev/mapper/vg_vmhost-lv_1 106G 330M 100G 1% /disk1

Edit /etc/fstab on the OpenVZ host and add the relevant mount point we created:

[root@openvz250 ~]# tail /etc/fstab 

/dev/mapper/vg_vmhost-lv_root /                       ext4    defaults        1 1
UUID=81400e9f-0316-4594-bb0e-47a2f76ccfe6 /boot                   ext4    defaults        1 2
/dev/mapper/vg_vmhost-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vg_vmhost/vz_root	/vz			 ext4    defaults        1 3
/dev/vg_vmhost/lv_1	/disk1			 ext4    defaults        1 3

I hope you liked this article, please feel free to leave comments or ask questions.

Comments

comments