還原單一磁碟上分割區的 pvresize 指令

還原單一磁碟上分割區的 pvresize 指令

當我嘗試為 / 文字系統擴展我的 lvm 時,我犯了一個錯誤。我也不確定這是否是個錯誤。
我沒有創建新分區並將其添加到 pv、vg,然後擴展 lv,而是從為根檔案系統提供服務的當前分區使用命令「pvresize」開始。

我執行的命令是:

[root@...]pvresize /dev/sda3 --setphysicalvolumesize 40G 

然後我嘗試使用以下內容擴充 vg:

 [root@...]# vgextend titan /dev/sda3 
  /dev/sdc: open failed: No medium found
  WARNING: Device /dev/sda3 has size of 58351616 sectors which is smaller than corresponding PV size of 83884032 sectors. Was device resized?
  WARNING: One or more devices used as PVs in VG vg have changed sizes.
  Physical volume '/dev/sda3' is already in volume group 'vg'
  Unable to add physical volume '/dev/sda3' to volume group 'vg'
  /dev/sda3: physical volume not initialized.

看到上面的輸出後,我意識到我必須在正在操作的單一磁碟上建立另一個分割區並將其新增到 pv 組,擴展磁碟區組,然後為根檔案系統增加邏輯磁碟區。

問題:如何安全地將實體磁碟區大小還原到開始時的位置,以使有關大小變更的警告消失?

您可以在這裡找到我認為您需要進一步指導解決方案的資訊:

[root@...]# lsblk -b
NAME           MAJ:MIN RM          SIZE RO TYPE MOUNTPOINT
sda              8:0    0  480103981056  0 disk 
├─sda1           8:1    0     629145600  0 part /boot/efi
├─sda2           8:2    0    1073741824  0 part /boot
└─sda3           8:3    0   29876027392  0 part 
  ├─lv-root 253:0    0   21474836480  0 lvm  /
  └─lv-swap 253:1    0    8396996608  0 lvm  [SWAP]

[root@t...]# pvdisplay -m -v
    WARNING: Device /dev/sda3 has size of 58351616 sectors which is smaller than corresponding PV size of 83884032 sectors. Was device resized?
  WARNING: One or more devices used as PVs in VG titan have changed sizes.
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg
  PV Size               <40.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              10239
  Free PE               3117
  Allocated PE          7122
  PV UUID               FgC2QI-pRpK-LZNS-di9w-Jc1d-XGXZ-2QxZI2

  --- Physical Segments ---
  Physical extent 0 to 5119:
    Logical volume  /dev/lv/root
    Logical extents 0 to 5119
  Physical extent 5120 to 7121:
    Logical volume  /dev/lv/swap
    Logical extents 0 to 2001
  Physical extent 7122 to 10238:
    FREE

答案1

在互聯網上花了時間並且不知道我要做什麼之後,我只是注意到錯誤本身並告訴我可以使用那裡提到的確切扇區大小。所以我執行了命令:

[root@...] pvresize --setphysicalvolumesize 58351616s

而且效果完美無缺。

[root@t...]# pvdisplay
   --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg
  PV Size               27.82 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              7122
  Free PE               0
  Allocated PE          7122
  PV UUID               FgC2QI-pRpK-LZNS-di9w-Jc1d-XGXZ-2QxZI2

  --- Physical volume ---
  PV Name               /dev/sda4
  VG Name               vg
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               n5CdvZ-0s9A-iZoz-A2i7-icF9-Wv42-CsL3s9

相關內容