OpenStack中的虚拟机(/dev/mapper/centos-root)进行磁盘扩容

时间:2023-03-09 02:44:55
OpenStack中的虚拟机(/dev/mapper/centos-root)进行磁盘扩容

一、虚拟机上先扩展分区:

OpenStack中的虚拟机(/dev/mapper/centos-root)进行磁盘扩容

二、centos系统root登入,新建分区

2.1 【fdisk -l】 最大分区为/dev/sda2,说明新创建的分区将会是sda3(在后面的步骤会进行选择)

2.2 输入【fdisk /dev/sda】

2.2.1命令行提示下输入【m】

2.2.2输入命令【n】添加新分区。

2.2.3输入命令【p】创建主分区。

2.2.4输入【回车】,选择默认

2.2.5输入【回车】,选择默认

2.2.6输入【w】,保持修改

2.3 输入【reboot】 重启linux,必须reboot,否则/dev/sda3无法格式化。

2.4 这时在/dev/目录下,才能看到了新的分区比如/dev/sda3

三、扩展/dev/mapper/centos-root

3.1.创建pv(给刚刚新建的分区 /dev/sda3)

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

3.2.把pv加入vg中,相当于扩充vg的大小

先使用vgs查看vg组

[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos wz--n- .51g 40.00m<br>

扩展vg,使用vgextend命令

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

3.3.我们成功把vg卷扩展了,在用vgs查看一下

[root@localhost ~]# vgs
VG     #PV #LV #SN Attr   VSize  VFree
  centos         wz--n- .50g .04g
[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- .47g                                                   
  swap centos -wi-ao----  .00g  虽然我们把vg扩展了,但是lv还没有扩展

3.4.扩展lv,使用lvextend命令

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

查看lv大小

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

查看df  -h中变化没有

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   18G  .1G   17G    % /
devtmpfs                 479M       479M    % /dev
tmpfs                    489M       489M    % /dev/shm
tmpfs                    489M  6.7M  483M    % /run
tmpfs                    489M       489M    % /sys/fs/cgroup
/dev/sda1                497M  125M  373M   % /boot
tmpfs                     98M        98M    % /run/user/<br><br>没有变化。

那么我们要使用[root@localhost ~]# xfs_growfs /dev/mapper/centos-root 命令使系统重新读取大小

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=    agcount=, agsize= blks
         =                       sectsz=   attr=, projid32bit=
         =                       crc=        finobt=
data     =                       bsize=   blocks=, imaxpct=
         =                       sunit=      swidth= blks
naming   =version               bsize=   ascii-ci= ftype=
log      =internal               bsize=   blocks=, version=
         =                       sectsz=   sunit= blks, lazy-count=
realtime =none                   extsz=   blocks=, rtextents=
data blocks changed from to

再使用df  -h查看

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

到这里我们就成功扩展了。