Check disk size before start.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 264 GiB, 283467841536 bytes, 553648128 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9011ee4a

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048   1050623   1048576   512M  b W95 FAT32
/dev/sda2       1052670 553648127 552595458 263.5G  5 Extended
/dev/sda5       1052672 553648127 552595456 263.5G 83 Linux

The following command extend the image (the hard disk in the virtual machine) with 1024 gigabytes.

1
qemu-img resize vm-215-disk-1.qcow2 +1024G

Ok, virtual size: 1.26 TiB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
qemu-img info vm-101-disk-0.qcow2
image: vm-101-disk-0.qcow2
file format: qcow2
virtual size: 1.26 TiB (1382979469312 bytes)
disk size: 229 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

After reboot VM, we can see the /dev/sda : 1.26 TiB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 1.26 TiB, 1382979469312 bytes, 2701131776 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9011ee4a

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048   1050623   1048576   512M  b W95 FAT32
/dev/sda2       1052670 553648127 552595458 263.5G  5 Extended
/dev/sda5       1052672 553648127 552595456 263.5G 83 Linux

We need extend partition 2 first and then partition 5

1
2
$ sudo growpart /dev/sda 2
CHANGED: partition=2 start=1052670 old: size=552595458 end=553648128 new: size=2700079073 end=2701131743
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 1.26 TiB, 1382979469312 bytes, 2701131776 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9011ee4a

Device     Boot   Start        End    Sectors   Size Id Type
/dev/sda1  *       2048    1050623    1048576   512M  b W95 FAT32
/dev/sda2       1052670 2701131742 2700079073   1.3T  5 Extended
/dev/sda5       1052672  553648127  552595456 263.5G 83 Linux
1
2
$ sudo growpart /dev/sda 5
CHANGED: partition=5 start=1052672 old: size=552595456 end=553648128 new: size=2700079071 end=2701131743
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 1.26 TiB, 1382979469312 bytes, 2701131776 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9011ee4a

Device     Boot   Start        End    Sectors  Size Id Type
/dev/sda1  *       2048    1050623    1048576  512M  b W95 FAT32
/dev/sda2       1052670 2701131742 2700079073  1.3T  5 Extended
/dev/sda5       1052672 2701131742 2700079071  1.3T 83 Linux

Done