1、 在虚拟机中对系统磁盘进行扩容看起来非常容易,只需要在vm控制器中扩容即可。以VMware中安装的centos7为例:
点击上图中的扩展按钮,并将原本的硬盘空间从180GB扩展到280GB。
2、事情并没有想象的那么简单,当我启动centos系统,并以root用户登录系统后,执行df -lh命令来查看磁盘空间,我发现扩容的空间并没有分配给各个磁盘,磁盘空间的总和依然为180GB。如下图:
3、使用fdisk -l命令列出磁盘分区表,发现只存在三个分区,总大小是192G,磁盘总大小为300.6G,还有100多G未分配空间。
4、使用fdisk命令创建一个新的分区,根据提示输入相应的命令,m获取帮助。
输入n创建分区,然后根据下一步的提示输入p或者e,p代表主分区,e代表扩展分区,这里我选择了p,默认回车,将剩余所有空间都用于该分区,最后输入w写入磁盘。
由于之前已经有三个分区,所以分区号默认为4,路径/dev/sda4。写入磁盘完毕后,切记一定要执行reboot,重启系统,否则新磁盘无法找到。
5、创建PV
6、查看VG
7、扩容VG
8、查看LV信息
9、选择需要扩容的LV,执行扩容命令,比如扩容根目录/,就需要扩容LV NAME 为 root的LV
10、对LV执行调整
11、再次查看磁盘容量,发现已经扩容成功,根目录 / 的容量变成了249G
其中LV执行调整的命令根据系统版本有区别:
xfs_growfs /dev/cl/root // centos7
resize2fs /dev/cl/root //centos6
名词解释:
1. 物理卷Physical volume (PV):可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者回环文件(loopback file)。物理卷包括一个特殊的header,其余部分被切割为一块块物理区域(physical extents)。 Think of physical volumes as big building blocks which can be used to build your hard drive.
2. 卷组Volume group (VG):将一组物理卷收集为一个管理单元。Group of physical volumes that are used as storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.
3. 逻辑卷Logical volume (LV):虚拟分区,由物理区域(physical extents)组成。A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partitions.
4. 物理区域Physical extent (PE):硬盘可供指派给逻辑卷的最小单位(通常为4MB)。A small part of a disk (usually 4MB) that can be assigned to a logical Volume. Think of physical extents as parts of disks that can be allocated to any partition.