临时清除配额永久清楚配额限制限制以及创建逻辑卷和逻辑卷的在线拉伸

准备工作

1、查看当前磁盘使用情况

[root@wanghaihan ~]# df -Th | grep -v tmp  ---查看分区情况
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        27G   15G   13G  54% /
/dev/sr0              iso9660   4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1             xfs      1014M  239M  776M  24% /boot
/dev/nvme0n1p5        vfat      699M  4.0K  699M   1% /mnt/win
/dev/nvme0n1p2        xfs       497M   26M  472M   6% /mnt/xfs2
/dev/nvme0n1p1        ext4      190M   92M   85M  53% /mnt/xfs1
[root@wanghaihan ~]# swapon -s  ---查看当前系统处于使用状态的交换分区信息
Filename				Type		Size	Used	Priority
/dev/nvme0n1p6                         	partition	2097148	0	-2
/dev/dm-1                              	partition	2097148	0	-3
[root@wanghaihan ~]# ls -lh /mnt/  
total 9.0K
dr-xr-xr-x. 9 root root 4.0K Feb 26  2020 cdrom
drwxr-xr-x. 2 root root  156 Apr  4 14:12 rpm
drwxr-xr-x. 2 root root 4.0K Jan  1  1970 win
drwxrwxrwx. 2 root root 1.0K Apr 12 16:54 xfs1
drwxr-xr-x. 2 root root    6 Apr 11 15:43 xfs2
[root@wanghaihan ~]# umount /mnt/xfs1  ---将文件系统下线
[root@wanghaihan ~]# umount /mnt/xfs2 
[root@wanghaihan ~]# vim /etc/fstab   ---将设置的自动挂载删除或者设为备注

2、将挂载的文件系统设为备注,因为要删除分区用于后续实验

image.png

3、删除分区

image.png

[root@wanghaihan ~]# partprobe /dev/nvme0n1  ---重新识别分区
[root@wanghaihan ~]# cat /proc/partitions   ---查看分区情况
major minor  #blocks  name

   8        0   31457280 sda
   8        1    1048576 sda1
   8        2   30407680 sda2
  11        0    4444160 sr0
 253        0   28303360 dm-0
 253        1    2097152 dm-1
 259        0    5242880 nvme0n1
[root@wanghaihan ~]# df -Th | grep -v tmp  ---查看文件系统,nvme0n1的文件系统已经消失
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        27G   15G   13G  54% /
/dev/sr0              iso9660   4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1             xfs      1014M  239M  776M  24% /boot

4、创建分区并挂载

[root@wanghaihan ~]# fdisk /dev/nvme0n1   ---创建新分区
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.


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): 
First sector (2048-10485759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +500M
Partition 1 of type Linux and of size 500 MiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@wanghaihan ~]# partprobe /dev/nvme0n1   ---重新识别分区
[root@wanghaihan ~]# cat /proc/partitions    ---查看分区情况
major minor  #blocks  name

   8        0   31457280 sda
   8        1    1048576 sda1
   8        2   30407680 sda2
  11        0    4444160 sr0
 253        0   28303360 dm-0
 253        1    2097152 dm-1
 259        0    5242880 nvme0n1
 259        1     512000 nvme0n1p1
