1、背景介绍:
OS系统:RHEL Linux 5.4
虚拟机:VMware 10.0
2、虚拟机中操作
首先是先扩展虚拟机的虚拟机硬盘。操作步骤:
1)将虚拟机系统Linux关闭,注意必须是关机状态。
2)依次单击【虚拟机】--【设置】
3)在弹出的窗口中,选择需要扩展的磁盘,这里以扩展“硬盘 2”为例,初始大小是10G(图片是扩展后截图的),需要将其扩大到30G。
4)输入需要将虚拟磁盘扩到后的大小。这里将原来的10G,扩大到30G。然后单击【扩展】,然后在返回的界面之后,单击确定。
3、Linux系统中的操作
查看虚拟硬盘扩容结果
[root@localhost ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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 2624 20972857+ 83 Linux
/dev/sda3 2625 2885 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 8e Linux LVM
卸载文件系统
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 7.5G 11G 41% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 760M 0 760M 0% /dev/shm
/dev/mapper/vg_ora11g-lv_ora11g
9.7G 5.2G 4.0G 57% /ora11g
[root@localhost ~]# umount /ora11g
格式化分区
[root@localhost ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 3916.
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): p
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1306-3916, default 1306): --回车
Using default value 1306
Last cylinder or +size or +sizeM or +sizeK (1306-3916, default 3916): --回车
Using default value 3916
Command (m for help): p
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 8e Linux LVM
/dev/sdb2 1306 3916 20972857+ 83 Linux
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: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 8e Linux LVM
/dev/sdb2 1306 3916 20972857+ 83 Linux
重启Linux系统
[root@localhost ~]# reboot
创建pv
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg_ora11g lvm2 a- 10.00G 200.00M
[root@localhost ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg_ora11g lvm2 a- 10.00G 200.00M
/dev/sdb2 lvm2 -- 20.00G 20.00G
将新的PV添加到VG中
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_ora11g 1 1 0 wz--n- 10.00G 200.00M
[root@localhost ~]# vgextend vg_ora11g /dev/sdb2
Volume group "vg_ora11g" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_ora11g 2 1 0 wz--n- 30.00G 20.20G
将新分区的所有空间添加到LV
[root@localhost ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_ora11g vg_ora11g -wi-ao 9.80G
[root@localhost ~]# lvextend /dev/mapper/vg_ora11g-lv_ora11g /dev/sdb2
Extending logical volume lv_ora11g to 29.80 GB
Logical volume lv_ora11g successfully resized
[root@localhost ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_ora11g vg_ora11g -wi-ao 29.80G
重置lv大小
resize2fs前需要先对lv执行e2fsck。
[root@localhost ~]# resize2fs /dev/mapper/vg_ora11g-lv_ora11g
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/mapper/vg_ora11g-lv_ora11g' first.
[root@localhost ~]# e2fsck -f /dev/mapper/vg_ora11g-lv_ora11g
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_ora11g-lv_ora11g: 39792/1286752 files (0.9% non-contiguous), 1394391/2569216 blocks
[root@localhost ~]# resize2fs /dev/mapper/vg_ora11g-lv_ora11g
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/vg_ora11g-lv_ora11g to 7812096 (4k) blocks.
The filesystem on /dev/mapper/vg_ora11g-lv_ora11g is now 7812096 blocks long.
挂载文件系统
[root@localhost ~]# mount /dev/mapper/vg_ora11g-lv_ora11g /ora11g
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 7.5G 11G 41% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 760M 0 760M 0% /dev/shm
/dev/mapper/vg_ora11g-lv_ora11g
30G 5.2G 23G 19% /ora11g