擴展vmware虛機磁盤空間

虛機的CPU、內存擴展都很容易,磁盤空間也是能夠擴展的只是相對來講操做要略複雜一些。linux

一。用root用戶登陸到你的linux系統,查看你係統的分區
#fdisk -l
會出現如下的信息:
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVMapp

Disk /dev/mapper/vg_zxw-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 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: 0x00000000ide

Disk /dev/mapper/vg_zxw-lv_root doesn't contain a valid partition table字體

Disk /dev/mapper/vg_zxw-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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: 0x00000000ui

Disk /dev/mapper/vg_zxw-lv_swap doesn't contain a valid partition table
根據提示信息能夠判斷出此係統的磁盤接口爲SCSI,對應「sda」若是上面的紅色字體是「hda」,那麼此係統的磁盤接口爲IDE對應「hda」因此我作一下操做:this

#fdisk /dev/sda/
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').code

Command (m for help):m //「 列出fdisk的幫助」
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)orm

Command (m for help):n //」 命令n用於添加新分區"
Command action
e extended
p primary partition (1-4)
p //" 選擇建立主分區"此時,
Partition number (1-4):3 //fdisk會讓你選擇主分區的編號,若是已經有了主分區sda1,sda2,那麼編號就選3,即要建立的該分區爲sda3.
First cylinder (2611-3916, default 2611): //此時,fdisk又會讓你選擇該分區的開始值這個就是分區的Start 值(start cylinder);這裏最好直接按回車,
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916): //此時,fdisk又會讓你選擇該分區的開始值這個就是分區的End 值這裏最好直接按回車,
Using default value 3916接口

Command (m for help): w //w "保存全部並退出,分區劃分完畢"
The partition table has been altered!內存

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.

2、咱們的新建分區/dev/sda3,卻不是LVM的。因此,接下來使用fdisk將其改爲LVM的。
#fdisk /dev/sda
Command (m for help): m
Command (m for help): t //改變分區系統id
Partition number (1-4): 3 //指定分區號
Hex code (type L to list codes): 8e //指定要改爲的id號,8e表明LVM。
Command (m for help): w

3、重啓系統後,登錄系統。(必定要重啓系統,不然沒法擴充新分區)

4、格式化該新添加的分區:
#fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 8e Linux LVM
你會發現多了一塊分區。
#mkfs -t ext3 /dev/sda3 //在硬盤分區「/dev/sda3」上建立「ext3」文件系統。
此時咱們就可使用該新增分區啦:

5、擴充新分區
#lvs
#pvcreate /dev/sda3 //pvcreate指令用於將物理硬盤分區初始化爲物理卷,以便被LVM使用。要建立物理卷必須首先對硬盤進行分區,而且將硬盤分區的類型設置爲「8e」後,才能使用pvcreat指令將分區初始化爲物理卷。
Physical volume "/dev/sda3" successfully created
#vgextend VolGroup00 /dev/sda3 (其中是當前須要擴充的lvm組名,能夠經過df -h查看,例如個人是: /dev/mapper/VolGroup00-LogVol00) //vgextend指令用於動態的擴展卷組,它經過向卷組中添加物理捲來增長卷組的容量。
#vgdisplay //用於顯示LNM卷組的元數據信息。
--- Volume group ---
VG Name vg_zxw
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 4994 / 10.01GB
VG UUID sqBgTs-iA8x-tCXZ-KYxK-SyWS-TfXQ-uBsLaR
(主要查看Free PE / Size 4994 / 10.01GB,說明咱們最多能夠有10.01GB的擴充空間。我通常選擇小於10.01GB)

lvextend -L+9.8G /dev/VolGroup00/LogVol00 /dev/sda3

Logical volume LogVol00 successfully resized#e2fsck -a /dev/VolGroup00/LogVol00 //使用e2fsck指令檢查文件系統錯誤。也可用「fsck -t ext2 -V /dev/sda3/檢查ext2文件系統。 (作fsck,檢查文件系統)#resize2fs /dev/VolGroup00/LogVol00 //resize2fs指令被用來增大或者收縮未加載的「ext2/ext3」文件系統的大小。#df -h //查看一下你的系統磁盤空間"/"目錄變成了40GBok,這樣就大功告成了。

相關文章
相關標籤/搜索