Linux LVM在线扩容

环境:
虚拟化环境,SUSE Linux Enterprise Server 11sp3,直接把虚拟磁盘从100G改成150G。
现有的LVM是100G,/home 的LV需要再加50G。

步骤:
fdisk 先把多加的50G分成一个区,再把该区划成pv,把该pv加到vg里面,再扩LV,最后扩文件系统。


Linux <wbr>LVM在线扩容



 Last login: Sat Mar 28 16:29:42 2015 from 10.31.29.10
xickDB:~ # df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/system-root  9.9G  5.2G  4.2G  56% /
udev                     1.9G  100K  1.9G   1% /dev
tmpfs                    9.0G   72K  9.0G   1% /dev/shm
/dev/sda1                152M   81M   63M  57% /boot
/dev/mapper/system-home   25G   13G   11G  55% /home

xickDB:~ # fdisk -l 

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 sectors

... ...

Disk /dev/mapper/system-swap doesn't contain a valid partition table

xickDB:~ # vgdisplay 
  --- Volume group ---
  VG Name               system
  System ID             
  Format                lvm2
  ... ...
  VG Size               99.84 GiB
  PE Size               4.00 MiB
  Total PE              25560
  Alloc PE / Size       11008 / 43.00 GiB
  Free  PE / Size       14552 / 56.84 GiB
  VG UUID               jarXED-0N3v-sey6-P4Rl-tLhp-gJtL-HJ11DB
   
xickDB:~ # fdisk /dev/sda

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 3): 
Using default value 3
First sector (209715200-314572799, default 209715200): 
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-314572799, default 314572799): 
Using default value 314572799

Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009d2de

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      321535      159744   83  Linux
/dev/sda2          321536   209715199   104696832   8e  Linux LVM
/dev/sda3       209715200   314572799    52428800   83  Linux

Command (m for help): w
The partition table has been altered!

xickDB:~ # reboot 
Broadcast message from root (pts/1) (Sat Mar 28 16:37:26 2015):

The system is going down for reboot NOW!

Last login: Sat Mar 28 16:29:59 2015 from 10.31.29.10
xickDB:~ # 

xickDB:~ # fdisk -l 

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009d2de

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      321535      159744   83  Linux
/dev/sda2          321536   209715199   104696832   8e  Linux LVM
/dev/sda3       209715200   314572799    52428800   83  Linux
... ...

xickDB:~ # pvs
  PV         VG     Fmt  Attr PSize  PFree 
  /dev/sda2  system lvm2 a--  99.84g 56.84g

xickDB:~ # pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

xickDB:~ # pvs
  PV         VG     Fmt  Attr PSize  PFree 
  /dev/sda2  system lvm2 a--  99.84g 56.84g
  /dev/sda3         lvm2 a--  50.00g 50.00g

xickDB:~ # vgextend system /dev/sda3
  Volume group "system" successfully extended

xickDB:~ # vgdisplay 
  --- Volume group ---
  VG Name               system
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               149.84 GiB
  PE Size               4.00 MiB
  Total PE              38359
  Alloc PE / Size       11008 / 43.00 GiB
  Free  PE / Size       27351 / 106.84 GiB
  VG UUID               jarXED-0N3v-sey6-P4Rl-tLhp-gJtL-HJ11DB
   
xickDB:~ # lvs
  LV   VG     Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  home system -wi-ao--- 25.00g                                           
  root system -wi-ao--- 10.00g                                           
  swap system -wi-ao---  8.00g                                           

xickDB:~ # lvextend --help 
  lvextend: Add space to a logical volume

lvextend
        [-A|--autobackup y|n]
        [--alloc AllocationPolicy]
        [-d|--debug]
        [-f|--force]
        [-h|--help]
        [-i|--stripes Stripes [-I|--stripesize StripeSize]]
        {-l|--extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] |
         -L|--size [+]LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
        [-m|--mirrors Mirrors]
        [--nosync]
        [--use-policies]
        [-n|--nofsck]
        [--noudevsync]
        [-r|--resizefs]
        [-t|--test]
        [--type VolumeType]
        [-v|--verbose]
        [--version]
        LogicalVolume[Path] [ PhysicalVolumePath... ]

xickDB:~ # lvextend --size +50G /dev/mapper/system-home 
  Extending logical volume home to 75.00 GiB
  Logical volume home successfully resized

xickDB:~ # lvs
  LV   VG     Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  home system -wi-ao--- 75.00g                                           
  root system -wi-ao--- 10.00g                                           
  swap system -wi-ao---  8.00g                                           

   
xickDB:~ # resize2fs /dev/mapper/system-home 
resize2fs 1.41.9 (22-Aug-2009)
Filesystem at /dev/mapper/system-home is mounted on /home; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/system-home to 19660800 (4k) blocks.
The filesystem on /dev/mapper/system-home is now 19660800 blocks long.

xickDB:~ # df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/system-root  9.9G  5.2G  4.2G  56% /
udev                     1.9G  104K  1.9G   1% /dev
tmpfs                    9.0G   72K  9.0G   1% /dev/shm
/dev/sda1                152M   81M   63M  57% /boot
/dev/mapper/system-home   74G   13G   58G  19% /home

posted @ 2015-03-28 17:52  Sunny_zhufeng  阅读(581)  评论(0编辑  收藏  举报