关于centos:CentOS分区VGPVLV

2次阅读

共计 2948 个字符,预计需要花费 8 分钟才能阅读完成。

CentOS 扩容卷组

pv、vg、lv 的意思

物理卷(Physical Volume,PV):就是指硬盘分区,也能够是整个硬盘或已创立的软 RAID,是 LVM 的根本存储设备。

卷组(Volume Group,VG):是由一个或多个物理卷所组成的存储池,在卷组上能创立一个或多个逻辑卷。

逻辑卷(Logical Volume,LV):相似于非 LVM 零碎中的硬盘分区,它建设在卷组之上,是一个规范的块设施,在逻辑卷之上能够建设文件系统。

1. 首先查看咱们的根分区大小是多少

[root@localhost ~]# df -hT
文件系统                类型      容量  已用  可用 已用 % 挂载点
/dev/mapper/centos-root xfs        18G  1.1G   17G    6% /
devtmpfs                devtmpfs  479M     0  479M    0% /dev
tmpfs                   tmpfs     489M     0  489M    0% /dev/shm
tmpfs                   tmpfs     489M  6.7M  483M    2% /run
tmpfs                   tmpfs     489M     0  489M    0% /sys/fs/cgroup
/dev/sda1               xfs       497M  125M  373M   25% /boot
tmpfs                   tmpfs      98M     0   98M    0% /run/user/0<br>

能够看到咱们的根分区大小为 17G

2. 增加一块物理的磁盘。在虚拟机中增加

3. 查看磁盘编号

ls /dev/sd*
/dev/sda  
/dev/sda1  
/dev/sda2  
/dev/sdb

能够看到 sdb 就是咱们方才增加的磁盘
4. 创立 pv

[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created

5. 把 pv 退出 vg 中,相当于裁减 vg 的大小

先应用 vgs 查看 vg 组

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   2   0 wz--n- 19.51g 40.00m

能够看到当初就一个 vg 组其中有两个 lv 卷,若不确定能够通过 lvs 查看是否是咱们须要扩大的分区

[root@localhost ~]# lvs
LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g                                                  swap centos -wi-ao----  2.00g  

能够看到这就是咱们须要扩大的根分区,我这里还有个 swap 分区
扩大 vg,应用 vgextend 命令

[root@localhost ~]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended

vgextend 名字命令接的 vg 的名字,前面是磁盘的地位
6. 咱们胜利把 vg 卷扩大了,在用 vgs 查看一下

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   2   0 wz--n- 39.50g 20.04g
[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 17.47g                                                   
  swap centos -wi-ao----  2.00g  

尽管咱们把 vg 扩大了,然而 lv 还没有扩大
7. 扩大 lv,应用 lvextend 命令

[root@localhost ~]# lvextend -L +20G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 37.47 GiB (9592 extents).
  Logical volume root successfully resized.-

指定扩大多大的空间到 lv 中去,前面的 /dev/mapper/centos-root 是指定扩大的文件地位,可在 df - h 中看见
查看 lv 大小

[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 37.47g                                                
  swap centos -wi-ao----  2.00g  

Tips: 卸载 lv

# 如果卷组容量须要缩小,要先放大 lv(逻辑卷)大小
lvreduce -L -400G /dev/mapper/vg-root
# 从卷组中移除
vgreduce VG_NAME /dev/sdb

查看 df - h 中变动没有

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用 % 挂载点
/dev/mapper/centos-root   18G  1.1G   17G    6% /
devtmpfs                 479M     0  479M    0% /dev
tmpfs                    489M     0  489M    0% /dev/shm
tmpfs                    489M  6.7M  483M    2% /run
tmpfs                    489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                     98M     0   98M    0% /run/user/0

没有变动。
那么咱们要应用[root@localhost ~]# xfs_growfs /dev/mapper/centos-root 命令使零碎从新读取大小

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1144832 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=4579328, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4579328 to 9822208

再应用 df - h 查看

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用 % 挂载点
/dev/mapper/centos-root   38G  1.1G   37G    3% /
devtmpfs                 479M     0  479M    0% /dev
tmpfs                    489M     0  489M    0% /dev/shm
tmpfs                    489M  6.7M  483M    2% /run
tmpfs                    489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                     98M     0   98M    0% /run/user/0

到这里咱们就胜利扩大了。

备注: 咱们能够自行生产 vg 组以及在新的 vg 中生成 lv

vgcreate 创立新的 vg 组

lvcreate 在新的 vg 中创立新的 lv,然而要指定对 vg 名字

vgreduce 把 pv 从 vg 中移除,若 vg 中只有一个 pv 则间接应用 vgremove

正文完
 0