擴容虛擬機器硬碟
目錄
擴容虛擬機器硬碟
前提條件
通過fdisk -l
能看到 /dev/mapper/XXXX-lv_swap
和 /dev/mapper/XXXX-lv_root
才可以使用該方法,其中的XXXX
每臺裝置可能不一樣;如下:
[[email protected] ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00024cd6 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 5222 41430016 8e Linux LVM Disk /dev/mapper/VolGroup-lv_root: 38.2 GB, 38193332224 bytes 255 heads, 63 sectors/track, 4643 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 4227 MB, 4227858432 bytes 255 heads, 63 sectors/track, 514 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
關閉linux作業系統
shutdown -h now
新增虛擬機器磁碟
檢視新新增的硬碟對應的linux系統的檔案
使用fdisk -l
檢視系統的磁碟情況,每一個Disk
表示一塊磁碟,由於我們新增的是硬碟,所以是sd
開頭的,而且這塊是新的硬碟所以沒有分割槽資訊; 從上圖看就是sdb
了;
這樣我們知道了新新增的硬碟對應的 linux系統中的哪個檔案了;
擴容磁碟空間
現在開始擴容linux系統的磁碟空間了,此處使用LVM
的知識,有興趣的可以自行去了解下;
新建物理卷,將新新增的硬碟建立為LVM格式的物理卷,
/dev/sdb
磁碟檔案;[[email protected]
檢視邏輯卷組的名稱,也即是
VG Name
;bash [[email protected] ~]# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 39.51 GiB PE Size 4.00 MiB Total PE 10114 Alloc PE / Size 10114 / 39.51 GiB Free PE / Size 0 / 0 VG UUID cKtBdq-4n3A-LuLe-QJnQ-j5Be-uOM7-bvVFoM
將新的物理卷新增到已經存在的邏輯卷組中;
VolGroup
是邏輯卷組的名稱,dev/sdb
是linux系統中的磁碟檔案(新新增的硬碟檔案)[[email protected] ~]# vgextend VolGroup /dev/sdb Volume group "VolGroup" successfully extended
檢視邏輯卷的名稱,每個邏輯卷可以看成是在邏輯卷組上一個分割槽;要先給邏輯卷擴容,首先要將磁碟劃分成物理卷,然後新增到邏輯卷組中才行;
[[email protected] ~]# lvdisplay --- Logical volume --- LV Path /dev/VolGroup/lv_root LV Name lv_root VG Name VolGroup LV UUID fqtkt5-jl0k-aBQt-c0o9-lpQN-w5y3-XGLXhO LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-11-07 17:10:34 +0800 LV Status available # open 1 LV Size 35.57 GiB Current LE 9106 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/VolGroup/lv_swap LV Name lv_swap VG Name VolGroup LV UUID 0IWtgU-JShd-3uua-Vz1d-Cllg-CjFR-lRk4B2 LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-11-07 17:10:41 +0800 LV Status available # open 1 LV Size 3.94 GiB Current LE 1008 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
給邏輯卷擴容,28G是根據新增硬碟的大小設定的;
/dev/VolGroup/lv_root
是邏輯卷的名稱;[[email protected] ~]# lvextend -L +28G /dev/VolGroup/lv_root Size of logical volume VolGroup/lv_root changed from 35.57 GiB (9106 extents) to 63.57 GiB (16274 extents). Logical volume lv_root successfully resized
重新載入磁碟資訊,
resize2fs
的引數表示邏輯卷的名稱,[[email protected] ~]# resize2fs /dev/VolGroup/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required old desc_blocks = 3, new_desc_blocks = 4 Performing an on-line resize of /dev/VolGroup/lv_root to 16664576 (4k) blocks. The filesystem on /dev/VolGroup/lv_root is now 16664576 blocks long. [[email protected] ~]#
使用
df -h
命令檢視下,大功告成