Diferencia entre revisiones de «Extender disco virtual»

De jagfloriano.com
Ir a la navegaciónIr a la búsqueda
Línea 153: Línea 153:
Partition number (1-3, default 3): 3
Partition number (1-3, default 3): 3
Partition 3 is deleted
Partition 3 is deleted
<syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">

Revisión del 16:44 2 ene 2026

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 ~]#

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@serverA~]# 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

Ejemplo alternativo: Extender disco sin particiones (raw disk)

Escenario

Este procedimiento aplica cuando el disco extendido desde VMware **no contiene particiones** y el sistema de ficheros está creado directamente sobre el dispositivo, por ejemplo /dev/sdb.

En este caso:

  • No se utiliza fdisk ni parted
  • No se modifica la tabla de particiones
  • Solo se requiere reescanear el disco y extender el filesystem


Verificación inicial

Comprobar el punto de montaje y tamaño actual:

[root@serverB ~]# df -Ph /var/lib/gravity
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb       1000G   15G  986G   2% /var/lib/gravity


Verificar que el sistema de ficheros está montado directamente sobre el disco:

[root@serverB ~]# lsblk | grep -i sdb
sdb                        8:16   0  1000G  0 disk /var/lib/gravity

Esto confirma que:

  • El disco **no está particionado**
  • El filesystem reside directamente sobre /dev/sdb


Reescaneo del disco

Forzar al kernel a detectar el nuevo tamaño tras la ampliación en VMware:

[root@serverB ~]# echo 1 > /sys/block/sdb/device/rescan

Verificar el nuevo tamaño detectado:

[root@serverB ~]# lsblk | grep -i sdb
sdb                        8:16   0   1.5T  0 disk /var/lib/gravity


Extender el sistema de ficheros (XFS)

Al tratarse de XFS, el filesystem puede extenderse **en caliente**:

[root@serverB ~]# xfs_growfs /dev/sdb
meta-data=/dev/sdb               isize=512    agcount=4, agsize=65536000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=262144000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=128000, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 262144000 to 392953856
[root@serverB ~]#


Verificación final

Confirmar que el sistema de ficheros refleja el nuevo tamaño:

[root@serverB ~]# df -Ph /var/lib/gravity
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb        1.5T   15G  1.5T   1% /var/lib/gravity
[root@serverB ~]#


Resultado

  • El kernel detecta el nuevo tamaño del disco
  • El filesystem XFS se extiende correctamente
  • No se requieren cambios en particiones
  • No es necesario reiniciar el sistema


Notas importantes

  • Este método solo aplica a discos **sin particiones**
  • El filesystem debe ser XFS
  • En ext4 sería necesario usar resize2fs
  • Siempre verificar con lsblk antes de actuar

Cuándo usar este procedimiento

Utilizar este método cuando:

  • El disco es /dev/sdb, /dev/sdc, etc.
  • No existe /dev/sdb1, /dev/sdb2, etc.
  • El filesystem está directamente sobre el disco

Referencias

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