La máquina virtual VMware expande el espacio en disco del directorio raíz de Linux (CentOS)

1. Apague Centos, elija editar la configuración de la máquina virtual, el disco duro, seleccione "Extender" en la utilidad y
Inserte la descripción de la imagen aquí
Inserte la descripción de la imagen aquí
haga clic en la extensión, VMware le indicará que el disco se ha extendido correctamente. Debe volver a particionar el disco y extender el sistema de archivos desde el sistema operativo invitado. En otras palabras, el espacio en disco expandido aquí aún no está disponible en el sistema operativo y aún no ha entrado en vigencia. Solo se puede usar después de configurarlo en el sistema operativo.
Inserte la descripción de la imagen aquí


2. Inicie el sistema operativo invitado Centos, verifique la situación del disco e
ingrese las instrucciones

[root@dw ~]# fdisk -l

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: 0x000b0b8a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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 /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

Entre ellos, puede ver que la situación actual de la partición es la siguiente

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

3. Crear
comando de entrada de partición sda3

[root@dw ~]# fdisk /dev/sda

Luego cree una partición de acuerdo con el símbolo del sistema, consulte la nota siguiente # para obtener más detalles

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): n    # 输入 n 表示创建新分区
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3    # 输入 3 表示sda3,因为前面已经有两个了
First sector (83886080-209715199, default 83886080):    # 回车,按默认值
Using default value 83886080
Last sector, +sectors or +size{
    
    K,M,G} (83886080-209715199, default 209715199):    # 回车,按默认值
Using default value 209715199
Partition 3 of type Linux and of size 60 GiB is set

Command (m for help): w    # 输入 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.

Verifique la partición nuevamente

[root@dw ~]# fdisk -l

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: 0x000b0b8a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM
/dev/sda3        83886080   209715199    62914560   83  Linux

Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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 /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

Entre ellos, la partición se ha cambiado a 3, pero esta vez no se ha montado y aún no se puede usar.

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM
/dev/sda3        83886080   209715199    62914560   83  Linux

4. Reinicie el sistema operativo.

[root@dw ~]# reboot

5. Formatee la nueva partición como ext3

Comando de entrada

[root@dw ~]# mkfs -t ext3 /dev/sda3

El resultado es

mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3932160 inodes, 15728640 blocks
786432 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
480 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

6. Inicialice la partición del disco duro físico como un volumen físico, para que LVM pueda usarlo, ingrese la instrucción

[root@dw ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <35.12g
  swap centos -wi-ao----  <3.88g
[root@dw ~]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.

7. Agregue volúmenes físicos al grupo de volúmenes para aumentar la capacidad del grupo de volúmenes.

Vea el nombre del grupo lvm, ingrese el comando df -h

[root@dw ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   36G   18G   18G  49% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    378M     0  378M   0% /run/user/0

Entre ellos, centos-root es el nombre del grupo donde se encuentra la raíz

Ingrese instrucciones para aumentar la capacidad del grupo de volumen

[root@dw ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended

8. Verifique el tamaño del espacio expandible

Ingrese el comando para mostrar la información de metadatos del grupo de volumen LNM

[root@dw ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               98.99 GiB
  PE Size               4.00 MiB
  Total PE              25342
  Alloc PE / Size       9982 / 38.99 GiB
  Free  PE / Size       15360 / 60.00 GiB
  VG UUID               zJfuos-4OrR-b2OS-g589-oj2P-Jhqe-laP5QC

Entre ellos, Free PE / Size es el espacio libre disponible para la asignación, hasta 60,00G, ingrese menos que este valor durante la expansión


9, expanda el espacio en disco

[root@dw ~]# lvextend -L+58G /dev/mapper/centos-root /dev/sda3

Rápido éxito de expansión

  Size of logical volume centos/root changed from <35.12 GiB (8990 extents) to <93.12 GiB (23838 extents).
  Logical volume centos/root successfully resized.

10. Utilice el comando e2fsck para verificar los errores del sistema de archivos.

[root@dw ~]# e2fsck -a /dev/mapper/centos-root
/dev/mapper/centos-root is mounted.
e2fsck: Cannot continue, aborting.

11. La expansión de archivos en formato xfs necesita usar el comando xfs_growfs para aumentar o reducir el tamaño del sistema de archivos "ext2 / ext3" descargado.

[root@dw ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        94G   18G   76G  19% /
/dev/sda1               xfs      1014M  149M  866M  15% /boot
tmpfs                   tmpfs     378M     0  378M   0% /run/user/0
[root@dw ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2301440 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9205760, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4495, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9205760 to 24410112

12. Vea los resultados después de expandir el espacio.

[root@dw ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   94G   18G   76G  19% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    378M     0  378M   0% /run/user/0

Como puede ver, el espacio en disco en el directorio raíz se ha expandido, ¡y listo!

Supongo que te gusta

Origin blog.csdn.net/weixin_48482704/article/details/115075411
Recomendado
Clasificación