我在 VMware 下有一个虚拟服务器,我从 sysadm 那里获得了 10 GB 的硬盘。
在 Linux 内部(运行 Ubuntu 11.04 服务器),一切都是通过 LVM 设置的。在 [c]fdisk 中,我确实找到了这些额外的 10 个演出 - 它们直接出现在主 LVM 分区之后。
我知道我可以用这个额外的空间创建一个新的 LVM 分区,然后将其添加到卷组,然后添加到逻辑卷,然后调整文件系统的大小。
但是,是否可以将这些额外的 gig 吸收到现有的 LVM 分区中?这样 LVM 对物理卷的看法就增加了,而不是将另一个物理卷添加到卷组中(最好自动渗透到卷组中)?
最佳答案
我刚刚在/dev/sda2 上构建了一个具有 15GB 磁盘和 LVM 的测试虚拟机。然后我将磁盘增加到 20GB 并让 LVM 在不添加另一个物理卷的情况下看到额外的 5GB。
以下是我遵循的步骤:
- apt-get 安装 gnu-fdisk(或 yum 安装 gnu-fdisk)
我必须使用 gfdisk 才能使整个过程正常运行。 “标准”fdisk 不走运。
- gfdisk/dev/sda
换成“扇区”为单位(这个很关键!!!)打印分区表:
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sda: 21 GB, 21089617920 bytes
255 heads, 63 sectors/track, 2564 cylinders, total 41190660 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 257008 83 Linux
Warning: Partition 1 does not end on cylinder boundary.
/dev/sda2 501758 29798632 14643247 8e Linux LVM
Warning: Partition 2 does not end on cylinder boundary.
Command (m for help):
记下“Linux LVM”分区 (/dev/vda2) 的“开始”扇区。 删除分区并使用相同的“起始”扇区 (501758) 和相同的分区类型 (8e) 重新创建它:
Command (m for help): d
Partition number (1-2): 2
Command (m for help): n
Partition type
e extended
p primary partition (1-4)
p
First sector (default 63s): 501758
Last sector or +size or +sizeMB or +sizeKB (default 41190659s):
Command (m for help): p
Disk /dev/sda: 21 GB, 21089617920 bytes
255 heads, 63 sectors/track, 2564 cylinders, total 41190660 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 257008 83 Linux
Warning: Partition 1 does not end on cylinder boundary.
/dev/sda2 501758 41190659 20338290 83 Linux
Command (m for help): t
Partition number (1-2): 2
Hex code (type L to list codes): 8e
Changed type of partition 2 to 8e (Linux LVM)
Command (m for help):
警告:请注意,我不接受分区的默认起始扇区,我是手动输入的,以便它与原始值相匹配!不过,我确实接受了“最后一个扇区”的默认值,因为我希望这个分区与磁盘一样大。
使用“p”验证您所做的一切是否正确,并将新的分区表写入磁盘:
Command (m for help): w
重启虚拟机。 现在登录虚拟机并运行:
root@git:~# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
完成!现在运行 vgdisplay,您将看到额外的 5GB 可用空间。
注意事项:
- 如果 LVM 不是虚拟机磁盘上的最后(或唯一)分区,您可能很难扩展分区的大小。这甚至可能是不可能的。
- 如果 LVM 在逻辑分区上(这是 Debian 在安装时默认放置的位置),或者换句话说,如果 LVM 在/dev/sda5 而不是/dev/sda2 上,您必须记下扩展分区(我们称之为/dev/sda2)和逻辑分区(我们称之为/dev/sda5),然后删除这两个分区,然后用相同的起始扇区重新创建它们。/dev/sda2 和/dev/sda5 的最后一个扇区应该是磁盘的最后一个扇区。
- 由于这是一个有风险的过程,我建议在尝试之前备份虚拟机。
关于vmware - LVM:扩展物理卷(VMWare下),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6898871/