[root@dywH ~]# yum install libguestfs-tools-c
[root@dywH ~]# yum install libguestfs-winsupport
[root@dywH ~]# virt-filesystems --long --parts --blkdevs -h -a /var/lib/libvirt/images/kvmusb.qcow2 Name Type MBR Size Parent /dev/sda1 partition 83 96M /dev/sda /dev/sda2 partition 8e 1.2G /dev/sda /dev/sda3 partition 8e 130M /dev/sda /dev/sda device - 1.7G -
[root@dywH ~]# qemu-img create -f qcow2 out.qcow2 4G Formatting 'out.qcow2', fmt=qcow2 size=4294967296 encryption=off cluster_size=65536
[root@dywH ~]# virt-resize --expand /dev/sda2 /var/lib/libvirt/images/kvmusb.qcow2 out.qcow2
Examining /var/lib/libvirt/images/kvmusb.qcow2 ...
**********
Summary of changes:
/dev/sda1: This partition will be left alone.
/dev/sda2: This partition will be resized from 1.2G to 3.8G. The LVM
PV on /dev/sda2 will be expanded using the 'pvresize' method.
/dev/sda3: This partition will be left alone.
**********
Setting up initial partition table on out.qcow2 ...
Copying /dev/sda1 ...
100% [-----------------------------------------------------------------] 00:00
Copying /dev/sda2 ...
100% [-----------------------------------------------------------------] 00:00
Copying /dev/sda3 ...
100% [-----------------------------------------------------------------] 00:00
Expanding /dev/sda2 using the 'pvresize' method ...
Resize operation completed with no errors. Before deleting the old
disk, carefully check that the resized disk boots and works correctly.
[root@dywH ~]# guestfish --rw -a out.qcow2
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
><fs> run
><fs> list-filesystems
/dev/sda1: ext4
/dev/vg_kvmhome/vo: ext4
/dev/vg_kvmusb/root: ext4
/dev/vg_kvmusb/swap: swap
><fs> lvresize
lvresize lvresize-free
><fs> help lvresize-free
NAME
lvresize-free - expand an LV to fill free space
SYNOPSIS
lvresize-free lv percent
DESCRIPTION
This expands an existing logical volume "lv" so that it fills "pc"% of
the remaining free space in the volume group. Commonly you would call
this with pc = 100 which expands the logical volume as much as possible,
using all remaining free space in the volume group.
><fs> lvresize-free /dev/vg_kvmusb/root 100
><fs> resize2fs /dev/vg_kvmusb/root
><fs> e2fsck-f /dev/vg_kvmusb/root
><fs> exit
/dev/vg_kvmusb/root/ 已經放大至 3.7G。
[root@dywH ~]# virt-df -h out.qcow2 Filesystem Size Used Available Use% out.qcow2:/dev/sda1 93M 25M 63M 28% out.qcow2:/dev/vg_kvmhome/vo 97M 5.6M 86M 6% out.qcow2:/dev/vg_kvmusb/root 3.7G 849M 2.7G 23%
[root@dywH ~]# mv /var/lib/libvirt/images/kvmusb.qcow2 /tmp
[root@dywH ~]# mv out.qcow2 /var/lib/libvirt/images/kvmusb.qcow2
[root@dywH ~]# virsh start kvmusb
vg_kvmusb-root 已經變成 3.7G。
[root@dywH ~]# ssh kvm8.deyu.wang
root@kvm8.deyu.wang's password:
Last login: Thu Dec 4 19:26:47 2014 from deyu.wang
[root@kvm8 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_kvmusb-root
3.7G 849M 2.7G 24% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/vda1 93M 26M 63M 29% /boot
/dev/mapper/vg_kvmhome-vo
97M 5.6M 87M 7% /home