前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >VM虚拟机扩容操作

VM虚拟机扩容操作

作者头像
summerking
发布2022-09-16 12:07:42
发布2022-09-16 12:07:42
1.2K00
代码可运行
举报
文章被收录于专栏:summerking的专栏summerking的专栏
运行总次数:0
代码可运行

之前在VMware上虚拟出了几个Centos搭建环境,随手分了80G给每台虚拟机,可是随着业务的发展,我发现虚拟机的磁盘空间不够了。这里记录下如何操作!

# 1.扩展注意事项

  1. 扩展需要重启虚拟机
  2. 无法扩展具有快照的虚拟机中的磁盘

# 2.扩容

  • 1.关闭虚拟机,点击硬盘

这里我们填写扩展的磁盘容量500G

  • 2.查看磁盘情况

点击查看

代码语言:javascript
代码运行次数:0
运行
复制
Last login: Sat Feb 20 10:04:59 2021 from 192.168.0.127
[root@master ~]# fdisk -l

磁盘 /dev/sda:536.9 GB, 536870912000 字节,1048576000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c7642

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   167772159    82836480   8e  Linux LVM

磁盘 /dev/mapper/centos-root:51.3 GB, 51308920832 字节,100212736 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:8455 MB, 8455716864 字节,16515072 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-home:25.1 GB, 25052577792 字节,48930816 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@master ~]# 

可以看到新增磁盘 /dev/sda

  • 3.fdisk执行分区

点击查看

代码语言:javascript
代码运行次数:0
运行
复制
[root@master ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):3
起始 扇区 (167772160-1048575999,默认为 167772160):
将使用默认值 167772160
Last 扇区, +扇区 or +size{K,M,G} (167772160-1048575999,默认为 1048575999):
将使用默认值 1048575999
分区 3 已设置为 Linux 类型,大小设为 420 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@master ~]# 

  • 4.重启虚拟机
代码语言:javascript
代码运行次数:0
运行
复制
[root@master ~]# reboot
PolicyKit daemon disconnected from the bus.
We are no longer a registered authentication agent.

连接断开

  • 5.执行配置
代码语言:javascript
代码运行次数:0
运行
复制
连接成功
Last login: Sat Feb 20 11:21:00 2021 from 192.168.0.112
[root@master ~]# lvs //报告有关逻辑卷的信息
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----  23.33g                                                    
  root centos -wi-ao---- <47.79g                                                    
  swap centos -wi-a-----  <7.88g                                                    
[root@master ~]# pvcreate /dev/sda3 //将物理硬盘分区初始化为物理卷,以便LVM使用
  Physical volume "/dev/sda3" successfully created.
[root@master ~]# vgextend centos /dev/sda3  //使用vgextend命令将物理卷/dev/sda3加入卷组centos
  Volume group "centos" successfully extended
[root@master ~]# vgdisplay  //显示LNM卷组的元数据信息
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               498.99 GiB
  PE Size               4.00 MiB
  Total PE              127742
  Alloc PE / Size       20222 / 78.99 GiB
  Free  PE / Size       107520 / 420.00 GiB  //这里就是可供分配的自由空间,最多有 420G,在扩展时输入小于该值即可
  VG UUID               xwALwi-FXZM-uQLS-792B-Bxoq-wOJx-lrdCHL
   
[root@master ~]# e2fsck -f /dev/mapper/centos-root //检查文件系统是否正常
e2fsck 1.42.9 (28-Dec-2013)
/dev/mapper/centos-root is mounted.
e2fsck: 无法继续, 中止.

  • 6.硬盘扩容
代码语言:javascript
代码运行次数:0
运行
复制
[root@master ~]# lvextend -L+419.99G /dev/mapper/centos-root /dev/sda3 
  Rounding size to boundary between physical extents: 419.99 GiB.
  Size of logical volume centos/root changed from <47.79 GiB (12233 extents) to <467.78 GiB (119751 extents).
  Logical volume centos/root successfully resized.
[root@master ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3131648 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12526592, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6116, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12526592 to 122625024

# 3.验证

代码语言:javascript
代码运行次数:0
运行
复制
[root@master ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root  468G   25G  444G    6% /
devtmpfs                 7.8G     0  7.8G    0% /dev
tmpfs                    7.8G     0  7.8G    0% /dev/shm
tmpfs                    7.8G   12M  7.8G    1% /run
tmpfs                    7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M   14% /boot
/dev/mapper/centos-home   24G  4.1G   20G   18% /home
tmpfs                    1.6G     0  1.6G    0% /run/user/1000
tmpfs                    1.6G     0  1.6G    0% /run/user/0
[root@master ~]# 
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-02-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • # 1.扩展注意事项
  • # 2.扩容
  • # 3.验证
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档