Resize a kvm disk image

1. From the vm, stop the vm:

poweroff

2. From the host, resize the disk image:

qemu-img resize /virt/disk02.img +50G

3. From the host edit partition table

parted /virt/disk02.img
GNU Parted 2.3
Using /virt/disk02.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free                                                       
Model:  (file)
Disk /virt/disk02.img: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        16.4kB  1049kB  1032kB           Free Space
 1      1049kB  51.5GB  51.5GB  primary  ext4         boot
        51.5GB  107GB   55.9GB           Free Space

(parted) rm 1                                                             
(parted) mkpart primary 1049kB -2G
(parted) print free                                                       
Model:  (file)
Disk /virt/disk02.img: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        16.4kB  1049kB  1032kB           Free Space
 1      1049kB  105GB   105GB   primary  ext4
        105GB   107GB   2000MB           Free Space

Yes: rm 1, since this only deletes partion information, not data. Then you recreate partition info on top of data.

4. From the guest, restart, then:

resize2fs /dev/sda1

Leave a Reply

*