FastNetMon

Wednesday 2 July 2014

Using ZFS with OpenVZ: OpenVZFS

In this manual we will install OpenVZ on top of ZFS on CentOS 6. More documentation about ZVOL: http://zfsonlinux.org/example-zvol.html

Installing OpenVZ 

 

At first you should install OpenVZ kernel and userspace using this guide http://openvz.org/Quick_installation:
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ
yum install vzkernel vzctl vzquota ploop
shutdown -r now
At second please reboot to OpenVZ kernel and _after_ this install OpenZFS packages:
yum remove kernel
yum install -y vzkernel-devel
rpm -ihv http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum localinstall -y --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release$(rpm -E %dist).noarch.rpm
yum update -y
yum install zfs -y
ZFS kernel modules will be installed using DKMS and will be recompiled for new kernels automatically.

Check ZFS loading:
zpool status
no pools available
Create ZFS pool with name vzpool (don't use name "vz" because it already used by OpenVZ's /vz partition):
zpool create -f vzpool mirror /dev/sdc /dev/sdd

Integrate ZFS with OpenVZ

 

Create OpenVZ container with simfs layout model:
vzctl create 101 --layout simfs --name zfs.ru --ostemplate debian-7.0-x86_64
Create ZFS zvol for 10G:
zfs create -V 10G vzpool/ct101
We can use sparse allocation and specify block size. But it's _VERY DANGEROUS_, please read documentation after doing something!
The reservation is kept equal to the volume’s logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size. Though not recommended, a "sparse volume" (also known as "thin provisioning") can be created by specifying the -s option to the zfs create -V command, or by changing the reservation after the volume has been created. A "sparse volume" is a volume where the reservation is less then the volume size. Consequently, writes to a sparse volume can fail with ENOSPC when the pool is low on space. For a sparse volume, changes to volsize are not reflected in the reservation.

-b blocksize
Equivalent to -o volblocksize=blocksize. If this option is specified in conjunction with -o volblock-size, the resulting behavior is undefined.
Create GPT partition table on created zvol:
parted -s /dev/vzpool/ct101 mklabel gpt
Create one partition for whole disk:
parted /dev/vzpool/ct101 "mkpart primary 1 -1"
Create ext4 filesystem on zvol:
mkfs -t ext4 -j -b4096 -Elazy_itable_init,resize=4294967295 -Jsize=128 /dev/vzpool/ct101-part1
And move container to this filesystem:
mkdir /mnt/101
mount /dev/vzpool/ct101-part1 /mnt/101
cp -a /vz/private/101/* /mnt/101/
umount /mnt/101
sync
Remove old container body:
rm -rf /vz/private/101/
And replace it by mounted ZFS zvol:
mkdir /vz/private/101
mount /dev/vzpool/ct101-part1 /vz/private/101
Mount container:
vzctl mount 101
Check files in /vz/root/101:
LANG=C ls -al /vz/root/101/
total 92K
drwxr-xr-x 23 root root 4.0K Jun 27 02:38 .
drwx------  3 root root 4.0K Jul  2 12:35 ..
drwxr-xr-x  2 root root 4.0K Jun 27 02:38 bin
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 boot
drwxr-xr-x  2 root root 4.0K Jun 27 02:36 dev
drwxr-xr-x 81 root root 4.0K Jul  2 12:35 etc
-rw-r--r--  1 root root    0 Jun 27 02:36 fastboot
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 home
drwxr-xr-x 11 root root 4.0K Jun 27 02:37 lib
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 lib64
drwx------  2 root root 4.0K Jun 27 02:36 lost+found
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 media
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 mnt
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 opt
dr-xr-xr-x  2 root root 4.0K Jun 27 02:36 proc
drwx------  2 root root 4.0K Jun 27 02:37 root
drwxr-xr-x  2 root root 4.0K Jun 27 02:38 run
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 sbin
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 selinux
drwxr-xr-x  2 root root 4.0K Jun 27 02:37 srv
drwxr-xr-x  2 root root 4.0K Jun 27 02:36 sys
drwxrwxrwt  2 root root 4.0K Jun 27 02:38 tmp
drwxr-xr-x 10 root root 4.0K Jun 27 02:38 usr
drwxr-xr-x 12 root root 4.0K Jun 27 02:38 var
Start container:
vzctl start 101
Starting container...
Container is unmounted
Container is mounted
Setting CPU units: 1000
Container start in progress...
Inside container filesystem show as simfs not an ZFS:
cat /proc/mounts
/dev/simfs / simfs rw,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,nosuid,noexec,relatime,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
none /run tmpfs rw,nosuid,noexec,relatime,size=26216k,mode=755 0 0
none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=157280k 0 0
none /run/user tmpfs rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755 0 0
If you need any help/questions, you can write to me: pavel.odintsov at gmail dot com.

No comments :

Post a Comment

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