LVM:扩展物理卷(VMWare下)

发布于 2024-11-27 02:30:10 字数 313 浏览 2 评论 0原文

我在 VMware 下有一个虚拟服务器,我从 sysadm 那里获得了 10 GB 的硬盘。

在 Linux 内部(运行 Ubuntu 11.04 服务器),一切都是通过 LVM 设置的。在 [c]fdisk 中,我确实发现了这些额外的 10 GB - 它们直接位于主 LVM 分区之后。

我知道我可以用这个额外的空间创建一个新的 LVM 分区,然后将其添加到卷组,然后添加到逻辑卷,然后调整文件系统的大小。

然而,是否有可能将这些额外的空间吸收到现有的 LVM 分区中?这样 LVM 的物理卷视图就会增加,而不是将另一个物理卷添加到卷组中(最好自动渗透到卷组)?

I have a virtual server under VMware, where I got 10 more GB harddisk from the sysadm.

Inside Linux (running Ubuntu 11.04 server), things are set up with LVM. In [c]fdisk, I do find these extra 10 gigs - they are present directly after the primary LVM partition.

I understand that I could make a new LVM partition out of this extra space, and then add this to the volume group, and then to the logical volume, and then resize the filesystem.

However, is it possible to assimilate these extra gigs into the existing LVM partition? So that the LVM's view of the physical volume increased instead of adding another physical volume into the volume group (preferably automatically percolating up to the volume group)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浸婚纱 2024-12-04 02:30:10

我刚刚在 /dev/sda2 上构建了一个带有 15GB 磁盘和 LVM 的测试虚拟机。然后我将磁盘增加到 20GB,并使 LVM 看到额外的 5GB,而无需添加另一个物理卷。

以下是我遵循的步骤:

  • apt-get install gnu-fdisk (或 yum install 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”分区的“起始”扇区(/开发/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. 由于这是一个有风险的过程,我建议在尝试之前先备份虚拟机。

I just built a test virtual machine with a 15GB disk and LVM on /dev/sda2. Then I grew the disk to 20GB and made LVM see the extra 5GB without adding another physical volume.

Here are the steps I followed:

  • apt-get install gnu-fdisk (or yum install gnu-fdisk)

I had to use gfdisk to make the whole thing work. No luck with the "standard" fdisk.

  • gfdisk /dev/sda

Switch to "sectors" as the unit (this is critical!!!) and print the partition table:

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):                                       

Write down the "start" sector of the "Linux LVM" partition (/dev/vda2).
Delete the partition and recreate it using the same "start" sector (501758) and the same partition type (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):                                                     

WARNING: please note that I didn't accept the default start sector for the partition, I entered it manually so that it matches the original value! I did accept the default value for the "last sector" though, because I want this partition to be as large as the disk.

Verify that you did everything correctly with "p" and write the new partition table to disk:

Command (m for help): w                                                   

Reboot the virtual machine.
Now log-in the virtual machine and run:

root@git:~# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Done! Now run vgdisplay and you will see the extra 5GB available as free extents.

CAVEATS:

  1. If LVM is not the last (or only) partition on the virtual machine disk, you might have an hard time extending the size of the partition. It might even be impossible.
  2. If LVM is on a logical partition (which is where Debian puts it by default at install time) or in other words if LVM is on /dev/sda5 instead of /dev/sda2, you must write down the starting sector of both the extended partition (let's call it /dev/sda2) and the logical partition (let's call it /dev/sda5), then delete both partitions, then recreate them with the same starting sector. The last sector of both /dev/sda2 and /dev/sda5 should be the last sector of the disk.
  3. Since this is a risky procedure I recommend doing a backup of the virtual machine before attempting it.
冷了相思 2024-12-04 02:30:10

以下是我在做同样的事情时经常使用的说明......

执行“fdisk –l /dev/sda” 我假设 /dev/sda2 是您的 LVM 分区
而且你没有 /dev/sda3。调整说明以匹配您的配置。

1) 确保您已经对虚拟机磁盘进行了扩容。

2) 执行“fdisk /dev/sda”

  • p(查看现有分区)
  • n(新分区)
  • p(主分区)——给出下一个可用分区号,可能为 3
  • 接受默认值。它将使用磁盘的其余部分
  • w(写入更改)

3) 重新启动

4) 运行“pvcreate /dev/sda3”

5) 运行“vgdisplay”以获取卷组的名称。在此示例中,它是“VolGroup”,如下所示:
enter step5

6) 运行 vgextend VolGroup /dev/sda3

7) 运行“df”查看根卷组的名称.
step7

8) 运行 lvextend /dev/mapper/VolGroup-lv_root -r -l+100%FREE
((-r) 选项也会导致其格式化)

