1、 在虛擬機(jī)中對(duì)系統(tǒng)磁盤進(jìn)行擴(kuò)容看起來非常容易,只需要在vm控制器中擴(kuò)容即可。以VMware中安裝的centos7為例:

點(diǎn)擊上圖中的擴(kuò)展按鈕,并將原本的硬盤空間從180GB擴(kuò)展到280GB。
2、事情并沒有想象的那么簡(jiǎn)單,當(dāng)我啟動(dòng)centos系統(tǒng),并以root用戶登錄系統(tǒng)后,執(zhí)行df -lh命令來查看磁盤空間,我發(fā)現(xiàn)擴(kuò)容的空間并沒有分配給各個(gè)磁盤,磁盤空間的總和依然為180GB。如下圖:

3、使用fdisk -l命令列出磁盤分區(qū)表,發(fā)現(xiàn)只存在三個(gè)分區(qū),總大小是192G,磁盤總大小為300.6G,還有100多G未分配空間。

4、使用fdisk命令創(chuàng)建一個(gè)新的分區(qū),根據(jù)提示輸入相應(yīng)的命令,m獲取幫助。

輸入n創(chuàng)建分區(qū),然后根據(jù)下一步的提示輸入p或者e,p代表主分區(qū),e代表擴(kuò)展分區(qū),這里我選擇了p,默認(rèn)回車,將剩余所有空間都用于該分區(qū),最后輸入w寫入磁盤。
由于之前已經(jīng)有三個(gè)分區(qū),所以分區(qū)號(hào)默認(rèn)為4,路徑/dev/sda4。寫入磁盤完畢后,切記一定要執(zhí)行reboot,重啟系統(tǒng),否則新磁盤無(wú)法找到。

5、創(chuàng)建PV

6、查看VG

7、擴(kuò)容VG

8、查看LV信息

9、選擇需要擴(kuò)容的LV,執(zhí)行擴(kuò)容命令,比如擴(kuò)容根目錄/,就需要擴(kuò)容LV NAME 為 root的LV
10、對(duì)LV執(zhí)行調(diào)整

11、再次查看磁盤容量,發(fā)現(xiàn)已經(jīng)擴(kuò)容成功,根目錄 / 的容量變成了249G

其中LV執(zhí)行調(diào)整的命令根據(jù)系統(tǒng)版本有區(qū)別:
xfs_growfs ? /dev/cl/root ? ? ? ? ?// centos7
resize2fs ? /dev/cl/root ? ? ? ? ? ? //centos6
名詞解釋:
? 1. 物理卷Physical volume (PV):可以在上面建立卷組的媒介,可以是硬盤分區(qū),也可以是硬盤本身或者回環(huán)文件(loopback file)。物理卷包括一個(gè)特殊的header,其余部分被切割為一塊塊物理區(qū)域(physical extents)。 Think of physical volumes as big building blocks which can be used to build your hard drive.
????2. 卷組Volume group (VG):將一組物理卷收集為一個(gè)管理單元。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):虛擬分區(qū),由物理區(qū)域(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. 物理區(qū)域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.