[root@wanghaihan ~]# mkfs.xfs /dev/nv
nvme0      nvme0n1    nvme0n1p1  nvram      
[root@wanghaihan ~]# mkfs.xfs /dev/nvme0n1p1 
mkfs.xfs: /dev/nvme0n1p1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.
[root@wanghaihan ~]# mkfs.xfs /dev/nvme0n1p1 -f  ---强制格式化文件系统
meta-data=/dev/nvme0n1p1         isize=512    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@wanghaihan ~]# blkid  ---查看分区uuid
/dev/mapper/rhel-root: UUID="5f02bac3-c040-4041-8f4c-722ec5672f36" TYPE="xfs" 
/dev/sda2: UUID="2XwJ40-qMhr-oGfp-IHJF-vHmk-zFFe-2GU8n7" TYPE="LVM2_member" 
/dev/sda1: UUID="2a64bdae-b004-46ff-a94f-5859f9b80f8c" TYPE="xfs" 
/dev/sr0: UUID="2020-02-25-11-40-31-00" LABEL="RHEL-7.8 Server.x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/rhel-swap: UUID="03ee9e10-2937-4042-becb-b20c151ce925" TYPE="swap" 
/dev/nvme0n1: PTTYPE="dos" 
/dev/nvme0n1p1: UUID="2cfb88ad-9a99-40da-864d-f25cb5d9d31a" TYPE="xfs" 
[root@wanghaihan ~]# vim /etc/fstab   ---添加分区自动挂载到目录
[root@wanghaihan ~]# mount -a  ---重新加载文件系统
mount: mount point /mnt/xfs does not exist
[root@wanghaihan ~]# mkdir /mnt/xfs  ---创建挂载目录
[root@wanghaihan ~]# mount -a
[root@wanghaihan ~]# df -Th  ---查看挂载情况
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  893M     0  893M   0% /dev
tmpfs                 tmpfs     910M     0  910M   0% /dev/shm
tmpfs                 tmpfs     910M   11M  900M   2% /run
tmpfs                 tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs        27G   15G   13G  54% /
/dev/sr0              iso9660   4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1             xfs      1014M  239M  776M  24% /boot
tmpfs                 tmpfs     182M   24K  182M   1% /run/user/0
/dev/nvme0n1p1        xfs       497M   26M  472M   6% /mnt/xfs
[root@wanghaihan ~]# vim /etc/fstab   ---添加配额选项

image.png

[root@wanghaihan ~]# umount /mnt/xfs  ---文件系统下线
[root@wanghaihan ~]# mount -a  ---上线
[root@wanghaihan ~]# df -Th | grep xfs  ---查看挂载情况
/dev/mapper/rhel-root xfs        27G   15G   13G  54% /
/dev/sda1             xfs      1014M  239M  776M  24% /boot
/dev/nvme0n1p1        xfs       497M   26M  472M   6% /mnt/xfs
[root@wanghaihan ~]# mount | grep nvme0n1p1  ---查看文件系统详细信息
/dev/nvme0n1p1 on /mnt/xfs type xfs (rw,relatime,seclabel,attr2,inode64,usrquota,prjquota)

5、临时关闭配额限制、重新开启配额限制

[root@wanghaihan ~]# echo "13:/mnt/xfs" > /etc/projects
[root@wanghaihan ~]# echo "xfsquota:13" > /etc/projid
[root@wanghaihan ~]# cat /etc/projects 
13:/mnt/xfs
[root@wanghaihan ~]# cat /etc/projid 
xfsquota:13
[root@wanghaihan ~]# xfs_quota -x -c "limit -p bsoft=280M bhard=300M xfsquota" /mnt/xfs/
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota        0   280M   300M  00 [------]      1      0      0  00 [------]

[root@wanghaihan ~]# cd /mnt/xfs/
[root@wanghaihan xfs]# dd if=/dev/zero of=root1 bs=1M count=200  ---创建文件验证
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.209259 s, 1.0 GB/s
[root@wanghaihan xfs]# dd if=/dev/zero of=root2 bs=1M count=200
dd: error writing ‘root2’: No space left on device
101+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.172867 s, 607 MB/s
[root@wanghaihan xfs]# xfs_quota -x -c "report -pbih" /mnt/xfs/  ---超过软配额后出现天数警告,超出后软配额以外的文件删除
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     300M   280M   300M  00 [7 days]      3      0      0  00 [------]

