Quota management in Linux is used to restrict and monitor disk space and inode usage by users and groups on a filesystem. It helps prevent a single user or process from consuming excessive resources.
-
Debian-based systems:
sudo apt install quota -y
-
RHEL/CentOS:
sudo yum install quota -y
-
Fedora:
sudo dnf install quota -y
Add quota options for the desired partition:
/dev/sdb1 /d1 ext4 defaults,usrquota,grpquota 0 0
sudo mount -o remount /d1
Run the following command to check and create the quota database:
sudo quotacheck -cum /home
c
: Create quota filesu
: Check user quotasm
: Do not remount the filesystem as read-only
- Initialize quotas on the filesystem:
sudo quotaon /d1
- Verify quota status:
sudo quota -ap
-
Check Block Device Information:
lsblk blkid df -h
-
Format Filesystem:
sudo mkfs.ext4 /dev/sdb1 sudo mkfs.xfs /dev/sdb1
-
Quota Management Commands:
quotacheck -cum /d1
: Check and create quota filesquotacheck -cugv /d2
: Check quotas for users and groupsquota -ap
: Display all quotasedquota username
: Edit user quotastouch /d1/aquota.user /d1/aquota.group
: Create required quota filestune2fs -O quota /dev/sdb1
: Enable quota feature on ext4 filesystem
Logical Volume Manager (LVM) is a storage management solution in Linux that provides flexibility and advanced features for managing disk space. It allows dynamic resizing of partitions.
- Physical Volume (PV): The actual storage device (e.g., /dev/sdb, /dev/sdc).
- Volume Group (VG): A pool of storage created from one or more PVs.
- Logical Volume (LV): A partition-like structure inside a VG, where file systems are created.
- Debian/Ubuntu:
apt install lvm2 -y
- RHEL/CentOS:
yum install lvm2 -y
- Check installed packages:
rpm -qa | grep lvm2
- List package files:
rpm -ql | grep lvm2
- Display package information:
rpm -qi lvm2
- Free the disk:
fdisk /dev/sdb
- Create a single partition:
fdisk /dev/sdb
- Check system block devices:
lsblk
- View mounted filesystems:
df -h
- Edit fstab (remove any unwanted entries):
vim /etc/fstab
- Identify available disks:
lsblk
- Initialize the disk as an LVM physical volume:
pvcreate /dev/sdb /dev/sdc
- Display physical volume details:
pvdisplay
- Verify physical volumes:
pvs
- Create a volume group named
vg_data
:vgcreate vg_data /dev/sdb /dev/sdc
- Display volume group details:
vgdisplay
- Create a 60 GB logical volume named
lv_storage
:lvcreate -L 60G -n lv_storage vg_data
- Check the logical volume content:
lvs
- Format the logical volume:
mkfs.ext4 /dev/vg_data/lv_storage
- Create a mount point:
mkdir /mnt/storage
- Mount the logical volume:
mount /dev/vg_data/lv_storage /mnt/storage
- Verify the block devices:
lsblk
- Check filesystem UUID:
blkid
- Verify the mount:
df -h
- Copy logs as a test:
cp -vr /var/log/* /mnt/storage
- List contents:
ls -lh /mnt/storage
- Extend the logical volume by 10 GB:
lvextend -L +10G /dev/vg_data/lv_storage
- Resize the filesystem:
resize2fs /dev/vg_data/lv_storage
- Verify the change:
df -h /mnt/storage
- Unmount the volume:
umount /mnt/storage
- Check and reduce the filesystem:
e2fsck -f /dev/vg_data/lv_storage resize2fs /dev/vg_data/lv_storage 15G
- Reduce the logical volume size:
lvreduce -L 15G /dev/vg_data/lv_storage
- Remount the volume:
mount /dev/vg_data/lv_storage /mnt/storage
- Mount the snapshot:
mount /dev/vg_data/lv_snapshot /mnt/snapshot
- Remove the snapshot after use:
umount /dev/vg_data/lv_snapshot lvremove /dev/vg_data/lv_snapshot
- Unmount the logical volume:
umount /mnt/storage
- Remove the logical volume:
lvremove /dev/vg_data/lv_storage
- Verify removal:
lvdisplay