LVM and Quota with Vserver on Debian

This article is based on the excellent article on 5dollarwhitebox.org.

At first install nessesary packages:

# aptitude -t sarge-backports install lvm2\
	util-vserver coreutils linux-image-2.6-vserver-686

Create Volume and Group (Replace '/dev/hda3' to your own needs!):

# pvcreate /dev/hda3
Physical volume "/dev/hda3" successfully created
# vgcreate vg0 /dev/hda3
Volume group "vg0" successfully created

Create a Logical Volume

# lvcreate -L2048 -n vserver1 vg0
Logical volume "vserver1" created

Create and mount Filesystem, installing base system into vserver and stopping it:

# mkfs -t ext3 -j /dev/vg0/vserver1
# mkdir /var/lib/vservers/vserver1
# mount -t ext3 /dev/vg0/vserver1 /var/lib/vservers/vserver1
# vserver vserver1 build -n vserver1 \
	--hostname vserver1.vs.domain.net \
	--interface eth0:10.0.0.1/32 -m debootstrap -- -d sarge \
	-m ftp://ftp.debian.org/debian
# vserver vserver1 stop
# umount /var/lib/vservers/vserver1

Vroot operations and attaching vroot to LVM partition (and detaching again)

/dev/vroot3 is used, cause we use /dev/hda3 in our example. Please adjust it!

# e2fsck -p /dev/vg0/vserver1
# mount /dev/vg0/vserver1 /var/lib/vservers/vserver1
# rm -f /var/lib/vservers/vserver1/dev/hdv1
# vrsetup /dev/vroot3 /dev/vg0/vserver1 # vroot3 cause /dev/hda3
# cp -fa /dev/vroot3 /var/lib/vservers/vserver1/dev/hdv1
# mount -o remount,ro /dev/vg0/vserver1
# umount /dev/vg0/vserver1
# vrsetup -d /dev/vroot3

Enable Quota Capabilities:

# echo "quota_ctl" >> /etc/vservers/vserver1/ccapabilites

Starting Vserver:

# e2fsck -p /dev/vg0/vserver1
# mount /dev/vg0/vserver1 /var/lib/vservers/vserver1
# rm -f /var/lib/vservers/vserver1/dev/hdv1
# vrsetup /dev/vroot3 /dev/vg0/vserver1
# cp -fa /dev/vroot3 /var/lib/vservers/vserver1/dev/hdv1
# vserver vserver1 start

Make it start and stopping automaticaly:

# vserver vserver1 stop
# sed -i s/MARK=default/MARK=production/ /etc/default/util-vserver
# echo "production" > /etc/vservers/vserver1/apps/init/mark
# sed -i s/AUTO=false/AUTO=true/ /etc/default/util-vserver
# wget -O /usr/local/sbin/vserver-mount-fs \
	ftp://ftp.cyconet.org/pub/debian/scripts/vserver-mount-fs
# wget -O /usr/local/sbin/mount-lvm-vservers \
	ftp://ftp.cyconet.org/pub/debian/scripts/mount-lvm-vservers
# chmod 700 /usr/local/sbin/mount-lvm-vservers
# chmod 700 /usr/local/sbin/vserver-mount-fs
# echo "/dev/vg0" > /etc/vservers/vserver1/apps/init/lv_exists
# update-rc.d mount-lvm-vservers defaults 20 21

That should be all to make it work! :-)

Show Comments