===== 为Xen虚拟机扩容根文件系统(LVM) =====

1. 增加1个4G的映像文件

# dd if=/dev/zero of=data.img bs=4k seek=1024k count=1

2. 更改虚拟机配置:

disk = [ "tap:aio:/xen_images/xen_centos6.5x64/centos6.5x64.img,xvda,w",

"tap:aio:/xen_images/xen_centos6.5x64/data.img,xvdb,w" ]

3. 查看LINUX的PV,VG和LV信息:

[root@server1 ~]# pvdisplay

--- Physical volume ---

PV Name               /dev/xvda2

VG Name               VolGroup00

PV Size               15.90 GB / not usable 20.79 MB

Allocatable           yes (but full)

PE Size (KByte)       32768

Total PE              508

Free PE               0

Allocated PE          508

PV UUID               AQLigU-Kra3-qXIU-ul0J-flmS-cB5j-RfAaEv

[root@server1 ~]# vgdisplay

--- Volume group ---

VG Name               VolGroup00

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  3

VG Access             read/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               2

Max PV                0

Cur PV                1

Act PV                1

VG Size               15.88 GB

PE Size               32.00 MB

Total PE              508

Alloc PE / Size       508 / 15.88 GB

Free  PE / Size       0 / 0

VG UUID               FbUuvN-yE0U-cRkA-fOL0-aIRP-eHdG-TzDN5P

[root@server1 ~]# lvdisplay

--- Logical volume ---

LV Name                /dev/VolGroup00/LogVol00

VG Name                VolGroup00

LV UUID                bLPTMQ-3TlN-1pIO-vKUv-oU9A-mYnh-dLdqFF

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                13.84 GB

Current LE             443

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                YDw1jP-eF7K-Yrms-H0QD-4f7p-oPMv-PeXqrO

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                2.03 GB

Current LE             65

Segments               1

Allocation             inherit

Read ahead sectors     auto

- currently set to     256

Block device           253:1

4. 将新增的硬盘/dev/xvdb创建为PV

[root@server1 ~]# pvcreate /dev/xvdb

Physical volume "/dev/xvdb" successfully created

[root@server1 ~]# pvdisplay

--- Physical volume ---

PV Name               /dev/xvda2

VG Name               VolGroup00

PV Size               15.90 GB / not usable 20.79 MB

Allocatable           yes (but full)

PE Size (KByte)       32768

Total PE              508

Free PE               0

Allocated PE          508

PV UUID               AQLigU-Kra3-qXIU-ul0J-flmS-cB5j-RfAaEv

"/dev/xvdb" is a new physical volume of "4.00 GB"

--- NEW Physical volume ---

PV Name               /dev/xvdb

VG Name

PV Size               4.00 GB

Allocatable           NO

PE Size (KByte)       0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               4sg3Xe-ryzB-6nL1-pyfb-2g9S-e3C3-32bv9m

5. 将新增的PV物理卷/dev/xvdb增加到VG卷组VolGroup00

# vgextend VolGroup00 /dev/xvdb

[root@server1 ~]# 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               19.84 GB

PE Size               32.00 MB

Total PE              635

Alloc PE / Size       508 / 15.88 GB

Free  PE / Size       127 / 3.97 GB

VG UUID               FbUuvN-yE0U-cRkA-fOL0-aIRP-eHdG-TzDN5P

6. 扩容LV逻辑卷/dev/VolGroup00/LogVol00

[root@server1 ~]# lvextend -l +127 /dev/VolGroup00/LogVol00

Extending logical volume LogVol00 to 17.81 GB

Logical volume LogVol00 successfully resized

[root@server1 ~]# vgdisplay

--- Volume group ---

VG Name               VolGroup00

System ID

Format                lvm2

Metadata Areas        2

Metadata Sequence No  5

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               19.84 GB

PE Size               32.00 MB

Total PE              635

Alloc PE / Size       635 / 19.84 GB

Free  PE / Size       0 / 0

VG UUID               FbUuvN-yE0U-cRkA-fOL0-aIRP-eHdG-TzDN5P

[root@server1 ~]# lvdisplay

--- Logical volume ---

LV Name                /dev/VolGroup00/LogVol00

VG Name                VolGroup00

LV UUID                bLPTMQ-3TlN-1pIO-vKUv-oU9A-mYnh-dLdqFF

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                17.81 GB

Current LE             570

Segments               2

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                YDw1jP-eF7K-Yrms-H0QD-4f7p-oPMv-PeXqrO

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                2.03 GB

Current LE             65

Segments               1

Allocation             inherit

Read ahead sectors     auto

- currently set to     256

Block device           253:1

7. LV扩容后激活变更以扩容文件系统

[root@server1 ~]# df -m

Filesystem           1M-blocks      Used Available Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

13732      3086      9938  24% /

/dev/xvda1                  99        14        80  15% /boot

tmpfs                      256         0       256   0% /dev/shm

[root@server1 ~]# 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 4669440 (4k) blocks.

The filesystem on /dev/VolGroup00/LogVol00 is now 4669440 blocks long.

[root@server1 ~]# df -m

Filesystem           1M-blocks      Used Available Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

17668      3090     13669  19% /

/dev/xvda1                  99        14        80  15% /boot

tmpfs                      256         0       256   0% /dev/shm

8. 至此,为虚拟机扩容根分区成功,扩容容量为127个PE(32M/PE),扩容大小为4G。

05-11 21:42