Your web hosting partners since 2004.
Buy now »

How to setup CentOS 7 with a OpenVZ 7 vz Logical Volume

Imagine you're making space for OpenVZ, it requires a dedicated EXT4 partition mounted on /vz.

We want to mount a specifically created logical volume, as it will be easier to extend it if required.

Before:

# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    1 232.7G  0 disk 
├─sda1            8:1    1     1G  0 part /boot
└─sda2            8:2    1 231.7G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0  15.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0   166G  0 lvm  /home

We'll want to shrink the home mount, as it's currently taking up all the remaining disk space.

We won't really need much, as we'll only be using this server for containers.

# lvreduce --resizefs -L -10G /dev/mapper/centos-home
fsadm: Xfs filesystem shrinking is unsupported.
  /usr/sbin/fsadm failed: 1
  Filesystem resize failed.

Unfortunately, you can't shrink a XFS file system.

We'll take a different approach.

Assuming that your /home directory is empty or backed up.

umount /dev/mapper/centos-home
lvremove /dev/mapper/centos-home
lvcreate -L 10GB -n home centos
mkfs.xfs /dev/centos/home
mount /dev/mapper/centos-home

After:

# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    1 232.7G  0 disk 
├─sda1            8:1    1     1G  0 part /boot
└─sda2            8:2    1 231.7G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0  15.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0    10G  0 lvm  /home

We can now create a /vz volume...

lvcreate -l 100%FREE -n vz centos
mkfs.ext4 /dev/mapper/centos-vz
mkdir /vz
mount /dev/mapper/centos-vz /vz

Now, with that done, you can add it to fstab:

echo "/dev/mapper/centos-vz /vz ext4 defaults 1 1" >> /etc/fstab

You'll have something like this:

#
# /etc/fstab
# Created by anaconda on Mon Feb 14 16:53:52 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=6e71a6ec-99ff-4ec0-b15f-df8541939411 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/mapper/centos-vz /vz ext4 defaults 1 1
# df -hT /vz
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/centos-vz ext4  154G   61M  146G   1% /vz

Last updated: 2022-02-21

« Go Back

Order now »

Used Phurix now going into my third year to host the village website and would recommend them to anyone.