方法一(適應於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
多謝逗逗,謎指導 。