Difference between revisions of "Standard non-shared quota"

From Linux-VServer

Jump to: navigation, search
(Save settings for reboot)
 
(14 intermediate revisions by 3 users not shown)
Line 8: Line 8:
  
 
Edit your /etc/fstab if this is not the case. You don't need to actually enable quotas in the host, but you at least need the usrquota and grpquota mount options.
 
Edit your /etc/fstab if this is not the case. You don't need to actually enable quotas in the host, but you at least need the usrquota and grpquota mount options.
 +
 +
Something like this will work on host machine:
 +
 +
/etc/fstab
 +
<pre>
 +
/dev/md0        /var/lib/vservers              reiserfs        defaults,usrquota,grpquota              0      0
 +
</pre>
 +
  
 
Then, use ''vrsetup'' to tell the kernel what block device you want to handle quota for:
 
Then, use ''vrsetup'' to tell the kernel what block device you want to handle quota for:
  vrsetup /dev/vroot/0 [partition]
+
  vrsetup /dev/vroot0 [partition]
 
Where [partition] is your /vservers partition. For example, this could be something like /dev/hda5 if you're just using standard partitioning, or something like /dev/lvm/vserver0 if you're using LVM.
 
Where [partition] is your /vservers partition. For example, this could be something like /dev/hda5 if you're just using standard partitioning, or something like /dev/lvm/vserver0 if you're using LVM.
  
Line 17: Line 25:
  
 
1. Create a default mtab for the guest. To do this, add:
 
1. Create a default mtab for the guest. To do this, add:
  /dev/hdv1 / ufs rw,usrquota,grpquota 0 0
+
  /dev/hdv1 / ufs defaults,usrquota,grpquota 0 0
 
to '''/etc/vservers/<name>/apps/init/mtab'''
 
to '''/etc/vservers/<name>/apps/init/mtab'''
  
Line 27: Line 35:
  
 
3. Copy the vroot device which we setup earlier to the vserver:
 
3. Copy the vroot device which we setup earlier to the vserver:
  cp -af /dev/vroot/0 /vservers/<name>/dev/hdv1
+
  cp -af /dev/vroot0 /vservers/<name>/dev/hdv1
  
 
=== Finishing the setup ===
 
=== Finishing the setup ===
Line 36: Line 44:
 
</pre>
 
</pre>
 
<pre>
 
<pre>
/dev/hdv1 / ufs rw,usrquota,grpquota 0 0
+
/dev/hdv1 / ufs defaults,usrquota,grpquota 0 0
 
</pre>
 
</pre>
  
Afterwards run
+
Add to /etc/rc.local
quotacheck -maugv
+
<pre>
 +
/sbin/quotacheck -maugv
 +
/sbin/quotaon /dev/hdv1
 +
</pre>
  
3. Still inside the guest, turn quotas on.
+
 
 +
 
 +
<b>"Setquota / " problem:</b>
 +
<pre>
 +
Changing disk quota ..
 +
.. Administration user failed! : setquota: Mountpoint (or device) / not found. setquota: Not all specified mountpoints are using quota. at ../web-lib-funcs.pl line 1323.
 +
 
 +
or:
 +
 
 +
Failed to create virtual server : setquota: Mountpoint (or device) / not found. setquota: Not all specified mountpoints are using quota.
 +
</pre>
 +
 
 +
<b>Solution:</b>
 +
Virtualmin will fail setting user quota as it requests / instead of /dev/hdv1 partition, so
 +
if  you are running virtualmin - create wrapper for setquota program:
 +
 
 +
<pre>
 +
if [ -f /usr/sbin/setquota-old ]
 +
then
 +
        echo "Nothing to do."
 +
else
 +
        mv /usr/sbin/setquota /usr/sbin/setquota-old
 +
        cat > /usr/sbin/setquota <<EOF
 +
#!/bin/bash
 +
var=$*
 +
/usr/sbin/setquota-old ${var/\/}/dev/hdv1
 +
EOF
 +
        chmod +x /usr/sbin/setquota
 +
fi
 +
</pre>
  
 
=== Save settings for reboot ===
 
=== Save settings for reboot ===
Line 49: Line 89:
 
Alternatively add the vrsetup line to the '''/etc/vservers/<vserver-name>/scripts/initialize''' script:
 
Alternatively add the vrsetup line to the '''/etc/vservers/<vserver-name>/scripts/initialize''' script:
 
<pre>
 
<pre>
echo "vrsetup /dev/vroot/0 [partition]" >> /etc/vservers/<vserver-name>/scripts/initialize
+
# set quota
 +
/bin/rm -f /var/lib/vservers/<vserver-name>/dev/hdv1
 +
/usr/sbin/vrsetup /dev/vroot0 [partition] #/dev/md0 or smth...
 +
/bin/cp -fa /dev/vroot0 /var/lib/vservers/<vserver-name>/dev/hdv1
 
</pre>
 
</pre>
  
 
and the vrsetup detach command into '''/etc/vservers/<vserver-name>/scripts/postpost-stop''':
 
and the vrsetup detach command into '''/etc/vservers/<vserver-name>/scripts/postpost-stop''':
 
<pre>
 
