方法一(适应于ext2/3):
1。调整之前:df -h
2。关闭 DomU:xm shutdown vm01
3。 给虚拟机镜像文件追加 2G 空间:dd if=/dev/zero bs=1024k count=2048 >> /var/lib/xen/p_w_picpaths/vm01.img
4。扫描检查镜像文件:e2fsck -f /var/lib/xen/p_w_picpaths/vm01.img
5。调整虚拟机镜像文件的大小:resize2fs /var/lib/xen/p_w_picpaths/vm01.img
6。重启 Xen:xm create vm01
7。进入虚拟机:xm console vm01

8。查看大小:df -h



方法二(针对于lvm逻辑卷扩大):

[root@XenServer ~]# cat /etc/xen/wowking    #查看xen虚拟机的配置文件
[root@XenServer ~]# dd if=/dev/zero of=/data/xen/p_w_picpaths/wowking1.img bs=1G count=10 #在wowking虚拟机的img路径再增加一个img,大小为10GB
[root@XenServer ~]# chmod a+x /data/xen/p_w_picpaths/wowking1.img #增加wowking1.img所有用户的控制权限
[root@XenServer ~]# ll /data/xen/p_w_picpaths/
[root@XenServer ~]# vim /etc/xen/wowking    #修改wowking虚拟机配置,将新增硬盘加入虚拟机中,“xvbd”第二块硬盘,“w”可写
disk = [ "tap:aio:/data/xen/p_w_picpaths/wowking.img,xvda,w","tap:aio:/data/xen/p_w_picpaths/wowking1.img,xvdb,w" ]
                         
[root@XenServer ~]# xm create wowking
                         
[root@Wowking ~]# fdisk -l
                         
Disk /dev/xvda: 37.3 GB, 37329305600 bytes
255 heads, 63 sectors/track, 4538 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14        3263    26105625   8e  Linux LVM
                         
Disk /dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
Disk /dev/xvdb doesn't contain a valid partition table
                         
                         
[root@Wowking ~]# fdisk /dev/xvdb   #在新硬盘增加分区并格式化
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
                         
                         
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
                         
Disk /dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
    Device Boot      Start         End      Blocks   Id  System
                         
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305
                         
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
                         
Command (m for help): p
                         
Disk /dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        1305    10482381   8e  Linux LVM
                         
Command (m for help): w
The partition table has been altered!
                         
[root@Wowking ~]# fdisk -l
                         
Disk /dev/xvda: 37.3 GB, 37329305600 bytes
255 heads, 63 sectors/track, 4538 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14        3263    26105625   8e  Linux LVM
                         
Disk /dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
                         
    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        1305    10482381   8e  Linux LVM
                         
                         
[root@Wowking ~]# pvcreate /dev/xvdb1   #将新建分区转为pv
  Writing physical volume data to disk "/dev/xvdb1"
  Physical volume "/dev/xvdb1" successfully created
                         
[root@Wowking ~]# vgdisplay #查看vg
  --- Volume group ---
  VG Name               VolGroup00
  System ID           
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               24.88 GB
  PE Size               32.00 MB
  Total PE              796
  Alloc PE / Size       796 / 24.88 GB
  Free  PE / Size       0 / 0 
  VG UUID               x1Psjp-jCsF-KQe9-iT00-XTOK-CbO3-mlonjp
                         
[root@Wowking ~]# vgextend VolGroup00 /dev/xvdb1    #因xen之前存在vg,全次目的将新建的pv加入vg
  Volume group "VolGroup00" successfully extended
[root@Wowking ~]# lvextend -L +9G /dev/mapper/VolGroup00-LogVol02   #扩展lv,大小为9G,“/dev/mapper/VolGroup00-LogVol02”是需要扩大的挂载点所对应的文件系统
  Extending logical volume LogVol02 to 20.16 GB
  Logical volume LogVol02 successfully resized
[root@Wowking ~]# resize2fs /dev/mapper/VolGroup00-LogVol02 #激动修改配置
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol02 is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol02 to 5283840 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol02 is now 5283840 blocks long.
                         
[root@Wowking ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      9.5G  5.6G  3.4G  63% /
/dev/mapper/VolGroup00-LogVol02
                       20G  9.3G  9.3G  50% /data
/dev/xvda1             99M   35M   60M  37% /boot
tmpfs                 1.0G     0  1.0G   0% /dev/shm
[root@Wowking ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID           
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  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               34.84 GB
  PE Size               32.00 MB
  Total PE              1115
  Alloc PE / Size       1084 / 33.88 GB
  Free  PE / Size       31 / 992.00 MB
  VG UUID               x1Psjp-jCsF-KQe9-iT00-XTOK-CbO3-mlonjp




多谢逗逗,谜指导 。