Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a CentOS 6.4 image install by KVM on Ubuntu 12.04 amd64 host. Here is the disk layout of 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 -

I want to add more space to /root, so I tried to use virt-resize. I create a 20G img then reize the /root by:

# truncate -s 20G centos-new.img 
# virt-resize centos.img centos-new.img --expand /dev/sda2 --LV-expand /dev/vg_centos/lv_root 

The output seems ok

**********
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 ...

I checked the layout of new vm and it's ok:

# 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 operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly.

Then I define a new vm on KVM using virsh. I copy the config file of current centos.img in /var/libvirt/qemu and edit this then define the vm. Everything is OK but I can not start the centos-new. Here is the log

# 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

Here is the last part of /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

and from /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

Two vms are located in same folder with same permission + owner. The centos.img boot as normal.

 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

I read a lot of guide like this: http://n40lab.wordpress.com/2013/05/29/resizing-a-qemu-kvm-linux-image-using-virt-resize-in-centos-6-4/ and the instructions are the same. Any suggests? Thank you all.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.