[root@wanghaihan xfs]# xfs_quota -x -c "disable -up" /mnt/xfs/  ---关闭配额限制
[root@wanghaihan xfs]# dd if=/dev/zero of=root3 bs=1M count=200
dd: error writing ‘root3’: No space left on device
72+0 records in
71+0 records out
74448896 bytes (74 MB) copied, 0.10888 s, 684 MB/s
[root@wanghaihan xfs]# ls -lh
total 471M
-rw-r--r--. 1 root root 200M Apr 13 11:35 root1
-rw-r--r--. 1 root root 200M Apr 13 11:41 root2
-rw-r--r--. 1 root root  71M Apr 13 11:41 root3
[root@wanghaihan xfs]# xfs_quota -x -c "report -pbih" /mnt/xfs/  ---查看后发现配额被关闭
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     471M   280M   300M  00 [-none-]      4      0      0  00 [------]

[root@wanghaihan xfs]# xfs_quota -x -c "state" /mnt/xfs/  ---查看详细信息
User quota state on /mnt/xfs (/dev/nvme0n1p1)
  Accounting: ON
  Enforcement: OFF
  Inode: #67 (1 blocks, 1 extents)
Group quota state on /mnt/xfs (/dev/nvme0n1p1)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (1 blocks, 1 extents)
Project quota state on /mnt/xfs (/dev/nvme0n1p1)
  Accounting: ON
  Enforcement: OFF
  Inode: #68 (1 blocks, 1 extents)
Blocks grace time: [7 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
[root@wanghaihan xfs]# 
[root@wanghaihan ~]# umount /mnt/xfs  ---关闭文件系统
[root@wanghaihan ~]# mount -a  ---重启文件系统
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/  
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     400M   280M   300M  00 [-none-]      3      0      0  00 [------]

[root@wanghaihan ~]# xfs_quota -x -c "enable -up" /mnt/xfs/  ---重新打开磁盘配额
XFS_QUOTAON: File exists
[root@wanghaihan ~]# rm -rf /mnt/xfs/root2
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     200M   280M   300M  00 [------]      2      0      0  00 [------]

[root@wanghaihan ~]# dd if=/dev/zero of=root2 bs=1M count=200
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.143534 s, 1.5 GB/s
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     200M   280M   300M  00 [------]      2      0      0  00 [------]

[root@wanghaihan ~]# dd if=/dev/zero of=root3 bs=1M count=200
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.136811 s, 1.5 GB/s
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/
Project quota on /mnt/xfs (/dev/nvme0n1p1)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
xfsquota     200M   280M   300M  00 [------]      2      0      0  00 [------]

6、永久删除配额限制

  661  xfs_quota -x -c "off -up" /mnt/xfs/  ---开启关闭配额功能
  662  xfs_quota -x -c "remove -p" /mnt/xfs/    ---移除配额配置
[root@wanghaihan ~]# xfs_quota -x -c "state" /mnt/xfs/  --查询配额信息查询不到
[root@wanghaihan ~]# xfs_quota -x -c "report -pbih" /mnt/xfs/
[root@wanghaihan ~]# umount /mnt/xfs   
[root@wanghaihan ~]# vim /etc/fstab   ---关闭文件系统后,将配置文件的配额选项删除
[root@wanghaihan ~]# mount -a
[root@wanghaihan ~]# mount | grep nvme0n1p1  ---配额相关词条已经消失
/dev/nvme0n1p1 on /mnt/xfs type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

二、创建逻辑卷

1、查看分区信息

[root@wanghaihan ~]# df -Th | grep -v tmp  
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        27G   15G   13G  55% /
/dev/sr0              iso9660   4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1             xfs      1014M  239M  776M  24% /boot
/dev/nvme0n1p1        xfs       497M  226M  272M  46% /mnt/xfs
[root@wanghaihan ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-1                              	partition	2097148	0	-2
[root@wanghaihan ~]# lsblk  
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   30G  0 disk 
├─sda1          8:1    0    1G  0 part /boot
└─sda2          8:2    0   29G  0 part 
  ├─rhel-root 253:0    0   27G  0 lvm  /  ---系统自动生成的逻辑分区
  └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]  ---系统自动生成的逻辑分区
sr0            11:0    1  4.2G  0 rom  /mnt/cdrom
nvme0n1       259:0    0    5G  0 disk 
└─nvme0n1p1   259:1    0  500M  0 part /mnt/xfs

2、创建逻辑分区

[root@wanghaihan ~]# fdisk /dev/nvme0n1
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.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e  ---将剩余的空间全部创建成扩展分区
Partition number (2-4, default 2): 3
First sector (1026048-10485759, default 1026048): 
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-10485759, default 10485759): 
Using default value 10485759
Partition 3 of type Extended and of size 4.5 GiB is set

