扩容虚拟机

2019-01-19  本文已影响0人  小鬼客

如何扩充虚拟机(centos)的内存

1.查看虚拟机的挂载情况

命令: df -h


image.png

2. 扩大VMWare硬盘空间

image.png

3.没有找到挂载点,默认是/dev/sda必须要先试用fdisk格式化,初始化挂载磁盘才可以使用

[root@code ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a89c1

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

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


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

[root@code ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

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


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

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

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   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
起始 扇区 (41943040-125829119,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-125829119,默认为 125829119):
将使用默认值 125829119
分区 3 已设置为 Linux 类型,大小设为 40 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)
正在同步磁盘。
[root@code ~]#

4. 重新启动虚拟机 roboot

5. 格式化分区,mkfs.ext3 /dev/sda3一直挂载的分区是sda3;

6.输入以下指令:

lvm    //进入lvm管理
lvm>pvcreate /dev/sda3 
lvm>vgextend centos /dev/sda3  //将初始化过的分区加入到虚拟卷组centos
lvm>vgdisplay -v
lvm>lvextend -l+1298 /dev/mapper/centos-root
lvm>pvdisplay
lvm>quit 

7.使用命令xfs_growfs /dev/mapper/centos-root扩展容量。

8. ok ,df -h 查看扩容结果

上一篇下一篇

猜你喜欢

热点阅读