使用 vgextend/lvextend 添加额外的 8GB 空间,但未反映在 df 输出中

Ant*_*ong 7 lvm virtualbox ubuntu-12.04

我在 VirtualBox 中创建了一个 ubuntu VM 实例。一开始我只为存储分配了 7GB,现在虚拟机空间不足。

首先,我通过 VirtualBox 前端向 VM 添加了另一个 8GB (/dev/sdb)。然后我设置了以下分区:

$ sudo fdisk -l /dev/sdb

Disk /dev/sdb: 8589 MB, 8589934592 bytes
40 heads, 1 sectors/track, 419430 cylinders, total 16777216 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 identifier: 0x076b5690

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    16777215     8387584    5  Extended
/dev/sdb5            4096    16777215     8386560   8e  Linux LVM
Run Code Online (Sandbox Code Playgroud)

然后我运行以下命令来扩展 VG。

  sudo pvcreate /dev/sdb5
  sudo vgextend ubuntudevbox2 /dev/sdb5
  sudo lvextend 100% /dev/ubuntudevbox2/root
  lvextend --help
  sudo lvextend -l 100%FREE /dev/ubuntudevbox2/root
  sudo lvextend -r -l 100%FREE /dev/ubuntudevbox2/root
  sudo resize2fs  /dev/mapper/ubuntudevbox2-root
Run Code Online (Sandbox Code Playgroud)

我原以为 / 的大小会扩展到 16Gb。然而 df 报告说

$ df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/ubuntudevbox2-root  8.0G  6.9G  680M  92% /
Run Code Online (Sandbox Code Playgroud)

root mount 只增加到 8G

这是VG信息

$ sudo vgdisplay ubuntudevbox2
[sudo] password for antkong: 
  --- Volume group ---
  VG Name               ubuntudevbox2
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               15.75 GiB
  PE Size               4.00 MiB
  Total PE              4033
  Alloc PE / Size       2182 / 8.52 GiB
  Free  PE / Size       1851 / 7.23 GiB
  VG UUID               ZV6VAi-qkxC-KnKz-1LHg-nfLB-afSI-mVpIPv
Run Code Online (Sandbox Code Playgroud)

为什么我没有获得完整的 8Gb 额外空间?

附加信息 1:我mkfs -t ext5 /dev/sdb5在使用 fdisk 添加新分区后立即运行。它会导致失败吗?

附加信息2:

$ uname -a
Linux ubuntudevbox2 3.5.0-27-generic #46-Ubuntu SMP Mon Mar 25 19:58:17 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

lvdisplay 输出:

$ sudo lvdisplay

  --- Logical volume ---
  LV Path                /dev/ubuntudevbox2/root
  LV Name                root
  VG Name                ubuntudevbox2
  LV UUID                V1Qq0f-qKJR-UTf5-4tjM-ycoY-1J5L-mJQ2Fy
  LV Write Access        read/write
  LV Creation host, time ubuntudevbox2, 2013-03-29 12:18:26 +1100
  LV Status              available
  # open                 1
  LV Size                8.03 GiB
  Current LE             2055
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/ubuntudevbox2/swap_1
  LV Name                swap_1
  VG Name                ubuntudevbox2
  LV UUID                LbvPFE-j3GO-oaF1-HQV3-a2r5-HTfy-YrhQve
  LV Write Access        read/write
  LV Creation host, time ubuntudevbox2, 2013-03-29 12:18:29 +1100
  LV Status              available
  # open                 2
  LV Size                508.00 MiB
  Current LE             127
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
Run Code Online (Sandbox Code Playgroud)

Mat*_*Ife 12

输出是绝对行

sudo lvextend -l 100%FREE /dev/ubuntudevbox2/root
Run Code Online (Sandbox Code Playgroud)

由于在 vgextended 之后您只有 8G 的空闲扩展区,因此您只能得到一个 lv 来表示 8G 的绝对大小。

您必须通知 LVM 您打算增加空间大小。来自lvextend;的联机帮助页

   -l, --extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}]
          Extend  or  set  the  logical  volume  size  in units of logical
          extents.  With the '+' sign the value is  added  to  the  actual
          size of the logical volume and without it, the value is taken as
          an absolute one.
Run Code Online (Sandbox Code Playgroud)

尝试

sudo lvextend -l +100%FREE /dev/ubuntudevbox2/root
Run Code Online (Sandbox Code Playgroud)

  • @mlfe 我运行它然后再次`sudo resize2fs /dev/mapper/ubuntudevbox2-root`。我现在可以看到我分配的所有空间。谢谢 (2认同)