current position:Home>Create lvm logical volumes and disk quotas

Create lvm logical volumes and disk quotas

2022-08-06 19:32:46Memo for Seniors

一、什么是lvm逻辑卷?

1.1 lvm逻辑卷概念

LVM 是 Logical Volume Manager 的简称,译为中文就是逻辑卷管理.它是 Linux 下对硬盘分区的一种管理机制.LVM 适合于管理大存储设备,并允许用户动态调整文件系统的大小.此外,LVM 的快照功能可以帮助我们快速备份数据.LVM 为我们提供了逻辑概念上的磁盘,使得文件系统不再关心底层物理磁盘的概念.

  • 物理卷(Physical Volume,PV):就是真正的物理硬盘或分区.
  • 卷组(Volume Group,VG):将多个物理卷合起来就组成了卷组.组成同一个卷组的物理卷可以是同一块硬盘的不同分区,也可以是不同硬盘上的不同分区.我们可以把卷组想象为一块逻辑硬盘.
  • 逻辑卷(Logical Volume,LV):卷组是一块逻辑硬盘,硬盘必须分区之后才能使用,我们把这个分区称作逻辑卷.逻辑卷可以被格式化和写入数据.我们可以把逻辑卷想象为分区.
  • 物理扩展(Physical Extend,PE):PE 是用来保存数据的最小单元,我们的数据实际上都是写入 PE 当中的.PE 的大小是可以配置的,默认是 4MB.

1.2 逻辑卷管理--lvm

1.动态调整磁盘容量,从而提高磁盘管理的灵活性

2./boot分区用于存放引导文件,不能基于lvm创建

3.图形界面管理工具

Work without graphics:To reduce hardware resource consumption

1.3 Establish logical volume conditions:

  1. Have a physical disk:物理卷(It can be a partition or a whole hard disk) /dev/sdc Indicates the entire hard disk /dev/sdc1 表示一个分区
  2. Combine multiple physical volumes into volume groups(Volume group capacity is drawn from physical volumes)
  3. The capacity to create a logical volume is drawn from the volume group(The logical volume capacity is determined by the volume group)

PS:To use a partition as a logical volume, be sure to change the system file format of the partition

二、How to create logical volumes?

2.1 建立物理卷

命令格式:

pvcreate /dev/sd{b1,c}

命令+设备名(It can be a partition or a whole hard disk)

image.pngPS:partition as a logical volume,To set a physical volume, change the physical volume type to 8e类型

2.2 建立卷组

命令格式:

vgcreate vg0 /dev/sdb1 /dev/sdc

命令+卷组名称+物理卷名称...

image.png

2.3 建立逻辑卷

命令格式:

lvcreate -L 15G -n lv1 vg0

命令+指定逻辑卷的大小+The set logical volume name+Create a logical volume from a volume group with a name

image.png

2.4 Create a file system and mount it

After the logical volume is created,Same as we create partitions,没有文件系统,Also no mount is unusable,So we have to do the following two steps:

第一步:建立文件系统:

命令格式:mkfs.xfs /dev/vg0/lv1 image.png

第二步:挂载

image.png PS:如上图所示,我们sdcThe normal display belongs to a logical volume,但是分区sdb1未显示,It's because of ourselvessdcis higher than the logical volume's capacity,If the logical volume capacity is higher than the logical volumesdcThe capacity of a single disk,sdb1The partition will appear on the logical volume as extra space in the volume grouplv1组中.

三、How to expand the logical volume?

3.1 The logical volume has enough space in the original volume group

If there is enough space in our logical volume, we can directly use the following command to expand the volume group:

命令格式:lvextend -L +10G /dev/vg0/lv1

命令+Expansion space size+The path name of the logical volume

image.png

image.pngPS:during command input,The command to increase the logical volume capacity must be used“+”Keep up with capacity space.

如上图所示,如果不加“+”,Our logical volume capacity will be=10G,But the initial size set by our logical volume is 15G,Equivalent to the capacity has been reduced,Adding internal files has been used over10G,Then if we use the wrong command, our files will be lost

3.2 The logical volume does not have enough space in the original volume group

第一步:Expand the volume group first

命令:vgextend vg0 /dev/sdd 命令+卷组名+The hard disk or partition that needs to be added to the volume group

image.png 第二步:Expand the logical volume

命令格式:lvextend -L +10G /dev/vg0/lv1 命令+The size of the expansion space+逻辑卷的路径

image.png

image.png PS:如果是xfsThe filesystem is to be refreshed using the mount point:

xfs_growfs /mnt(Refresh mount point command)

扩容中-rThe option is to directly expand the command format as follows:

lvextend -r -L +10G /dev/vg0/lv1

四、磁盘配额

4.1 磁盘配额概述

磁盘配额(Quota)就是 Linux 系统中用来限制特定的普通用户或用户组在指定的分区上占用的磁盘空间或文件个数的.在此概念中,有以下几个重点需要注意:

  1. 磁盘配额限制的用户和用户组,只能是普通用户和用户组,也就是说超级用户 root 是不能做磁盘配额的;
  2. 磁盘配额限制只能针对分区,而不能针对某个目录.
  3. 我们可以限制用户占用的磁盘容量大小(block),当然也能限制用户允许占用的文件个数(inode)

4.2 实现磁盘配额的条件

  1. 需要Linux内核支持
  2. 安装xfsprogs与quote软件包

4.3 Linux磁盘配额的特点

  • 作用范围:针对指定的文件系统(分区)
  • 限制对象:用户账号、组账号
  • 限制类型:磁盘容量、文件数量
  • 限制方法:软限制(Warning or not reminding)、硬限制(Enforced limits are not available)

4.4 How to configure disk quotas

Let's use a hard disk as an example,我们创建了一个sdb1partitions and onezhangsan用户,Next we set the followingsdb1The partition's disk quota:

第一步:添加磁盘配额属性

image.png 我们使用命令mountCheck whether the permission is established successfully:

image.png Our mounts are temporary mounts and we need to create permanent mounts:

使用vim /etc/fstab命令进行设置

image.png 保存退出后使用mount -a检查是否出错

第二步:Set soft and hard limits

基本命令:xfs_quota [选项] +条件内容

The options are as follows:

选项功能
x启动专家模式
c直接调用管理命令
u指定用户账户对象
g指定组账号对象

Options abovex有先后顺序,xOptions must come first

xfs_quota -x -c 'limit -u bsoft=80M bhard=100M isoft=40 ihard=50 zhangsan' /mnt/

image.png

We now switch to userszhangsan,并进入/mnt目录下创建文件1-20,and see if you can create the first21个文件:

image.png In turn, let's see if the file size is limited,We delete all the files we just created,Then create a fixed size in the empty directory in batches150M和151M的文件,Check out the difference between the two files:

image.png 150MThe file can be created normally,Let's delete this file again,创建一个151M的文件:

image.png

image.png From above we can see that our hard link restricts the creation of the file,So we newly created151MThe files are actually only 150M内容,The content of the file is incomplete,则无法使用.

copyright notice
author[Memo for Seniors],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/218/202208061926556641.html

Random recommended