vmware - LVM:扩展物理卷(VMWare下)

标签 vmware hard-drive lvm

我在 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 可用空间。

注意事项:

  1. 如果 LVM 不是虚拟机磁盘上的最后(或唯一)分区,您可能很难扩展分区的大小。这甚至可能是不可能的。
  2. 如果 LVM 在逻辑分区上(这是 Debian 在安装时默认放置的位置),或者换句话说,如果 LVM 在/dev/sda5 而不是/dev/sda2 上,您必须记下扩展分区(我们称之为/dev/sda2)和逻辑分区(我们称之为/dev/sda5),然后删除这两个分区,然后用相同的起始扇区重新创建它们。/dev/sda2 和/dev/sda5 的最后一个扇区应该是磁盘的最后一个扇区。
  3. 由于这是一个有风险的过程,我建议在尝试之前备份虚拟机。

关于vmware - LVM:扩展物理卷(VMWare下),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6898871/

相关文章:

c# - 如何使用 Java 在 Windows 上创建虚拟磁盘(letter、share 等)?

io - 当我在一个 LV 下有多个磁盘时,lvm 的性能如何

centos7 - 在 LVM 之上扩展 GlusterFS

c# - vSphere VMware.Vim Clone_VM 'The operation is not allowed in the current state.'

ssh - 如果 SSH session 断开连接,通过 SSH 在 Vmware ESXI 主机外壳上运行的进程是否会继续?

linux - Ifconfig 不提供 Kali Linux 上的任何详细信息

c++ - 保留硬盘中数据的物理地址

linux - 如何连接到 vmplayer guest 操作系统上托管的网络服务器?

C++ Qt - 获取物理磁盘大小 (Win32)

linux - lvcreate 在物理卷上创建什么?会删除数据吗?