Skip to main content

Ampliación de disco (basado en qcow2) en sistema virtualizado KVM (proxmox)

Contexto

Proceso para ampliar un disco virtual qcow2 en Proxmox cuando el sistema operativo invitado usa LVM y la tabla de particiones GPT no reconoce el nuevo tamaño tras la ampliación.

Escenario inicial

  • Disco qcow2 ampliado desde ~36GB a 46GB en Proxmox
  • Sistema operativo no reconoce el espacio adicional
  • Estructura: sda1 (BIOS boot), sda2 (boot), sda3 (LVM PV)

Síntomas

fdisk /dev/sda

Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (75497471 != 96468991) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.

Command (m for help): p

Disk /dev/sda: 46 GiB, 49392123904 bytes, 96468992 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: gpt
Disk identifier: EBD99DE4-BA1E-4F14-9EFF-FE7FE140CF1A

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3674111  3670016  1.8G Linux filesystem
/dev/sda3  3674112 75497438 71823327 34.2G Linux filesystem

Command (m for help): q

Observamos el mensaje de problemas y el de la capacidad de discos, que no es renocido pese a que su tamaño si lo es, 46Gib vs 36Gib

Prerequisitos

  • Backup: Crear snapshot en Proxmox antes de proceder
  • Acceso: Conexión SSH o consola al sistema invitado
  • Herramientas: gdisk, parted, lvm2 (generalmente preinstalados)

Proceso paso a paso

1. Verificar estado inicial

❯ pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [<34.25 GiB / 0    free]
  Total: 1 [<34.25 GiB] / in use: 1 [<34.25 GiB] / in no VG: 0 [0   ]

2. Corregir estructura GPT

 gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): v

Problem: The secondary header's self-pointer indicates that it doesn't reside
at the end of the disk. If you've added a disk to a RAID array, use the 'e'
option on the experts' menu to adjust the secondary header's and partition
table's locations.

Warning: There is a gap between the secondary partition table (ending at sector
75497470) and the secondary metadata (sector 75497471).
This is helpful in some exotic configurations, but is generally ill-advised.
Using 'k' on the experts' menu can adjust this gap.

Caution: Partition 3 doesn't end on a 2048-sector boundary. This may
result in problems with some disk encryption tools.

Identified 1 problems!

Command (? for help): x

Expert command (? for help): e
Relocating backup data structures to the end of the disk

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

3. Redimensionar partición

# Expandir la partición al 100% del disco disponible
parted /dev/sda resizepart 3 100%

4. Expandir Physical Volume

# Redimensionar el PV para usar todo el espacio de la partición
❯ pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
# Verificar el resultado
> pvdisplay /dev/sda3
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <44.25 GiB / not usable 16.50 KiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              11327
  Free PE               0
  Allocated PE          11327
  PV UUID               NzNz30-KIRH-bWmQ-aSFy-N0mU-x1lt-hQ62uH  

5. Expandir Logical Volume y filesystem

# Conocer el VL de aplicación (Pueden ser varios, y cada uno una cnatidad)
❯ lvscan
  ACTIVE            '/dev/ubuntu-vg/ubuntu-lv' [<34.25 GiB] inherit
# Expandir el LV usando todo el espacio libre disponible  (ejemplo)
❯ lvresize --extents +100%FREE --resizefs /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <34.25 GiB (8767 extents) to <44.25 GiB (11327 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 6
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 11598848 (4k) blocks long.

# El flag --resizefs ejecuta automáticamente resize2fs

6. Verificación final

# Verificar espacio disponible
df -h /
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   44G   32G   10G  77% /

# Vista general de la estructura
lsblk
...
sda                         8:0    0   46G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 44.2G  0 part
  └─ubuntu--vg-ubuntu--lv 252:0    0 44.2G  0 lvm  /
sr0                        11:0    1 1024M  0 rom
...

# Verificar estado LVM
vgdisplay
lvdisplay

Mensajes esperados

Durante gdisk verify (v)

Problem: The secondary header's self-pointer indicates that it doesn't reside at the end of the disk
Warning: There is a gap between the secondary partition table and secondary metadata
Caution: Partition 3 doesn't end on a 2048-sector boundary

Nota: Estos son problemas esperados tras ampliar el disco y se corrigen con el comando e en expert mode.

Durante lvresize

Physical volume "/dev/sda3" changed
Size of logical volume changed from <34.25 GiB to <44.25 GiB
resize2fs: on-line resizing required
The filesystem is now XXXXXX (4k) blocks long.

Consideraciones importantes

Seguridad

  • Sin downtime: Todo el proceso se ejecuta en caliente
  • Solo crecimiento: No se mueven ni reducen datos existentes
  • LVM como protección: Añade capa adicional de seguridad

Orden crítico

  1. Corregir GPT antes que redimensionar particiones
  2. Redimensionar partición antes que PV
  3. Expandir PV antes que LV

Troubleshooting común

  • "Disk in use" warning: Normal, se puede ignorar en operaciones de crecimiento
  • GPT mismatch: Esperado tras resize de qcow2, se corrige con gdisk
  • Alignment warnings: Generalmente no críticos en discos virtuales

Comandos de verificación post-proceso

# Verificar que no quedan problemas GPT
gdisk /dev/sda
v
q

# Estado final del disco
fdisk -l /dev/sda

# Estado LVM completo
pvs && vgs && lvs

# Espacio en filesystem
df -h /

Resultado esperado

  • Disco reconocido con nuevo tamaño completo
  • Sin mensajes de error en GPT
  • Espacio adicional disponible en el filesystem raíz
  • Sistema operativo funcionando normalmente

  • Proceso validado en Ubuntu 22.04 sobre Proxmox VE con discos qcow2
  • Generado el 26/09/2025 por Abdelkarim Mateos Sánchez - Administrador de Sistemas
Aviso

Esta documentación y su contenido, no implica que funcione en tu caso o determinados casos. También implica que tienes conocimientos sobre lo que trata, y que en cualquier caso tienes copias de seguridad. El contenido el contenido se entrega, tal y como está, sin que ello implique ningún obligación ni responsabilidad por parte de Castris

Si necesitas soporte profesional puedes contratar con Castris soporte profesional.