有台配置好的虚拟机,一直是用来做日志统计,这天连接上去,才发现这台机器当时是自己在本机上玩的,没想到会用在真实工作环境下,现在空间快不够了,需要给这台虚拟机扩下容量了,可是在线扩容我还真没高过,没办法,在弄台虚拟机来玩玩。。。
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/VolGroup00-LogVol006983168 2253172 4369548 35% //dev/sda1 101086 12056 83811 13% /boottmpfs 257668 0 257668 0% /dev/shm[root@localhost ~]# fdisk -lDisk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 1044 8281507+ 8e Linux LVMDisk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk /dev/sdb doesn't contain a valid partition table
上面是本机现在的清况,下面开始创建物理卷
1、 创建分区
使用分区工具(如:fdisk等)创建LVM分区,方法和创建其他一般分区的方式是一样的,区别仅仅是LVM的分区类型为8e。
使用fdisk创建分区,根据设备文件的绝对路径(/dev/hda)进入分区管理
一定要指定分区的格式为8e,这是LVM的分区格式
2、 创建PV
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created[root@localhost ~]# pvdisplay ##可以用“pvdisplay”命令查看物理卷情况--- Physical volume ---PV Name /dev/sda2VG Name VolGroup00PV Size 7.90 GB / not usable 23.41 MBAllocatable yes (but full)PE Size (KByte) 32768Total PE 252Free PE 0Allocated PE 252PV 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/sdbVG NamePV Size 1.00 GBAllocatable NOPE Size (KByte) 0Total PE 0Free PE 0Allocated PE 0PV 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 systemAttempt to close device '/dev/cdrom' which is not open.Volume group "VolGroup00" successfully extended[root@localhost ~]# vgdisplay ##查看卷组的空间
--- Volume group ---VG Name VolGroup00System IDFormat lvm2Metadata Areas 2Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 2Act PV 2VG Size 8.84 GBPE Size 32.00 MBTotal PE 283Alloc 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/LogVol00VG Name VolGroup00LV UUID DDmERv-LIlu-cwXR-oM9t-33wj-l2ko-zw715WLV Write Access read/writeLV Status available# open 1LV Size 6.88 GBCurrent LE 220Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:0--- Logical volume ---LV Name /dev/VolGroup00/LogVol01VG Name VolGroup00LV UUID e0uO3o-HHrl-LFD1-iy3j-GSQc-U5mM-Q0GU4FLV Write Access read/writeLV Status available# open 1LV Size 1.00 GBCurrent LE 32Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:1下面就开始扩容的操作了。。。
[root@localhost ~]# lvextend -L +1G /dev/VolGroup00/LogVol00Extending 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/LogVol00Rounding up size to full physical extent 928.00 MBExtending logical volume LogVol00 to 7.78 GBLogical 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 sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 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 requiredPerforming 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 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/VolGroup00-LogVol007933376 2253184 5270604 30% / #本来是35%/dev/sda1 101086 12056 83811 13% /boottmpfs 257668 0 257668 0% /dev/shm
至此在虚拟机上,最简单的一个LVM扩容操作完毕,为日后查看写本文做备忘。。。
=====================================================================
更改现有lvm大小
lvreduce -L 10G -f -r /dev/mapper/vg001-homevol
lvextend -L +200G -f -r /dev/mapper/vg001-rootvol