FastNetMon

Tuesday, 19 November 2013

How to mount multiple disks to OpenVZ ploop container?

Hello, OpenVZ admin! :)

In many cases you can want ability to mount an additional ploop devices in OpenVZ container (be care! This guide works only with ploop), i.e. add separate as /data or /mnt. It's not so obviously but I can help you. My test container number (CTID) is 19484, be careful because this number is another in your case!  

At first, you must select path where you plans save additional disk images. In my case, it's /storage folder on hardware node.

1. We must create subfolder for saving additional disk data (image + description file). I recommend to name it with CTID.

mkdir /storage
mkdir /storage/19484

2. Create ploop device with defined size in this folder.
ploop init -s 10G -f ploop1 -v 2 /storage/19484/additional_disk_image -t ext4

3. Please stop container (it's needed because we manipulate with container root filesystem and it's so dangerous):



vzctl stop 19484

4.  We must add hook scripts for mount and umount this disk to container root mount point.

Please create file /etc/vz/conf/19484.mount with following content:
#!/bin/bash 
ploop mount -m /vz/root/$VEID/mnt  /storage/$VEID/DiskDescriptor.xml
And file  /etc/vz/conf/19484.umount with following content (we must add exit 0 because at first start vzctl will tries to umount disk and we got an error):


#!/bin/bash 
ploop umount /storage/$VEID/DiskDescriptor.xml
exit 0
Add execution flag to both files:
chmod +x /etc/vz/conf/19484.mount /etc/vz/conf/19484.umount
5. Start container:
vzctl start 19484
At first startups you must got error message because vzctl can't unmount additional disk at startup (so strange feature, really! What reason to umount disks at startup?) . It's ok, you can sefely ignore. At next start/restart you did not got any errors.   
Error in ploop_umount_image (ploop.c:1579): Image /storage/19484/additional_disk_image is not mounted
At second and next start's you can see no error:
vzctl start 19484
Starting container...
Opening delta /vz/private/19484/root.hdd/root.hdd
Adding delta dev=/dev/ploop18662 img=/vz/private/19484/root.hdd/root.hdd (rw)
/dev/ploop18662p1: clean, 36570/144288 files, 228564/576251 blocks
Mounting /dev/ploop18662p1 at /vz/root/19484 fstype=ext4 data='balloon_ino=12,'
Opening delta /storage/19484/additional_disk_image
Adding delta dev=/dev/ploop50284 img=/storage/19484/additional_disk_image (rw)
Mounting /dev/ploop50284p1 at /vz/root/19484/mnt fstype=ext4 data='balloon_ino=12,'
Container is mounted
Adding IP address(es): 78.47.76.28
Setting CPU units: 1000
Container start in progress...
Check new disk in container:
vzctl exec 19484 'df -h'
Filesystem         Size  Used Avail Use% Mounted on
/dev/ploop18662p1  2.2G  858M  1.3G  41% /
/dev/ploop50284p1  9.9G  164M  9.2G   2% /mnt
none               136M  4.0K  136M   1% /dev
none                28M 1020K   27M   4% /run
none               5.0M     0  5.0M   0% /run/lock
none                52M     0   52M   0% /run/shm
none               100M     0  100M   0% /run/user
It's important, you don't need any quota setup because ploop is complete filesystem and it's limited by standard linux mechanic like native hard drive.

Mounting additional disk as read only

If you want you can mount additional disk as read only. You must add -r flag to ploop mount command.

In read only case you will see something like this while containers starts:
vzctl start 19484
Starting container...
Opening delta /vz/private/19484/root.hdd/root.hdd
Adding delta dev=/dev/ploop18662 img=/vz/private/19484/root.hdd/root.hdd (rw)
/dev/ploop18662p1: clean, 36570/144288 files, 228582/576251 blocks (check in 4 mounts)
Mounting /dev/ploop18662p1 at /vz/root/19484 fstype=ext4 data='balloon_ino=12,'
Opening delta /storage/19484/additional_disk_image
Adding delta dev=/dev/ploop50284 img=/storage/19484/additional_disk_image (ro)
Mounting /dev/ploop50284p1 at /vz/root/19484/mnt fstype=ext4 data='balloon_ino=12,' ro
Container is mounted
Adding IP address(es): 78.47.76.28
Setting CPU units: 1000
Container start in progress...

No comments :

Post a Comment

Note: only a member of this blog may post a comment.