分享

VMware实现虚拟机磁盘扩容

 白杨4546 2022-04-17

情况描述

VMware安装虚拟机后,磁盘空间不足,需要进行扩展。
系统版本:Centos 7
可用空间


扩容步骤

  1. 关机
    如下图所示,为当前虚拟机扩展磁盘容量时,需要先关闭虚拟机

  1. 选择编辑虚拟机设置

  1. 选择左侧【硬盘】,右侧点击【扩展】

  2. 输入扩展后的硬盘大小(非增量,而是增加后的总量)
    这里以从10GB增加15GB,到25GB为例

  1. 点击扩展,弹出提示,确定。
  2. 启动虚拟机,执行以下命令(对新增硬盘进行分区):
    fdisk /dev/sda
    p(查看已有分区,用于确定新增分区号)
    n
    p
    3(分区号,由已有最大分区号+1得到)
    回车(默认起始扇区)
    回车(默认结束扇区)
    t(修改分区类型)
    3
    8e(分区类型,Linux LVM partition)
    w(将改动写入分区)
    完成后自动退出,具体细节如下:
[root@client ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

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


命令(输入 m 获取帮助):p

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

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

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

命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 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)
正在同步磁盘。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  1. 重启系统shutdown -r now
  2. 对新增硬盘格式化
    执行mkfs.ext3 /dev/sda3 (数字3由第6步情况决定)
[root@client ~]# mkfs.ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  1. 添加新LVM到已有的LVM组,实现扩容:
    lvm
    lvm> pvcreate /dev/sda3
    lvm>vgextend centos /dev/sda3
    lvm>lvextend -L +14.9G /dev/mapper/centos-root //注意14.9为实际新增的容量,根据前面添加的空间设定
    lvm>pvdisplay
    lvm>quit

  2. 文件系统扩容
    xfs_growfs /dev/mapper/centos-root

  3. 检查
    df -h
    显示如下:

文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.6M  478M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   23G  7.6G   16G   33% /
/dev/sda1               1014M  171M  844M   17% /boot
tmpfs                     98M  4.0K   98M    1% /run/user/42
tmpfs                     98M   28K   98M    1% /run/user/0
/dev/sr0                 4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

扩容成功
扩容成功。

情况描述

VMware安装虚拟机后,磁盘空间不足,需要进行扩展。
系统版本:Centos 7
可用空间


扩容步骤

  1. 关机
    如下图所示,为当前虚拟机扩展磁盘容量时,需要先关闭虚拟机

  1. 选择编辑虚拟机设置

  1. 选择左侧【硬盘】,右侧点击【扩展】

  2. 输入扩展后的硬盘大小(非增量,而是增加后的总量)
    这里以从10GB增加15GB,到25GB为例

  1. 点击扩展,弹出提示,确定。
  2. 启动虚拟机,执行以下命令(对新增硬盘进行分区):
    fdisk /dev/sda
    p(查看已有分区,用于确定新增分区号)
    n
    p
    3(分区号,由已有最大分区号+1得到)
    回车(默认起始扇区)
    回车(默认结束扇区)
    t(修改分区类型)
    3
    8e(分区类型,Linux LVM partition)
    w(将改动写入分区)
    完成后自动退出,具体细节如下:
[root@client ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

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


命令(输入 m 获取帮助):p

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

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

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

命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 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)
正在同步磁盘。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  1. 重启系统shutdown -r now
  2. 对新增硬盘格式化
    执行mkfs.ext3 /dev/sda3 (数字3由第6步情况决定)
[root@client ~]# mkfs.ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  1. 添加新LVM到已有的LVM组,实现扩容:
    lvm
    lvm> pvcreate /dev/sda3
    lvm>vgextend centos /dev/sda3
    lvm>lvextend -L +14.9G /dev/mapper/centos-root //注意14.9为实际新增的容量,根据前面添加的空间设定
    lvm>pvdisplay
    lvm>quit

  2. 文件系统扩容
    xfs_growfs /dev/mapper/centos-root

  3. 检查
    df -h
    显示如下:

文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.6M  478M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   23G  7.6G   16G   33% /
/dev/sda1               1014M  171M  844M   17% /boot
tmpfs                     98M  4.0K   98M    1% /run/user/42
tmpfs                     98M   28K   98M    1% /run/user/0
/dev/sr0                 4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

扩容成功
扩容成功。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多