尝试识别并扩展 CentOS 根分区

尝试识别并扩展 CentOS 根分区

我帮助一家位于半个国家的公司维护他们在 CentOS 7 上运行的网站和 Web 服务器。根分区不断耗尽磁盘空间并导致服务器崩溃,所以他们说他们又为其添加了 300GB。我无法识别新的磁盘空间并将其添加到根分区。

这是fdisk -l输出。

$ sudo fdisk -l

Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0007be79

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   266338303   132656128   8e  Linux LVM

Disk /dev/sdb: 136.4 GB, 136365211648 bytes, 266338304 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-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 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 / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/centos-home: 77.9 GB, 77921779712 bytes, 152190976 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

我有点困惑。/dev/sda 有 322.1 GB,磁盘标签类型为“dos”。我假设这是新磁盘。

但是上面有 sda1 和 sda2 分区。那是操作系统吗?

我需要向 /dev/mapper/centos-root 分区添加 300 GB。我该怎么做?

我附上了一些可能有用的其他命令的结果。

$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               126.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              32386
  Free PE               16
  Allocated PE          32370
  PV UUID               vFa16P-F0LF-hpTo-6xca-Wz83-wfoD-GbxNVp

$ sudo lvmdiskscan
  /dev/centos/root [      50.00 GiB] 
  /dev/sda1        [     500.00 MiB] 
  /dev/centos/swap [      <3.88 GiB] 
  /dev/sda2        [     126.51 GiB] LVM physical volume
  /dev/centos/home [      72.57 GiB] 
  /dev/sdb         [     127.00 GiB] 
  4 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

$ sudo parted -l
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 322GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  525MB  524MB  primary  xfs          boot
 2      525MB   136GB  136GB  primary               lvm


Error: /dev/sdb: unrecognised disk label
Model: Msft Virtual Disk (scsi)                                           
Disk /dev/sdb: 136GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-home: 77.9GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  77.9GB  77.9GB  xfs


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system     Flags
 1      0.00B  4161MB  4161MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 53.7GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  53.7GB  53.7GB  xfs

答案1

我刚刚找到了这个出色的教程,它解决了我所有的问题。我看了两遍。第一次是将未使用的 /dev/sda 空间格式化为 LVM 分区并将其添加到逻辑卷。第二次是格式化新的 /dev/sdb 磁盘,并将其添加到逻辑卷。

我的 centos-root 磁盘空间从 54 GB 增加到了 376 GB!

https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk/

相关内容