<pre>
echo "vrsetup -d /dev/vroot/0" >> /etc/vservers/<vserver-name>/scripts/postpost-stop
+
#remove quota
 +
/usr/sbin/vrsetup -d /dev/vroot0
 
</pre>
 
</pre>
 +
 +
 +
== New Quotatool since debian squeeze ==
 +
 +
 +
Since the debian squeeze the quota tool are shipped with a new version where the setup of /dev/hdvx will not work. To make it work with those tools you must:
 +
 +
- never use hide_mounts capabilities
 +
- name the virtual device inside the guest the same name as the real one.
 +
 +
So the mtab should have the real device name and /dev/vrootx should be copied to /vservers/guestxx/dev/realdevicename and not /dev/hdvx
 +
 +
 +
 +
[[Category:Configuration]]

Latest revision as of 11:07, 7 January 2012

Want to enable quotas from within a vserver, nothing special, just plain old and good quota support? Then this might help you! First things first, you will need a vserver enabled kernel that you have made working and you need to add vroot support to it (In menuconfig it is in Device Drivers → Block Devices → Virtual Root device support).

After booting on the vroot enabled vserver kernel, you should have a directory /dev/vroot/ with 8 vroot devices (0-7) you can use to set up your quota, if you don't, then you may make them by mknod /dev/vroot/n b 4 n (where n can be from 0 to 7). If your Linux distribution uses udev, these will be at /dev/vroot[0-7] instead.

Contents

[edit] Initial Setup

First, ensure that the filesystem where your vservers are located on the host has quota options enabled: usrquota,grpquota

Edit your /etc/fstab if this is not the case. You don't need to actually enable quotas in the host, but you at least need the usrquota and grpquota mount options.

Something like this will work on host machine:

/etc/fstab

/dev/md0        /var/lib/vservers               reiserfs        defaults,usrquota,grpquota              0       0


Then, use vrsetup to tell the kernel what block device you want to handle quota for:

vrsetup /dev/vroot0 [partition]

Where [partition] is your /vservers partition. For example, this could be something like /dev/hda5 if you're just using standard partitioning, or something like /dev/lvm/vserver0 if you're using LVM.

[edit] Setting Up Vservers For Quota

Setting up the vserver for quota is straight forward: (you need util-vserver 30.208 or newer)

1. Create a default mtab for the guest. To do this, add:

/dev/hdv1 / ufs defaults,usrquota,grpquota 0 0

to /etc/vservers/<name>/apps/init/mtab

Note: Replace ufs with xfs if you're using an XFS file-system.

2. Add the quota capability to the guest vserver. Add:

quota_ctl 

to /etc/vservers/<name>/ccapabilities

3. Copy the vroot device which we setup earlier to the vserver:

cp -af /dev/vroot0 /vservers/<name>/dev/hdv1

[edit] Finishing the setup

1. Start your guest.
2. Inside the guest, make sure the mtab entry is present:

grep /dev/hdv1 /etc/mtab
/dev/hdv1 / ufs defaults,usrquota,grpquota 0 0

Add to /etc/rc.local

/sbin/quotacheck -maugv
/sbin/quotaon /dev/hdv1
 


"Setquota / " problem:

Changing disk quota ..
.. Administration user failed! : setquota: Mountpoint (or device) / not found. setquota: Not all specified mountpoints are using quota. at ../web-lib-funcs.pl line 1323.

or:

Failed to create virtual server : setquota: Mountpoint (or device) / not found. setquota: Not all specified mountpoints are using quota. 

Solution: Virtualmin will fail setting user quota as it requests / instead of /dev/hdv1 partition, so if you are running virtualmin - create wrapper for setquota program:

if [ -f /usr/sbin/setquota-old ]
then
        echo "Nothing to do." 
else
        mv /usr/sbin/setquota /usr/sbin/setquota-old
        cat > /usr/sbin/setquota <<EOF
#!/bin/bash
var=$*
/usr/sbin/setquota-old ${var/\/}/dev/hdv1
EOF
        chmod +x /usr/sbin/setquota
fi

[edit] Save settings for reboot

To have setting persist on reboot, put vrsetup line into /etc/init.d/util-vserver start function, so after reboot vroot device get setup before it start.

Alternatively add the vrsetup line to the /etc/vservers/<vserver-name>/scripts/initialize script:

# set quota
/bin/rm -f /var/lib/vservers/<vserver-name>/dev/hdv1
/usr/sbin/vrsetup /dev/vroot0 [partition] #/dev/md0 or smth...
/bin/cp -fa /dev/vroot0 /var/lib/vservers/<vserver-name>/dev/hdv1

and the vrsetup detach command into /etc/vservers/<vserver-name>/scripts/postpost-stop:

#remove quota
/usr/sbin/vrsetup -d /dev/vroot0


[edit] New Quotatool since debian squeeze

Since the debian squeeze the quota tool are shipped with a new version where the setup of /dev/hdvx will not work. To make it work with those tools you must:

- never use hide_mounts capabilities - name the virtual device inside the guest the same name as the real one.

So the mtab should have the real device name and /dev/vrootx should be copied to /vservers/guestxx/dev/realdevicename and not /dev/hdvx

Personal tools