本来有台上面配置好CACTI的监控服务的虚拟机,一直是用来监控现在的服务器,这天连接上去,才发现这台机器当时是自己在本机上玩的,没想到会用在真实工作环境下,现在空间快不够了,需要给这台虚拟机扩下容量了,可是在线扩容我还真没高过,没办法,在弄台虚拟机来玩玩。
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6983168 2253172 4369548 35% /
/dev/sda1 101086 12056 83811 13% /boot
tmpfs 257668 0 257668 0% /dev/shm
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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 1044 8281507+ 8e Linux LVM
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table
上面是本机现在的清况,下面开始创建物理卷
[root@localhost ~]# pvcreate /dev/sdb
Physical volume “/dev/sdb” successfully created
[root@localhost ~]# pvdisplay ##可以用“pvdisplay”命令查看物理卷情况
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 7.90 GB / not usable 23.41 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 252
Free PE 0
Allocated PE 252
PV UUID Up0jiK-5I0E-d5J5-wZSu-WIhX-aKRA-OR9Pjm
“/dev/sdb” is a new physical volume of “1.00 GB” ###新建的物理卷
— NEW Physical volume —
PV Name /dev/sdb
VG Name
PV Size 1.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID zkullQ-PgoI-fHH4-xL3K-VLGm-JgMr-T7R1oA
下面就是将新添的物理卷加入到已有的逻辑卷组中
[root@localhost ~]# vgextend /dev/VolGroup00 /dev/sdb
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Volume group “VolGroup00” successfully extended
[root@localhost ~]# vgdisplay ##查看卷组的空间
— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 8.84 GB
PE Size 32.00 MB
Total PE 283
Alloc PE / Size 252 / 7.88 GB ###原有的
Free PE / Size 31 / 992.00 MB ##新加的扩容进去的空间
VG UUID 0q4Uy2-coR3-bLwU-izpJ-kLOC-PxO3-9Efm8H
###############################################################
[root@localhost ~]# lvdisplay 查看下分区
— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID DDmERv-LIlu-cwXR-oM9t-33wj-l2ko-zw715W
LV Write Access read/write
LV Status available
# open 1
LV Size 6.88 GB
Current LE 220
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID e0uO3o-HHrl-LFD1-iy3j-GSQc-U5mM-Q0GU4F
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1
下面就开始扩容的操作了。
[root@localhost ~]# lvextend -L +1G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 7.88 GB
Insufficient free space: 32 extents needed, but only 31 available
###这里显示失败,空间不够,我的命令是加一个G的空间,但是空间不足。。。
[root@localhost ~]# lvextend -L +900M /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 928.00 MB
Extending logical volume LogVol00 to 7.78 GB
Logical volume LogVol00 successfully resized
##成功了,我改为添加900M,其实在上面vgdisplay 的时候可以看到他添加了多少空间,但是当时我操作的时候,没注意看,呵呵。。。这个时候你在用lvdisplay命令看LV的空间的话,可以看到/dev/VolGroup00/LogVol00的空间已经增大了。。。
下面开始检查LVM设备对应inode和block之间的关系
[root@localhost ~]# e2fsck -f /dev/VolGroup00/LogVol00
e2fsck 1.39 (29-May-2006)
/dev/VolGroup00/LogVol00 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/dev/VolGroup00/LogVol00: recovering journal
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/VolGroup00/LogVol00: ***** FILE SYSTEM WAS MODIFIED *****
/dev/VolGroup00/LogVol00: ***** REBOOT LINUX *****
/dev/VolGroup00/LogVol00: 108951/2064384 files (0.3% non-contiguous), 627952/2048000 blocks
最后是增加的容量生效
[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 2048000 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2048000 blocks long.
最后用df在看下现在的空间情况:
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7933376 2253184 5270604 30% / #本来是35%
/dev/sda1 101086 12056 83811 13% /boot
tmpfs 257668 0 257668 0% /dev/shm
至此在虚拟机上,最简单的一个LVM扩容操作完毕,为日后查看写本文做备忘。