Ton*_*ang 25 kvm virtualization qemu
有没有办法调整虚拟机磁盘的大小?假设将磁盘大小从 32GB 增加到 64GB。我在 Ubuntu 服务器 11.10 64 位上运行 KVM/Qemu。谢谢。
mal*_*lat 29
在基于 Debian 的发行版上,您应该virt-resize改用。这现在处理引擎盖下的几乎所有事情。假设您的图像名为Win7(为什么不呢?)。首先确保您的 VM 已关闭:
安装工具:
# apt-get install libguestfs-tools
Run Code Online (Sandbox Code Playgroud)
获取 VM 磁盘的位置:
# virsh dumpxml Win7 | xpath -e /domain/devices/disk/source
Found 2 nodes in stdin:
-- NODE --
<source file="/var/lib/libvirt/images/Win7.img" />
-- NODE --
<source file="/var/lib/libvirt/images/Win7.iso" />
Run Code Online (Sandbox Code Playgroud)
您可能需要/var/lib/libvirt/images/Win7.img在以下方面进行调整:
# virt-filesystems --long --parts --blkdevs -h -a /var/lib/libvirt/images/Win7.img
Name Type MBR Size Parent
/dev/sda1 partition 07 100M /dev/sda
/dev/sda2 partition 07 32G /dev/sda
/dev/sda device - 32G -
Run Code Online (Sandbox Code Playgroud)
创建您的 64G 磁盘:
# truncate -s 64G /var/lib/libvirt/images/outdisk
Run Code Online (Sandbox Code Playgroud)
您需要扩展 /dev/sda2(不是引导分区):
# virt-resize --expand /dev/sda2 /var/lib/libvirt/images/Win7.img /var/lib/libvirt/images/outdisk
Examining /var/lib/libvirt/images/Win7.img ...
100% [progress bar] --:--
**********
Summary of changes:
/dev/sda1: This partition will be left alone.
/dev/sda2: This partition will be resized from 32G to 64G. The
filesystem ntfs on /dev/sda2 will be expanded using the
'ntfsresize' method.
**********
Setting up initial partition table on outdisk ...
Copying /dev/sda1 ...
Copying /dev/sda2 ...
100% [progress bar] 00:00
100% [progress bar] 00:00
Expanding /dev/sda2 using the 'ntfsresize' method ...
Resize operation completed with no errors. Before deleting the old
disk, carefully check that the resized disk boots and works correctly.
Run Code Online (Sandbox Code Playgroud)
进行备份以防万一(或者mv如果您不想要备份,请使用):
# cp /var/lib/libvirt/images/Win7.img /var/lib/libvirt/images/Win7.img.old
# mv /var/lib/libvirt/images/outdisk /var/lib/libvirt/images/Win7.img
Run Code Online (Sandbox Code Playgroud)
现在启动!
更多信息:man virt-resize
Cae*_*ium 19
我建议在执行任何这些操作之前,您按原样获取磁盘映像的完整副本,然后当它全部中断时,您可以将其复制回来重新开始。
你需要做3件事:
1)使磁盘映像更大。在您的主机中:
qemu-img resize foo.qcow2 +32G
Run Code Online (Sandbox Code Playgroud)
现在您的来宾可以看到更大的磁盘,但仍然有旧的分区和文件系统。
2) 把磁盘镜像里面的分区做大。为此,您需要在来宾中启动 LiveCD,因为您将无法弄乱已安装的分区。这是相当复杂的,可能是最危险的部分。这里复制的东西很多,所以我现在只做链接。你想做这样的事情:
http://www.howtoforge.com/linux_resizing_ext3_partitions_p2
或 2b) 如果您只想要更多存储空间,则创建新分区会更简单(也更安全)。使用 fdisk 或 cfdisk,或者任何你觉得舒服的东西——你现在应该在你的来宾磁盘上看到一大堆未分配的空间。
3)最后,如果您调整现有分区的大小,请使新的更大分区内的文件系统更大(这实际上在上面链接的指南中)。在你的客人里面:
resize2fs /dev/sda1
Run Code Online (Sandbox Code Playgroud)