Command (m for help): p

Disk /dev/nvme0n1: 5368 MB, 5368709120 bytes, 10485760 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: 0x7135cfb9

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme0n1p1            2048     1026047      512000   83  Linux
/dev/nvme0n1p3         1026048    10485759     4729856    5  Extended

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l  ---创建逻辑分区
Adding logical partition 5
First sector (1028096-10485759, default 1028096): 
Using default value 1028096
Last sector, +sectors or +size{K,M,G} (1028096-10485759, default 10485759): +800M
Partition 5 of type Linux and of size 800 MiB is set

Command (m for help): p

Disk /dev/nvme0n1: 5368 MB, 5368709120 bytes, 10485760 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: 0x7135cfb9

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme0n1p1            2048     1026047      512000   83  Linux
/dev/nvme0n1p3         1026048    10485759     4729856    5  Extended
/dev/nvme0n1p5         1028096     2666495      819200   83  Linux

Command (m for help): t
Partition number (1,3,5, default 5): 
Hex code (type L to list all codes): 8e  ---装换成8e逻辑卷,83类型会崩溃
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/nvme0n1: 5368 MB, 5368709120 bytes, 10485760 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: 0x7135cfb9

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme0n1p1            2048     1026047      512000   83  Linux
/dev/nvme0n1p3         1026048    10485759     4729856    5  Extended
/dev/nvme0n1p5         1028096     2666495      819200   8e  Linux LVM


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@wanghaihan ~]# partprobe /dev/nvme0n1  ---更新分区信息
[root@wanghaihan ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   31457280 sda
   8        1    1048576 sda1
   8        2   30407680 sda2
  11        0    4444160 sr0
 253        0   28303360 dm-0
 253        1    2097152 dm-1
 259        0    5242880 nvme0n1
 259        1     512000 nvme0n1p1
 259        2          0 nvme0n1p3
 259        3     819200 nvme0n1p5   ---分区创建成功

3、创建逻辑卷

[root@wanghaihan ~]# pvcreate /dev/nvme0n1p5  ---设备初始化
  Physical volume "/dev/nvme0n1p5" successfully created.
[root@wanghaihan ~]# pvs  ---查看物理卷
  PV             VG   Fmt  Attr PSize   PFree  
  /dev/nvme0n1p5      lvm2 ---  800.00m 800.00m
  /dev/sda2      rhel lvm2 a--  <29.00g   4.00m
[root@wanghaihan ~]# vgcreate myvg /dev/nvme0n1p5  ---创建名为myvg卷组
  Volume group "myvg" successfully created
[root@wanghaihan ~]# vgs  ---查看卷组信息
  VG   #PV #LV #SN Attr   VSize   VFree  
  myvg   1   0   0 wz--n- 796.00m 796.00m
  rhel   1   2   0 wz--n- <29.00g   4.00m
[root@wanghaihan ~]# lvcreate -n mylv -L 200M myvg  ---创建名为mylv的逻辑卷
  Logical volume "mylv" created.
[root@wanghaihan ~]# lvs  ---查看逻辑卷信息
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 200.00m                                                    
  root rhel -wi-ao----  26.99g                                                    
  swap rhel -wi-ao----   2.00g   

[root@wanghaihan ~]# mkfs -t ext4 /dev/myvg/mylv  ---初始化逻辑卷
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@wanghaihan ~]# blkid  ---查看分区信息
/dev/mapper/rhel-root: UUID="5f02bac3-c040-4041-8f4c-722ec5672f36" TYPE="xfs" 
/dev/sda2: UUID="2XwJ40-qMhr-oGfp-IHJF-vHmk-zFFe-2GU8n7" TYPE="LVM2_member" 
/dev/sda1: UUID="2a64bdae-b004-46ff-a94f-5859f9b80f8c" TYPE="xfs" 
/dev/sr0: UUID="2020-02-25-11-40-31-00" LABEL="RHEL-7.8 Server.x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/rhel-swap: UUID="03ee9e10-2937-4042-becb-b20c151ce925" TYPE="swap" 
/dev/nvme0n1: PTTYPE="dos" 
/dev/nvme0n1p1: UUID="2cfb88ad-9a99-40da-864d-f25cb5d9d31a" TYPE="xfs" 
/dev/nvme0n1p5: UUID="IjaniZ-29d7-6JIQ-4tFY-0DAP-aTSO-yVWA3c" TYPE="LVM2_member" 
/dev/mapper/myvg-mylv: UUID="4f3cbced-1bdf-446e-a836-7b703814d307" TYPE="ext4"   ---逻辑卷创建成功
[root@wanghaihan ~]# vim /etc/fstab   ---挂载逻辑卷
 

image.png

[root@wanghaihan ~]# mkdir /mnt/lvm  ---创建挂载目录
[root@wanghaihan ~]# ls -l /dev/myvg/mylv 
lrwxrwxrwx. 1 root root 7 Apr 13 19:39 /dev/myvg/mylv -> ../dm-2
[root@wanghaihan ~]# ls -l /dev/mapper/myvg-mylv  ---除了上面的软连接,这个软连接是linux自动生成的,逻辑卷都会有
lrwxrwxrwx. 1 root root 7 Apr 13 19:39 /dev/mapper/myvg-mylv -> ../dm-2
[root@wanghaihan ~]# mount -a  ---挂载
[root@wanghaihan ~]# df -Th | grep lvm  ---挂载成功
/dev/mapper/myvg-mylv ext4      190M  1.6M  175M   1% /mnt/lvm

4、逻辑卷的拉伸

1、方法一

[root@wanghaihan ~]# lvextend -L +400M^C  ---扩容400M
[root@wanghaihan ~]# lvextend -L 600M /dev/myvg/mylv   ---扩容到600M
  Size of logical volume myvg/mylv changed from 200.00 MiB (50 extents) to 600.00 MiB (150 extents).
  Logical volume myvg/mylv successfully resized.
[root@wanghaihan ~]# lvs  
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao---- 600.00m                                                    
  root rhel -wi-ao----  26.99g                                                    
  swap rhel -wi-ao----   2.00g                                                    
[root@wanghaihan ~]# df -Th | grep lvm  ---此时查看还没有扩容
/dev/mapper/myvg-mylv ext4      190M  1.6M  175M   1% /mnt/lvm
[root@wanghaihan ~]# resize2fs /dev/myvg/mylv   ---通知文件系统扩容
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 5
The filesystem on /dev/myvg/mylv is now 614400 blocks long.

[root@wanghaihan ~]# df -Th | grep lvm  ---在线扩容成功
/dev/mapper/myvg-mylv ext4      578M  2.3M  545M   1% /mnt/lvm

2、方法二

[root@wanghaihan ~]# fdisk /dev/nvme0n1   ---创建新的逻辑分区
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.


Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (2668544-10485759, default 2668544): 
Using default value 2668544
Last sector, +sectors or +size{K,M,G} (2668544-10485759, default 10485759): +800M
Partition 6 of type Linux and of size 800 MiB is set 

Command (m for help): t
Partition number (1,3,5,6, default 6): 6
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@wanghaihan ~]# partprobe /dev/nvme0n1  ---更新分区信息
[root@wanghaihan ~]# pvcreate /dev/nvme0n1p6  ---设备初始化,创建物理卷
  Physical volume "/dev/nvme0n1p6" successfully created.
[root@wanghaihan ~]# pvs
  PV             VG   Fmt  Attr PSize   PFree  
  /dev/nvme0n1p5 myvg lvm2 a--  796.00m 196.00m
  /dev/nvme0n1p6      lvm2 ---  800.00m 800.00m
  /dev/sda2      rhel lvm2 a--  <29.00g   4.00m
[root@wanghaihan ~]# vgextend myvg /dev/nvme0n1p6    ---创建卷组
  Volume group "myvg" successfully extended
[root@wanghaihan ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  myvg   2   1   0 wz--n-   1.55g 992.00m
  rhel   1   2   0 wz--n- <29.00g   4.00m
[root@wanghaihan ~]# lvresize -L +600M /dev/myvg/mylv   ---创建逻辑卷
  Size of logical volume myvg/mylv changed from 600.00 MiB (150 extents) to 1.17 GiB (300 extents).
  Logical volume myvg/mylv successfully resized.
[root@wanghaihan ~]# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao----  1.17g                                                    
  root rhel -wi-ao---- 26.99g                                                    
  swap rhel -wi-ao----  2.00g                                                    
[root@wanghaihan ~]# df -Th | grep lvm
/dev/mapper/myvg-mylv ext4      578M  2.3M  545M   1% /mnt/lvm
[root@wanghaihan ~]# resize2fs /dev/myvg/mylv   ---通知文件系统
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 10
The filesystem on /dev/myvg/mylv is now 1228800 blocks long.

[root@wanghaihan ~]# df -Th | grep lvm  ---扩容成功
/dev/mapper/myvg-mylv ext4      1.2G  2.7M  1.1G   1% /mnt/lvm

Linux 中,可以使用逻辑卷管理器 LVM 来对用户进行配额限制。下面是具体的操作步骤: 1. 创建逻辑卷 首先,需要创建一个逻辑卷。可以使用 lvcreate 命令来创建: ``` sudo lvcreate -L 10G -n myvol vg01 ``` 其中,-L 选项指定逻辑卷的大小,-n 选项指定逻辑卷的名称,vg01 是卷组的名称。 2. 格式化逻辑卷 接下来,需要对逻辑卷进行格式化,以便可以在上面创建文件系统。可以使用 mkfs 命令来格式化: ``` sudo mkfs.ext4 /dev/vg01/myvol ``` 这里使用的是 ext4 文件系统。 3. 挂载逻辑卷逻辑卷挂载到一个目录下,以便能够访问其中的文件。可以使用 mount 命令来挂载: ``` sudo mount /dev/vg01/myvol /mnt/myvol ``` 其中,/mnt/myvol 是挂载点的路径。 4. 创建用户 创建一个新用户,并将其添加到一个新的组中: ``` sudo useradd -m -G mygrp myuser ``` 其中,-m 选项表示同时创建用户的主目录,-G 选项表示将用户添加到 mygrp 组中。 5. 设置配额 使用 Quota 工具设置配额。首先需要安装 Quota 工具: ``` sudo apt-get install quota ``` 然后,需要启用 Quota 功能,可以在 /etc/fstab 文件中添加 usrquota 和 grpquota 选项: ``` /dev/mapper/vg01-myvol /mnt/myvol ext4 defaults,usrquota,grpquota 0 0 ``` 接下来,需要重新挂载逻辑卷: ``` sudo mount -o remount /mnt/myvol ``` 接着,使用 edquota 命令设置用户配额限制: ``` sudo edquota -u myuser ``` 这将打开一个文本编辑器,让你可以设置该用户配额限制。例如,可以将硬盘配额设置为 1G,软盘配额设置为 900M。 6. 检查配额 使用 repquota 命令检查用户配额限制: ``` sudo repquota /mnt/myvol ``` 这将显示关于该逻辑卷上所有用户配额信息,包括已使用的空间和配额限制
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值