将新添加硬盘划到根目录的方法: 

但是前提是更目录是支持lvm的---以下的方法的前提是/目录是支持lvm

LVM 甚至可以在服务器不断电的情况下动态对磁盘进行扩容,再虚拟一块硬盘后来加入到LVM中


1.添加虚拟硬盘
先关掉虚拟机的电源,然后选择虚拟机,点右键,setting里面点击Add后选择硬盘设备,设置硬盘为1G

2.开启电源,RHEL5启动完成后

格式化硬盘,划出硬盘分区并将格式改为 LVM格式


fdisk -l 查看硬盘分区情况


Disk /dev/hda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 522 4088542+ 8e Linux LVM

Disk /dev/hdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 1985 1000408+ 8e Linux LVM


fdisk /dev/hdb

n

p

2

Command (m for help): n 新建分区
Command action
e extended
p primary partition (1-4) 分区类型为主分区(如果硬盘分区超过4个了,则选择扩展分区,再新建逻辑分区)
p
Partition number (1-4): 2 第几个分区
First cylinder (1986-8322, default 1986): 起始磁柱
Using default value 1986 这时选默认
Last cylinder or +size or +sizeM or +sizeK (1986-8322, default 8322): +1024M 这里我们将这个分区设成一G


Command (m for help): p 查看分区情况

Disk /dev/hdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 1985 1000408+ 8e Linux LVM
/dev/hdb2 1986 3970 1000440 83 Linux


Command (m for help): t 更改分区的类型
Partition number (1-4): 2 选择第二个
Hex code (type L to list codes): 8e 这里磁盘格式为 LINUX LVM ,可以使用L来进行查看



Command (m for help): p 再次查看

Disk /dev/hdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 1985 1000408+ 8e Linux LVM
/dev/hdb2 1986 3970 1000440 8e Linux LVM 可以看到 hdb2已经变成LVM格式了


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. 这里提示我们重启系统后分区表才会改变,其实用下面一个命令即可



partprobe

[root@el5test ~]# fdisk -l

Disk /dev/hda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 522 4088542+ 8e Linux LVM

Disk /dev/hdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 1985 1000408+ 8e Linux LVM
/dev/hdb2 1986 3970 1000440 8e Linux LVM 可以看到hdb2格式化完成了


3.加入到LVM中

[root@el5test ~]# pvdisplay 先看下系统中PV
--- Physical volume ---
PV Name /dev/hda2
VG Name VolGroup00
PV Size 3.90 GB / not usable 24.72 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 124
Free PE 0
Allocated PE 124
PV UUID 0fxOi9-ZeOY-OlQf-QmIO-Gpb4-kaci-24ovGP

--- Physical volume ---
PV Name /dev/hdb1
VG Name VolGroup00
PV Size 976.96 MB / not usable 16.96 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 30
Free PE 5
Allocated PE 25
PV UUID dtNfYJ-31fK-5CxL-9Pxa-pYWb-GcQ5-Vt5011

[root@el5test ~]# pvcreate /dev/hdb2 建立物理卷(PV)
Physical volume "/dev/hdb2" successfully created

[root@el5test ~]# vgextend VolGroup00 /dev/hdb2 把新物理卷加入到卷组中去
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "VolGroup00" successfully extended 加入成功

[root@el5test ~]# lvextend -L+1G /dev/VolGroup00/LogVol00 把新的空间加到逻辑卷中去
Extending logical volume LogVol00 to 5.03 GB
Logical volume LogVol00 successfully resized


[root@el5test ~]# resize2fs -p /dev/VolGroup00/LogVol00 加上去之后,目前用df -h还看不到新的空间,需要激活
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 1318912 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 1318912 blocks long.


[root@el5test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
4.9G 3.0G 1.7G 65% / 可以看到这个卷动态放大了
/dev/hda1 99M 14M 81M 15% /boot
tmpfs 132M 0 132M 0% /dev/shm
none 132M 104K 132M 1% /var/lib/xenstored