尝试使用 gdisk 调整 LVM 分区大小

尝试使用 gdisk 调整 LVM 分区大小

我使用带有两个逻辑卷的 LVM:

  • 首先LV挂载到根目录/
  • 第二个 LV 挂载到/var/log目录

这两个 LV 基于物理卷 /dev/sda3。设备 /dev/sda 使用 GPT 分区表。

我的目的是调整分区 /dev/sda3 的大小以占用磁盘上的所有可用内存。

为此我使用了gdisk命令:

这是我当前的分区表:

Command (? for help): p
Disk /dev/sda: 4294967296 sectors, 2.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 546DEB45-C1DE-402B-BB51-4011AC159B4F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 4294967262
Partitions will be aligned on 8-sector boundaries
Total free space is 4188012544 sectors (2.0 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34          614433   300.0 MiB   EF00
   2          614434        17386294   8.0 GiB     8200
   3        17386295       106954718   42.7 GiB    8E00

这就是我调整第三个分区大小的方法:

Command (? for help): d
Partition number (1-3): 3

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (17386295-4294967262, default = 17386296) or {+-}size{KMGTP}:
Last sector (17386296-4294967262, default = 4294967262) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

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.
The operation has completed successfully.

事实上,第三个分区有新的大小:

Command (? for help): p
Disk /dev/sda: 4294967296 sectors, 2.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 546DEB45-C1DE-402B-BB51-4011AC159B4F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 4294967262
Partitions will be aligned on 8-sector boundaries
Total free space is 1 sectors (512 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34          614433   300.0 MiB   EF00
   2          614434        17386294   8.0 GiB     8200
   3        17386296      4294967262   2.0 TiB     8E00  Linux LVM

现在,我需要通知内核分区表的新变化。

据我了解,有以下三种选择:

partprobe

Error: Partition(s) 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.

partx -uv /dev/sda

partition: none, disk: /dev/sda, lower: 0, upper: 0
/dev/sda: partition table type 'gpt' detected
/dev/sda: partition #1 resized
/dev/sda: partition #2 resized
/dev/sda: partition #3 resized
partx: /dev/sda: updating partition #3 failed: Invalid argument
partx: /dev/sda: error updating partition 3

reboot:机器没有恢复,我进入了 KDB shell。

问:我做错了什么?增加分区 /dev/sda3 大小的正确方法是什么?

顺便说一句,我注意到当我使用像 100GiB 这样的较小磁盘(而不是我之前使用的 2TiB)时,命令partx -uv /dev/sda在职的没有引发错误(partprobe仍在抱怨)。这该如何解释呢?

感谢您的帮助!

答案1

gdisk结果中可以看出,前后的起始扇区之间存在差异。

3 17386295 106954718 42.7 GiB 8E00

3 17386296 4294967262 2.0 TiB 8E00 Linux LVM

这会导致 LVM 出现问题,因为它无法识别 PV 的正确信息。尝试更正此问题(将起始扇区设置为 17386295),分区的可见性将恢复,因为 PV 将恢复。

相关内容