大网数据广告活动
服务器运维问答

How to increase KVM guest disk size using LVM VG as storage pool?

· 52CE 我爱测

The KVM host server is running CentOS 6.5 and a LVM volume group "storage_pool" is used as the main storage pool for KVM. An Ubuntu guest is installed using an ext4 filesystem and mounts the whole /dev/vda1 as /. This is the gues…

问题原文

原帖链接 · f10bit · CC BY-SA 3.0

The KVM host server is running CentOS 6.5 and a LVM volume group "storage_pool" is used as the main storage pool for KVM.

An Ubuntu guest is installed using an ext4 filesystem and mounts the whole /dev/vda1 as /. This is the guest disk configuration:

<disk type='block' device='disk'>
  <driver name='qemu' type='raw' cache='none' io='native'/>
  <source dev='/dev/storage_pool/kvmguest.img'/>
  <target dev='vda' bus='virtio'/>
  <alias name='virtio-disk0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>

What would be the best approach to increase the guest disk size? The VG has a lot of free space.

I have found some examples but most use LVM inside the guests as well, or weren't completely applicable. As far as I understand, the common method is to create a larger LV in the same VG, shutdown the guest, transfer the data, edit the configuration to use the new LV?

Thanks in advance for any suggestions or pointers

已采纳解答

原帖链接 · f10bit · CC BY-SA 3.0

This is the procedure I went with:

  1. Extend the logical volume of the kvm guest

    # lvextend -L+50G /dev/storage_pool/guest.img
    
  2. Shutdown the kvm guest and deactivate the logical volume

    # virsh shutdown guest
    # lvchange -a n /dev/storage_pool/guest.img
    
  3. List and note the partition information of the kvm guest, most importantly the first sector. If it doesn't display sectors you may need to add the '-u' or '-u sectors' switch

    # fdisk -l /dev/storage_pool/guest.img
    
  4. Delete and recreate the partition to fill the whole extended space, make sure you are using sectors as units and to select the same first sector (usually 2048 if partition is aligned), you can use the 'u' fdisk command to toggle between units

    # fdisk /dev/storage_pool/guest.img
    Command (m for help): d
    Partition number (1-4): 1
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (...): 2048
    Last sector...: hit enter and use the default last sector
    Command (m for help): a
    Partition number (1-4): 1
    Command (m for help): w
    
  5. Expose the ext3/4 filesystem and resize it

    # kpartx -a -v /dev/storage_pool/guest.img
    # e2fsck -p -f /dev/mapper/storage_pool-guest.img1
    # resize2fs /dev/mapper/storage_pool-guest.img1
    # e2fsck -p -f /dev/mapper/storage_pool-guest.img1
    # kpartx -d -v /dev/storage_pool/guest.img
    
  6. Activate the logical volume and start the kvm guest

    # lvchange -a y /dev/storage_pool/guest.img
    # virsh start guest
    

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-05-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。