LVM擴容-----給虛擬機器新增空間

531968912發表於2015-02-27
本來有臺上面配置好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擴容操作完畢,為日後檢視寫本文做備忘。

出處:http://world77.blog.51cto.com/414605/382230

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25462274/viewspace-1442494/,如需轉載,請註明出處,否則將追究法律責任。

相關文章