Linux

如何將捲組擴展到 Linux 物理卷的大小

  • June 18, 2019

我從一個 25GB 的硬碟開始,想把它擴展到 150GB。我曾經fdisk將 /dev/sda2 分區從 26GB 擴展到 149GB。lsblk顯示以下資訊:

NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0  150G  0 disk
├─sda1          8:1    0    1G  0 part /boot
└─sda2          8:2    0  149G  0 part
 ├─rhel-root 253:0    0   76G  0 lvm  /
 └─rhel-swap 253:1    0    3G  0 lvm  [SWAP]
sdb             8:16   0   50G  0 disk
└─rhel-root   253:0    0   76G  0 lvm  /
sr0            11:0    1 1024M  0 rom

fdisk -l顯示以下輸出:

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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/sda: 161.1 GB, 161061273600 bytes, 314572800 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: 0x000b0bb3

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   314572799   156236800   83  Linux

Disk /dev/mapper/rhel-root: 81.6 GB, 81595990016 bytes, 159367168 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/rhel-swap: 3221 MB, 3221225472 bytes, 6291456 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

我放入了第二個 50GB 磁碟,並且能夠使用vgextend並將xfs_growfs其添加到卷組中。現在,rhel 卷組是 76GB。但是,我不明白為什麼卷組不是 200GB,因為sda2是 149GB。結果pvscan如下:

 PV /dev/sda2   VG rhel            lvm2 [<29.00 GiB / 0    free]
 PV /dev/sdb    VG rhel            lvm2 [<50.00 GiB / 0    free]
 Total: 2 [78.99 GiB] / in use: 2 [78.99 GiB] / in no VG: 0 [0   ]

它顯示 /dev/sda2 <29.00GB,這讓我感到驚訝。我原以為它是 149G,如圖所示lsblk。我試過了vgextend rhel /dev/sda2,它說物理卷 /dev/sda2 已經在卷組 rhel 中,這是有道理的。我只是在努力理解為什麼df -h我認為它是 200GB 時只顯示 76GB。這是輸出df -h

Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   76G   11G   66G  14% /
devtmpfs               3.9G     0  3.9G   0% /dev
tmpfs                  3.9G     0  3.9G   0% /dev/shm
tmpfs                  3.9G  9.0M  3.9G   1% /run
tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1             1014M  217M  798M  22% /boot
tmpfs                  783M     0  783M   0% /run/user/1000
tmpfs                  783M     0  783M   0% /run/user/0

請讓我知道我可以採取哪些步驟來使 /dev/mapper/rhel-root 成為應有的完整 200GB。

嘗試使用pvresize. 最終分區被調整大小,但不是 lvm 中的物理卷。

https://linux.die.net/man/8/pvresize

引用自:https://serverfault.com/questions/971956