Extender disco virtual

De jagfloriano.com
Ir a la navegaciónIr a la búsqueda

Procedimiento: Extender disco físico y LVM online

Alcance

Este procedimiento aplica **únicamente a máquinas virtuales** ejecutándose sobre VMware con Red Hat Enterprise Linux 7 u 8 y discos gestionados mediante LVM.

El procedimiento se realiza online (sin apagar el sistema), siempre que el disco ya haya sido extendido previamente desde VMware.

Requisitos previos

  • El disco ha sido extendido desde VMware
  • El sistema utiliza LVM
  • Acceso como root
  • Copia de seguridad recomendada

Verificación inicial

Comprobar versión del sistema operativo:

[root@serverA ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)

Ver particiones actuales:

[root@serverA ~]# cat /proc/partitions |grep sda
   8        0  104857600 sda
   8        1    1048576 sda1
   8        2     262144 sda2
   8        3  103545856 sda3

Comprobar el volumen físico:

[root@serverA ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda3  vg00 lvm2 a--  <98.75g <27.92g
[root@serverA ~]#


[root@serverA ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16
/dev/sda3         2623488   209715199   103545856   8e  Linux LVM

Reescaneo del disco

Forzar al kernel a detectar el nuevo tamaño del disco:

[root@serverA ~]# echo 1 > /sys/block/sda/device/rescan

Verificar nuevo tamaño:

[root@serverA ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16
/dev/sda3         2623488   209715199   103545856   8e  Linux LVM

Recrear la partición LVM (sin perder datos)

⚠️ **Importante** Solo eliminar y recrear la partición **siempre usando el mismo sector inicial**.

Entrar en fdisk:

fdisk /dev/sda

Pasos dentro de fdisk:

  • p → Mostrar particiones
  • d → Eliminar partición LVM (ej. sda3)
  • n → Crear nueva partición primaria
  • Usar el **mismo sector inicial**
  • Usar todo el espacio disponible
  • t → Cambiar tipo a 8e (Linux LVM)
  • w → Guardar cambios

Pasos detallados:

[root@serverA ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16
/dev/sda3         2623488   209715199   103545856   8e  Linux LVM

Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3):
First sector (2623488-838860799, default 2623488):
Using default value 2623488
Last sector, +sectors or +size{K,M,G} (2623488-838860799, default 838860799):
Using default value 838860799
Partition 3 of type Linux and of size 398.8 GiB is set

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16
/dev/sda3         2623488   838860799   418118656   83  Linux

Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000659b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     2623487      262144    6  FAT16
/dev/sda3         2623488   838860799   418118656   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Recargar tabla de particiones

Aplicar los cambios sin reiniciar:

[root@serverA ~]# partprobe
[root@serverA ~]# partx -u /dev/sda

Verificar:

[root@serverA ~]# cat /proc/partitions |grep -i sda
   8        0  419430400 sda
   8        1    1048576 sda1
   8        2     262144 sda2
   8        3  418118656 sda3

Redimensionar el volumen físico

Extender el PV para que use todo el espacio disponible:

[root@serverA ~]# pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

Comprobar espacio libre en el VG:

[root@serverA ~]# pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/sda3  vg00 lvm2 a--  <398.75g <327.92g
[root@serverA ~]#

Extender el volumen lógico y el sistema de ficheros

Ver tamaño actual:

df -h /

Extender el volumen lógico y el filesystem en un solo paso:

lvextend -L +300G /dev/mapper/vg00-lv_root -r

Verificar resultado final:

df -h /


Resultado esperado

  • El disco físico refleja el nuevo tamaño
  • El volumen físico (PV) usa todo el espacio
  • El volumen lógico (LV) ha crecido
  • El sistema de ficheros se ha extendido correctamente
  • No se requiere reinicio


Caso especial: corrección de tabla GPT

En algunos casos, tras extender el disco, el sistema puede mostrar errores de GPT.

Ejemplo de error detectado por parted:

The backup GPT table is not at the end of the disk

Solución:

parted /dev/sda

Aceptar las opciones:

  • Fix para mover la GPT backup
  • Fix para usar todo el espacio disponible

Verificar tabla corregida:

[root@rkalvumdsws ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print

Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system
believes the disk is smaller.  Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? Fix
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra
838860800 blocks) or continue with the current setting?
Fix/Ignore? Fix
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  269MB   268MB   fat16        EFI System Partition  boot
 2      269MB   1343MB  1074MB  ext4
 3      1343MB  107GB   106GB                                      lvm

(parted)

Notas importantes

  • No cambiar nunca el sector inicial de la partición LVM
  • Este procedimiento es seguro si se sigue correctamente
  • Recomendado ejecutar en ventanas de mantenimiento
  • Funciona en RHEL 7 y RHEL 8 sobre VMware


Referencias

  • Documentación oficial Red Hat LVM
  • VMware Guest OS Disk Rescan