Redimensionner l'espace disque d'une machine virtuelle à chaud
Description
Parmis de nombreux avantages d'utiliser des machines virtuelles plutôt que des machines physiques, l'un d'eux est l'augmentation de l'espace disque sans avoir besoin d'aller dans le datacenter pour ajouter un disque.
Dans ce wiki, nous allons voir comment redimissionner
Prérequis
Debian 9 minimum
Dans ce tutoriel la machine utilise LVM.
L'augmentation du disque est effectué dans Proxmox. Cela fonctionne aussi avec VMWare et Xen, mais n'a pas été testé sans LVM.
Et action
LVM a plusieurs bonnes caractéristiques intégrées, mais dans notre cas, la principale caractéristique qui suscitera notre intérêt est le redimensionnement à chaud.
Pour afficher l'espace disque j'utilise la commande lsblk
qui affiche correctement l'espace disque utilisezr par disque et par partition.
root@app-1 ~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.8G 0 part
└─template--vg-root 254:0 0 29.8G 0 lvm /
sr0 11:0 1 4M 0 rom
sr1 11:1 1 1024M 0 rom
Et après une petite augmentation de 10Go :
root@app-1 ~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.8G 0 part
└─template--vg-root 254:0 0 29.8G 0 lvm /
sr0 11:0 1 4M 0 rom
sr1 11:1 1 1024M 0 rom
So we will see during this doc how to get the same structure with LVM system. Prepare the disk
We use parted to grow the part of the disk who contain our extended partition.
parted /dev/sda
We list the partitions in parted by typing print.
We grow the extended partition (part 2 in our case).
resizepart 2 100%
When is done we must grow the logical volume part (part 5 in our case).
resizepart 5 100%
We print our partition list
print2
We must grow the VolumeGroup now
pvresize /dev/sda5
And finally we finish by growing the desired logical volume.
lvresize --extents +100%FREE /dev/systemdeb/var
Resizing the filesystem
At this time we have resize our disk and set up LVM for using the new space.
Now we must resize our filesystem if we want use this space.
Resizing with EXT2/EXT3/EXT4
resize2fs /dev/systemdeb/var
Resizing with XFS ( used in this case )
xfs_growfs /dev/systemdeb/var
And finaly the new structure with 5Gio in more.
root@host$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 487M 0 part /boot └─sda5 8:5 0 39.5G 0 part ├─systemdeb-swap 254:0 0 952M 0 lvm [SWAP] ├─systemdeb-root 254:1 0 9.3G 0 lvm / ├─systemdeb-tmp 254:2 0 4.2G 0 lvm /tmp └─systemdeb-var 254:3 0 25.1G 0 lvm /var