9 运行“df –h”来查看新的磁盘空间

Here are the instructions I always use when I'm doing the same thing...

Do “fdisk –l /dev/sda” I’m assuming /dev/sda2 is your LVM partition
and you don’t have a /dev/sda3. Adjust the instructions to match your config.

1) Make sure you have expanded the VM disk.

2) do “fdisk /dev/sda”

  • p (to see existing partitions)
  • n (new partition)
  • p (primary partition) -- give it the next available partition number, probably 3
  • accept the defaults. It will use the rest of the disk
  • w (write changes)

3) REBOOT

4) run ‘pvcreate /dev/sda3’

5) run ‘vgdisplay’ to get the name of the volume group. In this example, it’s “VolGroup”, as in:
enter step5

6) run vgextend VolGroup /dev/sda3

7) run “df” to see the name of the root volume group.
step7

8) run lvextend /dev/mapper/VolGroup-lv_root -r -l+100%FREE
( the (-r) option causes it to format it, too)

9 run “df –h” to see your new disk space

天邊彩虹 2024-12-04 02:30:10

这是我更喜欢在虚拟机上拥有一个与 /boot 和其他初始部分分开的大物理卷的原因之一。这允许您将整个磁盘创建为 LVM 物理磁盘 (pvcreate /dev/sdb)。然后,如果您需要调整大小,则不需要进行任何文件系统更改,因为它直接位于磁盘上。

在这种情况下,您只需运行 pvresize /dev/sdb 并继续执行 vgextend、lvextend 和 resize2fs。维护起来更简单。

This is one of the reasons I prefer to have one big physical volume on the VMs that is separate from the /boot and other initial parts. This allows you to create a whole disk as an LVM physical disk (pvcreate /dev/sdb). Then if you need to do a resize, none of the file system changes need to happen because it is directly on disk.

In that scenario, you simply run pvresize /dev/sdb and move on with your vgextend, lvextend and resize2fs. Much simpler to maintain.

终难愈 2024-12-04 02:30:10

就我个人而言,我遵循了此博客中的说明。

总结一下步骤:

  • 使用 vm-ware 工具 vmware-vdiskmanager 增加虚拟磁盘大小
  • 在另一个系统上启动(GParted live CD 或安装 Iso CD-ROM 来启动)
  • 使用 Gparted 工具 (简单和图形界面)增加最近扩展的驱动器
  • 删除CD-ROM(或ISO)并在原始分区上启动。

为了扩展我的 Linux VM (RedHat EL 6),我确实在 GParted ISO 映像上启动(来自 此处 )并且我能够扩展我想要的分区。请注意,最后我必须移动我想要不变的分区。

我的一位同事也很安全,但我建议在运行 Gparted Linux 之前备份虚拟机。

Personally I followed the instruction in this blog.

To summarize the steps:

  • Increase the virtual disk size using the vm-ware tools vmware-vdiskmanager
  • Boot on another system (GParted live CD or mount an Iso CD-ROM to boot on)
  • Use the Gparted tools (easy and graphic interface) to increase the recently expended drive
  • remove the CD-ROM (or the ISO) and boot on the original partition.

For expanding my Linux VM (RedHat EL 6) I did boot on the GParted ISO image (from here) and I was able to extend the partition I wanted. Note I had to move the partition I wanted unchanged at the end.

It was safe with one of my colleague as well, but I would recommand to backup the VM before running Gparted Linux.

菩提树下叶撕阳。 2024-12-04 02:30:10

无需重启即可扩展磁盘

    echo 1 > /sys/block/sda/device/rescan
    echo 1 > /sys/block/sdb/device/rescan
    
    partprobe
    
    gdisk fix warnging
    
    parted change partion size
    
    ## parted can executed as command line. but this is very dangerous
    parted -s /dev/sdb "resizepart 2 -1" quit
    parted -s /dev/sdb "resizepart 3 100%" quit
    resizepart 3 100%
    
    pvresize /dev/sda3
    
    lvextend -l +100%FREE cs/root
    
    xfs_growfs /dev/cs/root

extend disk without reboot

    echo 1 > /sys/block/sda/device/rescan
    echo 1 > /sys/block/sdb/device/rescan
    
    partprobe
    
    gdisk fix warnging
    
    parted change partion size
    
    ## parted can executed as command line. but this is very dangerous
    parted -s /dev/sdb "resizepart 2 -1" quit
    parted -s /dev/sdb "resizepart 3 100%" quit
    resizepart 3 100%
    
    pvresize /dev/sda3
    
    lvextend -l +100%FREE cs/root
    
    xfs_growfs /dev/cs/root
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文