首先我们需要添加一块磁盘:

基础服务——搭建LVM磁盘配额

 

基础服务——搭建LVM磁盘配额

 

[[email protected] ~]# reboot              重启,使得系统读取磁盘

[[email protected] ~]# ls /dev/sd*                         查看SCSI设备

/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb

 

[[email protected] ~]# fdisk –l              查看硬盘情况

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x00002ec3

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048      616447      307200   83  Linux

/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris

/dev/sda3         4810752    41943039    18566144   83  Linux

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

 

[[email protected] ~]# fdisk /dev/sdb 给新添加的磁盘分区

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x6c2ce855.

 

Command (m for help): n                  新建分区

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p                   默认选择

Partition number (1-4, default 1): 1                   选择第一个分区

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G   指定分区大小

Partition 1 of type Linux and of size 10 GiB is set

 

Command (m for help): n                  再次新建一个分区

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p): p

Partition number (2-4, default 2):           默认选择第二个分区

First sector (20973568-41943039, default 20973568):

Using default value 20973568

Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039):         回车即可

Using default value 41943039

Partition 2 of type Linux and of size 10 GiB is set

 

Command (m for help): p         打印磁盘分区信息

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x6c2ce855

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    20973567    10485760   83  Linux

/dev/sdb2        20973568    41943039    10484736   83  Linux

 

Command (m for help): t          更改分区类型

Partition number (1,2, default 2): 1                   选择第一个分区 

Hex code (type L to list all codes): 8e                修改为8e类型

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): t          更改分区类型

Partition number (1,2, default 2): 2                   选择第一个分区

Hex code (type L to list all codes): 8e                修改为8e类型

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): p        打印磁盘分区信息

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x6c2ce855

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    20973567    10485760   8e  Linux LVM

/dev/sdb2        20973568    41943039    10484736   8e  Linux LVM

 

Command (m for help): w        保存退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

[[email protected] ~]# pvcreate /dev/sdb{1,2}            创建物理卷

  Physical volume "/dev/sdb1" successfully created.

  Physical volume "/dev/sdb2" successfully created.

[[email protected] ~]# pvdisplay                   查看物理卷

 

[[email protected] ~]# vgcreate zz /dev/sdb1 /dev/sdb2            创建物理卷组

  Volume group "zz" successfully created

[[email protected] ~]# vgdisplay                   查看物理卷组

 

[[email protected] ~]# lvcreate -L 5G -n sb zz              创建逻辑卷

  Logical volume "sb" created.

[[email protected] ~]# lvdisplay /dev/zz/sblvdisplay /dev/zz/sb         查看逻辑卷

  --- Logical volume ---

  LV Path                /dev/zz/sb

  LV Name                sb

  VG Name                zz

  LV UUID                fFHyw1-Tbu1-zVxP-GOZM-t9D4-sHx8-5qRYSp

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2020-04-10 00:22:13 +0800

  LV Status              available

  # open                 0

  LV Size                5.00 GiB

  Current LE             1280

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:2

  

  Failed to find logical volume "zz/sblvdisplay"

 

 

[[email protected] ~]# lvextend -L +2G /dev/zz/sb              逻辑卷扩容

  Size of logical volume zz/sb changed from 5.00 GiB (1280 extents) to 7.00 GiB (1792 extents).

  Logical volume zz/sb successfully resized.

 

 

[[email protected] ~]# lvdisplay /dev/zz/sb                  查看逻辑卷

  --- Logical volume ---

  LV Path                /dev/zz/sb

  LV Name                sb

  VG Name                zz

  LV UUID                fFHyw1-Tbu1-zVxP-GOZM-t9D4-sHx8-5qRYSp

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2020-04-10 00:22:13 +0800

  LV Status              available

  # open                 0

  LV Size                7.00 GiB

  Current LE             1792

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:2

  

 

[[email protected] ~]# mkfs.ext4 /dev/zz/sb               格式化成为ext4格式

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

458752 inodes, 1835008 blocks

91750 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1879048192

56 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

 

[[email protected] ~]# mkdir /abc                创建一个配额目录

[[email protected] ~]# mount /dev/zz/sb /abc/          将逻辑卷挂载到目录中

[[email protected] ~]# resize2fs /dev/zz/sb                 查看系统文件大小

resize2fs 1.42.9 (28-Dec-2013)

The filesystem is already 1835008 blocks long.  Nothing to do!

 

[[email protected] ~]# mount | tail -1         查看挂载类型

/dev/mapper/zz-sb on /abc type ext4 (rw,relatime,seclabel,data=ordered)

[[email protected] ~]# mount -o remount,usrquota,grpquota /dev/zz/sb /abc/       制定挂载类型

[[email protected] ~]# mount | tail -1        查看挂载类型

/dev/mapper/zz-sb on /abc type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)

[[email protected] ~]# chmod 777 /abc/              给配额目录777权限

[[email protected] ~]# vim /etc/fstab                   配置永久挂载

/dev/zz/sb              /abc                    ext4    defaults,usrquota,grpquota      0 0

[[email protected] ~]# mount –a                  刷新配置文件

[[email protected] ~]# setenforce 0            关闭沙盒

[[email protected] ~]# ll /abc/                       查看配额目录类型

total 16

drwx------. 2 root root 16384 Apr 10 00:22 lost+found

[[email protected] ~]# quotacheck –augcv                  创建配额

quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.

quotacheck: Scanning /dev/mapper/zz-sb [/abc] done

quotacheck: Cannot stat old user quota file /abc/aquota.user: No such file or directory. Usage will not be subtracted.

quotacheck: Cannot stat old group quota file /abc/aquota.group: No such file or directory. Usage will not be subtracted.

quotacheck: Cannot stat old user quota file /abc/aquota.user: No such file or directory. Usage will not be subtracted.

quotacheck: Cannot stat old group quota file /abc/aquota.group: No such file or directory. Usage will not be subtracted.

quotacheck: Checked 2 directories and 0 files

quotacheck: Old file not found.

quotacheck: Old file not found.

[[email protected] ~]# ll /abc/

total 32

-rw-------. 1 root root  6144 Apr 10 00:26 aquota.group

-rw-------. 1 root root  6144 Apr 10 00:26 aquota.user

drwx------. 2 root root 16384 Apr 10 00:22 lost+found

 

[[email protected] ~]# useradd zs                创建配额用户

[[email protected] ~]# edquota -u zs           添加zs用户到配额中

Disk quotas for user zs (uid 1001):

 Filesystem             blocks       soft       hard     inodes     soft     hard

 /dev/mapper/zz-sb       0          0          0          0        0        3

 

[[email protected] ~]# quotaon -ugv /abc           开启配额

/dev/mapper/zz-sb [/abc]: group quotas turned on

/dev/mapper/zz-sb [/abc]: user quotas turned on

 

切换zs用户验证:

[[email protected] ~]# su - zs

[[email protected] ~]$ cd /abc/

[[email protected] abc]$ touch 1

[[email protected] abc]$ touch 2

[[email protected] abc]$ touch 3

[[email protected] abc]$ touch 4

dm-2: write failed, user file limit reached.

touch: cannot touch ‘4’: Disk quota exceeded

相关文章: