Linux中使用lvm管理磁盘

操作系统 CentOS Linux release 7.8.2003 (Core)

1、检查系统中是否安装了LVM管理工具

# rpm -qa|grep lvm
[root@yktServer ~]# rpm -qa |grep lvm
lvm2-libs-2.02.186-7.el7_8.2.x86_64
lvm2-2.02.186-7.el7_8.2.x86_64

2、如果未安装,则使用yum安装

# yum -y install lvm*

# rpm -qa|grep lvm

3、如果使用操作系统默认的分区,CentOS7是使用LVM分区,且已有一个vg卷组名为 centos

[root@yktServer ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               49.50 GiB
  PE Size               4.00 MiB
  Total PE              12673
  Alloc PE / Size       12673 / 49.50 GiB
  Free  PE / Size       0 / 0   
  VG UUID               WAwVNx-NAA5-Jn3e-44P9-UwOn-IHMk-TPZD1v

4、查看磁盘情况,可以看到操作系统默认有一个LVM分区为 /dev/sda2

[root@yktServer ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000b6ad5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM

Disk /dev/mapper/centos-root: 44.6 GB, 44560285696 bytes, 87031808 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 /dev/mapper/centos-swap: 8594 MB, 8594128896 bytes, 16785408 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

这个/dev/sda2即为/dev/mapper/centos-root的大小,挂载在 / 分区,使用xfs硬盘分区格式

[root@yktServer dev]# df -lT
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
devtmpfs                devtmpfs   1918820       0   1918820   0% /dev
tmpfs                   tmpfs      1930652       0   1930652   0% /dev/shm
tmpfs                   tmpfs      1930652   11820   1918832   1% /run
tmpfs                   tmpfs      1930652       0   1930652   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       43499776 2109112  41390664   5% /
/dev/sda1               xfs         508580  190788    317792  38% /boot
tmpfs                   tmpfs       386132       0    386132   0% /run/user/0

5、使用lvm实现,/ 分区的扩容,也就是/dev/mapper/centos-root的扩容。所以我们增加一块硬盘为 /dev/sdb,并且格式化成LVM分区

[root@yktServer dev]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa33f228b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM

6、使新添加的硬盘/dev/sdb支持lvm技术。

[root@yktServer dev]# pvcreate /dev/sdb
[root@yktServer dev]# pvscan
  PV /dev/sda2   VG centos          lvm2 [<39.51 GiB / 0    free]
  PV /dev/sdb1   VG centos          lvm2 [<10.00 GiB / 0    free]
  Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0   ]

7、将dev/sdb1加入vg卷组

[root@yktServer dev]# vgextend centos /dev/sdb1

8、扩展大小,使用Free PE,将空闲的pv加入vg

lvextend -l +2000 /dev/mapper/centos-root  #l +是PE的数量
lvextend -L +2048M /dev/mapper/centos-root  #L +是字节数,M/G 等单位

在这里插入图片描述
10、刷新

[root@yktServer dev]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=6, agsize=2064640 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=10878976, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4032, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

扩展 / 分区 大小完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值