====== Agrandir un disque ======
{{tag>virtualisation libvirt "agrandir disque"}}
===== Prérequis =====
Le paquet libguestfs-tools doit être installé
# aptitude install libguestfs-tools
===== Agrandisement disque =====
Nous nous plaçons où se trouvent nos disques de VMs
# cd /var/lib/libvirt/images
Nous agrandissons le disque au format qcow2
# qemu-img resize test.qcow2 +10G
Comme nous ne pouvons agrandir directement la partition en place, nous le copions
# cp test.qcow2 test-orig.qcow2
Nous agrandissons la partition /dev/sda2
# virt-resize --expand /dev/sda2 test-orig.qcow2 test.qcow2
Vous devriez avoir ce genre de retour
[ 0.0] Examining test-orig.qcow2
◓ 25% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒═══════════════════════════════════════════════════════════════════════════════════════════════════════════════⟧ --:--
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
**********
Summary of changes:
/dev/sda1: This partition will be left alone.
/dev/sda2: This partition will be resized from 16,5G to 27,0G. The LVM PV
on /dev/sda2 will be expanded using the ‘pvresize’ method.
**********
[ 12,9] Setting up initial partition table on test.qcow2
[ 14,2] Copying /dev/sda1
[ 15,7] Copying /dev/sda2
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 78,1] Expanding /dev/sda2 using the ‘pvresize’ method
Resize operation completed with no errors. Before deleting the old disk,
carefully check that the resized disk boots and works correctly.
Nous vérifions
# qemu-img info confmgt02.qcow2
Nous avons ce type de retour
image: confmgt02.qcow2
file format: qcow2
virtual size: 28G (30064771072 bytes)
disk size: 1.9G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
refcount bits: 16
corrupt: false
===== Extension LVM =====
Nous démarrons la VM. Il ne reste plus qu'à agrandir le volume groupe LVM
# lvextend -L +10G /dev/mapper/vg_sys-lv_log
ou pour prendre 100% de l'espace libre
# lvextend -l +100%FREE /dev/mapper/vg_sys-lv_log
Pour retailler une partition ext4
# resize2fs /dev/mapper/vg_sys-lv_log
Pour retailler une partition xfs
# xfs_growfs /dev/mapper/vg_sys-lv_log
===== Liens =====
* [[https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/|How to Resize a qcow2 Image and Filesystem with Virt-Resize]]
* [[https://www.2daygeek.com/extend-increase-resize-lvm-logical-volume-in-linux/|How to Extend/Increase LVM’s (Logical Volume Resize) in Linux]]