[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
- 根據4回傳的資訊,輸入fdisk /dev/sda
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):
[備註]
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)
- 輸入 p 取得目前的資訊
Command (m for help): p
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
- 輸入 n 創建新的partition,接著按兩下Enter,以使用最小及最大的數值 (使用完整的free空間)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-10443, default 2611):
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-10443, default 10443):
Using default value 10443
- 輸入 t 更改系統ID,選擇第3個partition,直接輸入8e
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
- 輸入 w 將設定寫入硬碟
Command (m for help): 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.
Syncing disks.
-
將 VM Guest 重新開機
-
輸入 fdisk -l 可以看到剛剛新增的sda3
</pre lang=”bash”>[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
/dev/sda3 2611 10443 62918572+ 8e Linux LVM
- 使用 pvcreate 創建 volume
[root@localhost ~]# pvcreate /dev/sda3
dev_is_mpath: failed to get device for 8:3
Writing physical volume data to disk "/dev/sda3"
Physical volume "/dev/sda3" successfully created
- 使用 vgextend 將 sda3 加入 VolGroup00
[root@localhost ~]# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
- 使用 vgdisplay 查詢 VolGroup00 未使用的空間為 60G
[root@localhost ~]# vgdisplay VolGroup00 | grep "Free"
Free PE / Size 1920 / 60.00 GB
- 使用 lvextend 增加空間 (從14可以得知為60G)
[root@localhost ~]# lvextend -L+60G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 77.88 GB
Logical volume LogVol00 successfully resized
- 使用 resize2fs 修改分割區大小
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 20414464 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 20414464 blocks long.
- 輸入 df -h 驗證有沒有成功
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
76G 14G 58G 20% /
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 506M 0 506M 0% /dev/shm
參考資訊: Extending a logical volume in a virtual machine running Red Hat or Cent OS (1006371)