Admin guidelines for user quotas

Disk quotas on xfs are supported, and all EL7 and above systems in the company use xfs. No limits are planned for ext4 filesystems at this time.

Report on entire filesystem quotas

sudo xfs_quota -xc 'report -h' /home
$ sudo xfs_quota -xc 'report -h' /home
User quota on /home (/dev/mapper/bf-home)
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0  1000M   1.3G  00 [------]
svcacct1     192K  1000M   1.3G  00 [------]
jdoe1             0  1000M   1.3G  00 [------]
bgstack15     98.2M  1000M   1.3G  00 [------]
sudo du -xBM --max-depth 1 /home | sort -n | tail
# sudo du -xBM --max-depth 1 /home | sort -n | tail
1M      /home/testuser
2M      /home/wharvey
53M     /home/jsmith
179M    /home/bgstack15
261M    /home/svcacct2
14489M  /home/jdoe1
14986M  /home

Changing quotas

After a Linux engineer approves, a user quota may be changed.

Change the default quota

The default quota affects all users. Do not use this one!

sudo xfs_quota -x -c 'limit bsoft=250m bhard=300m -d' /home

Change a user quota

sudo xfs_quota -xc 'limit bsoft=1000m bhard=1200m jdoe1' /home

Remove a user quota

Setting to zero will return a user back to the default quota. The documentation states this makes an unlimited quota, but the documentation is incorrect (original research).

sudo xfs_quota -xc 'limit bsoft=0 bhard=0 jdoe1' /home

Policy for user quotas for home directories for Linux


The default storage limit for users on the /home filesystem is 250MB. If all of your allocated space is used, you cannot grow files or make new ones in your home directory. Using the entire disk quota can cause your application to display an error.

This limitation exists to reinforce the company’s Data Retention Policy and allocate disk space fairly. Users should not store large files in the home directories. The home directories are designed for incidental storage for OS user files, and work files being used before moving them to a final location.


Dow do I request more space?

Open a help ticket to the IT queue. The Linux team will review your request and work with you on the requirements. Be advised that exceptions to the main policy are very rare, because /home exists for work-related files which are primarily stored elsewhere. Storage of personal files and large work files in /home is not supported and is not a valid use case for an exception.

How do I check my disk usage and clean up files

You can view information about your home directory and how much space you are currently using.

Command Explanation
du -hs * | sort -h
Show all files and directories in the current directory, and sort by size
du -xBM --max-depth 3 /home/jdoe | sort -n | tail
Show the largest 10 files and directories in /home/jdoe, drilling down to a max of 3 subdirectories
ls -al
List all files and directories in the current directory
Delete files named FILE1, FILE2, and FILE3.
rmdir foobar
Remove an empty directory named foobar


Similar guidelines for other organizations include

Playbook that runs du

Here’s a playbook I wrote for my Ops team. Apparently they’re impressed by the simplest things.

# Filename: du.yml
# Author: bgstack15
# Startdate: 2018-07-24
# Title: Book that Runs du
# Purpose: Run du with elevated privileges, primarily for auditing /home
# History:
# Usage:
#    In ansible tower.
#    Variables:
#       path=/home   What location to check
#       max_depth=1  How many directories to read in to
#       tail=5       How many to show
# Reference:
# Improve:
# Documentation:

- name: book that runs du
  hosts: all
  become: yes
  become_user: root
  become_method: sudo

  - name: du
    shell: /usr/bin/du -xBM --max-depth "{{ max_depth | default('1') }}" "{{ path | default('/home') }}" | sort -n | tail -n "{{ tail | default('5') }}" | sed -r -e 's/[[:space:]]+/ /g;'
      warn: no
    register: du

  - debug:
      msg: "{{ du.stdout_lines }}"

Create, attach, detach disk to vm in kvm on command line

In kvm, let’s say you want to create a new disk and attach it to a virtual machine. You could use Virtual Machine Manager. But for the command line, here is a quick way how to do it.

Create a disk

Create a qcow2 disk that is fully allocated. When I tried with disks that were not fully allocated, the vm would only see the 200K or so and would not let me write a partition table large enough to do anything.

time qemu-img create -f qcow2 /var/lib/libvirt/images/vmname-vdb.qcow2 22000M -o preallocation=full

Attach a disk

You can omit the flags as needed, if you don’t want to update the virtual machine’s definition, or –config. And some of these are probably redundant, but they did not throw errors for me and I wanted the change to be immediate and persistent upon vm reboot, so I leave them all in.

virsh attach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --target vdb --persistent --config --live

Detach a disk

Same thing as the attaching, only you don’t include the –target flag.

virsh detach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --persistent --config --live



Man pages

  1. qemu-img

Remove scsi disk from operating system

To tell an OS you are ready to remove a scsi disk, you can run this command:

echo 1 > /sys/block/sdX/device/delete

Where sdX is the device you are ready to detach.

For virtual machines I don’t usually bother doing that, but that is how to safely tell GNU/Linux you are going to remove the device.



  1. Original question

Resize a live logical volume

Resizing a live logical volume

If you use lvm to abstract the filesystems away from the direct hardware, you might need to know how to add additional space without taking the filesystem offline. This post shows how you might do that.

Attach new disk

Save current state to a file for comparison.

ls -l /dev/{s,v}d* > ~/

Install additional disk to system (in hypervisor or attach to physical machine).
Scan with (from sg3_utils package).
If that fails, try

find /sys/class/scsi_host/host*/scan | while read line; do echo "- - -" > $line; done

Find the name of the new disk:

ls -l /dev/{s,v}d* > ~/
diff ~/ ~/

The output should be the name of the new disk.

Create a new partition

How to do it in fdisk:

fdisk /dev/newdisk

Add the partition to lvm and the logical volume

pvcreate /dev/newdisk1
vgextend vgname /dev/newdisk1
lvextend /dev/vgname/lvname /dev/newdisk1

Resize the filesystem

Filesystem type ext4 can be resized live:

resize2fs /dev/vgname/lvname