打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

虚拟机 /dev/mapper/centos-root 动态扩容

[root@bogon ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.2G  6.2G   51M 100% /
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.6M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/sda1               1014M  175M  840M  18% /boot
tmpfs                    184M     0  184M   0% /run/user/0

 

该LVM分区动态扩容分两种情况:

一、扩容原有磁盘/dev/sda

首先在虚拟机控制台扩容已有的sda后

 1 fdisk /dev/sda 对/dev/sda磁盘进行操作(新建分区及格式化)
 2 n
 3 p
 4 回车 默认分区号;
 5 回车 默认磁盘创建开始位置;
 6 回车 默认磁盘创建结束位置;
 7 t 设置分区类型
 8 8e LVM类型
 9 w 保存
10 重启
11 ls /dev/sd* 会发现多出一个/dev/sda3
12 lvm 进入lvm管理
13 lvm>pvcreate /dev/sda3 创建逻辑卷
14 lvm>vgextend centos /dev/sda3  //将初始化过的分区加入到虚拟卷组 centos
15 lvm>vgdisplay -v
16 lvm>lvextend -L +100G /dev/mapper/centos-root
17 lvm>pvdisplay   //查看卷容量
18 lvm>quit   
19 使用命令xfs_growfs /dev/mapper/centos-root扩展容量
20 df -h 进行查看扩容之后的

 

二、新加磁盘进行扩容

在虚拟机控制台新加磁盘后,并重启虚拟机

[root@bogon ~]# ls /dev/sd* 会发现多出一个/dev/sdb
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb
[root@bogon ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   2   0 wz--n- <7.00g    0
[root@bogon ~]# pvcreate /dev/sdb
WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb.
  Physical volume "/dev/sdb" successfully created.
[root@bogon ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   2   0 wz--n- <7.00g    0
[root@bogon ~]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended
[root@bogon ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   2   0 wz--n- 26.99g <20.00g
[root@bogon ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao----  <6.20g
  swap centos -wi-ao---- 820.00m
[root@bogon ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.2G  6.2G   43M 100% /
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.6M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/sda1               1014M  175M  840M  18% /boot
tmpfs                    184M     0  184M   0% /run/user/0
[root@bogon ~]# lvextend -L +20G /dev/mapper/centos-root
  Insufficient free space: 5120 extents needed, but only 5119 available
[root@bogon ~]# lvextend -L +19G /dev/mapper/centos-root
  Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to <16.20 GiB (4146 extents).
  Logical volume centos/root successfully resized.
[root@bogon ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=406016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1624064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
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 1624064 to 4245504
[root@bogon ~]# df -h
完成。


posted on 2019-09-23 17:16  星辰大海ゞ  阅读(2209)  评论(0编辑  收藏  举报