我在Ubuntu 12.04 amd64主机上安装了由KVM安装的CentOS 6.4映像。 这是centos.img的磁盘布局
# virt-filesystems --long -h --all -a centos.img Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ext4 - - 500M - **/dev/vg_centos/lv_root filesystem ext4 - - 2.5G -** /dev/vg_centos/lv_swap filesystem swap - - 2.0G - /dev/vg_centos/lv_root lv - - - 2.5G /dev/vg_centos /dev/vg_centos/lv_swap lv - - - 2.0G /dev/vg_centos /dev/vg_centos vg - - - 4.5G - /dev/sda2 pv - - - 4.5G - /dev/sda1 partition - - 83 500M /dev/sda /dev/sda2 partition - - 8e 4.5G /dev/sda /dev/sda device - - - 5.0G -
我想为/ root添加更多的空间,所以我尝试使用virt-resize。 我创build一个20G img,然后通过以下方式重新设置/ root:
# truncate -s 20G centos-new.img # virt-resize centos.img centos-new.img --expand /dev/sda2 --LV-expand /dev/vg_centos/lv_root
输出似乎没问题
********** Setting up initial partition table on centos-new.img ... Copying /dev/sda1 ... 100% ⟦▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓⟧ 00:00 Copying /dev/sda2 ... 100% ⟦▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓⟧ 00:00 Expanding /dev/sda2 using the 'pvresize' method ... Expanding /dev/vg_centos/lv_root using the 'resize2fs' method ...
我检查了新vm的布局,这没关系:
# virt-filesystems --long -h --all -a centos-new.img Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ext4 - - 500M - **/dev/vg_centos/lv_root filesystem ext4 - - 18G -** /dev/vg_centos/lv_swap filesystem swap - - 2.0G - /dev/vg_centos/lv_root lv - - - 18G /dev/vg_centos /dev/vg_centos/lv_swap lv - - - 2.0G /dev/vg_centos /dev/vg_centos vg - - - 20G - /dev/sda2 pv - - - 20G - /dev/sda1 partition - - 83 500M /dev/sda /dev/sda2 partition - - 8e 20G /dev/sda /dev/sda device - - - 20G -
resize操作完成没有错误。 在删除旧磁盘之前,请仔细检查resize的磁盘是否启动并正常工作。
然后我使用virsh在KVM上定义一个新的vm。 我将当前centos.img的configuration文件复制到/ var / libvirt / qemu中,然后编辑它,然后定义vm。 一切都好,但我不能开始新的。 这是日志
# virsh start centos-new error: Failed to start domain centos-new error: internal error process exited while connecting to monitor: char device redirected to /dev/pts/13 kvm: -drive file=/home/tungns/VirtualBox VMs/centos-new.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /home/tungns/VirtualBox VMs/centos-new.img: Invalid argument
这是/var/log/libvirt/libvirtd.log的最后一部分:
2013-06-07 10:59:33.391+0000: 5553: error : qemuMonitorOpenUnix:295 : failed to connect to monitor socket: No such process 2013-06-07 10:59:33.392+0000: 5553: error : qemuProcessWaitForMonitor:1301 : internal error process exited while connecting to monitor: char device redirected to /dev/pts/13 kvm: -drive file=/home/tungns/VirtualBox VMs/centos-new.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /home/tungns/VirtualBox VMs/centos-new.img: Invalid argument
和/var/log/libvirt/qemu/centos-new.log :
2013-06-07 10:59:32.712+0000: starting up LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin QEMU_AUDIO_DRV=none /usr/bin/kvm -S -M pc-1.0 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name centos-new -uuid 1acf632e-cea2-4754-8f36-30799fecc3d0 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/centos-new.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -drive file=/home/tungns/VirtualBox VMs/centos-new.img,if=none,id=drive-ide0-0-0,format=qcow2 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=18,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=00:16:3e:76:04:23,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -vnc 0.0.0.0:0 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 char device redirected to /dev/pts/13 kvm: -drive file=/home/tungns/VirtualBox VMs/centos-new.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /home/tungns/VirtualBox VMs/centos-new.img: Invalid argument 2013-06-07 10:59:33.392+0000: shutting down
两个vms位于具有相同权限+所有者的同一文件夹中。 centos.img启动正常。
784460 -rw-r--r-- 1 root root 803405824 Jun 7 16:20 centos.img 5468088 -rw-r--r-- 1 root root 21474836480 Jun 7 17:17 centos-new.img
我读了很多这样的指导: http : //n40lab.wordpress.com/2013/05/29/resizing-a-qemu-kvm-linux-image-using-virt-resize-in-centos-6-4 /和说明是一样的。 有什么build议? 谢谢你们。