User Tools

Site Tools


linux:kvmqemu:expanddisk

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linux:kvmqemu:expanddisk [2023/02/12 17:05] – created olaflinux:kvmqemu:expanddisk [2023/11/05 13:41] (current) – Added LVM extension olaf
Line 1: Line 1:
 ++===== KVM / QEMU Extend a virtual disk ======
 +
 +===== Extend a virtual disk with simple partition schema =====
 +
 +With the VM shut down directly extend the disk image on the host:
 +<code bash>
 +qemu-img resize virtual_disk.qcow2 +10G
 +</code>
 +
 +Load the network block device driver into the kernel and attach the disk to the host
 +<code bash>
 +modprobe nbd
 +qemu-nbd -c /dev/nbd0 virtual_disk.qcow2
 +</code>
 +
 +Use a partition manager (gParted ...) to extend the partition
 +
 +Disconnect the virtual disk from the host
 +<code bash>
 +qemu-nbd -d /dev/nbd0
 +</code>
 +
 +Start the VM and check if all is ok
 +
 +===== Extend a virtual disk with LVM partitions =====
 +
 +With the VM shut down directly extend the disk image on the host:
 +<code bash>
 +qemu-img resize virtual_disk.qcow2 +10G
 +</code>
 +
 +Start the VM and login. \\
 +As root or sudo:
 +
 +<code bash>
 +lsblk
 +</code>
 +<code>
 +NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
 +sr0                  11:0    1  1024M  0 rom  
 +vda                 252:   0   260G  0 disk 
 +├─vda1              252:1    0   600M  0 part /boot/efi
 +├─vda2              252:2    0     1G  0 part /boot
 +└─vda3              252:3    0 208.4G  0 part 
 +  ├─rhel_rhel8-root 253:0    0   180G  0 lvm  /
 +  ├─rhel_rhel8-swap 253:1    0     4G  0 lvm  [SWAP]
 +  └─rhel_rhel8-home 253:2    0  24.4G  0 lvm  /home
 +</code>
 +This shows the LVM partitions are on device vda, partition 3 (vda3)\\
 +
 +<code bash>
 +pvs
 +</code>
 +
 +<code>
 +  PV         VG         Fmt  Attr PSize   PFree
 +  /dev/vda3  rhel_rhel8 lvm2 a--  258.41g    0 
 +</code>
 +The virtual device is ''/dev/vda3'' and the volume group is ''rhel_rehl8''
 +
 +Claim the free disk space for partition 3
 +<code bash>
 +growpart /dev/vda 3
 +pvresize /dev/vda3
 +</code>
 +... and finally claim the available space for the root partition:
 +<code bash>
 +lvextend -r -l +100%FREE /dev/rhel_rhel8/root
 +</code>
 +
 +Check if all went well:
 +
 +<code bash>
 +lsblk
 +</code>
 +<code>
 +NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
 +sr0                  11:0    1  1024M  0 rom  
 +vda                 252:   0   260G  0 disk 
 +├─vda1              252:1    0   600M  0 part /boot/efi
 +├─vda2              252:2    0     1G  0 part /boot
 +└─vda3              252:3    0 258.4G  0 part 
 +  ├─rhel_rhel8-root 253:0    0   230G  0 lvm  /
 +  ├─rhel_rhel8-swap 253:1    0     4G  0 lvm  [SWAP]
 +  └─rhel_rhel8-home 253:2    0  24.4G  0 lvm  /home
 +</code>
 +
 +vda3 grew from 208.4 GB to 258.4 GB and the space was added to rhel_rhel8-root: it grew from 180 GB to 230 GB.
 +
 +Done.
 +
  
linux/kvmqemu/expanddisk.txt · Last modified: 2023/11/05 13:41 by olaf