VirtualBox:扩展分区

发布于 2024-12-15 16:56:39 字数 171 浏览 6 评论 0原文

我安装了 virtualbox-4.1.0 和 centos-5.6。现在我想扩展之前分配给虚拟机安装的 VM 映像,它是 8Gb,现在还不够。有没有办法在不丢失信息的情况下扩展分区?

实际上,在centos中,我有一个根文件系统和我的主目录等,所以这个分区最终需要调整大小。

预先感谢您的建议!

I have virtualbox-4.1.0 with centos-5.6 installed in. Now I would like to extend the VM image, which I previously allocated for virtual machine installation, it was 8Gb, that's not enough now. Is there a way to extend the partition without loosing information?

Actually in centos I have one root fs with my home dir etc. so this partition eventually would need to be resized.

Thanks in advance for suggestions!

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

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

发布评论

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

评论(8

北城半夏 2024-12-22 16:56:39

只需 4 个步骤即可完成:

  1. 使用 VBoxManage 工具将 VMDK 克隆为 VDI 格式。
  2. 使用 VBoxManage 工具调整磁盘大小以创建可用空间。
  3. 修改文件系统以使用 GParted 为驱动器分配可用空间。
  4. 将创建的磁盘空间添加到 Linux 文件系统。

详细步骤如下(使用“虚拟机CentOS 6.4”和“VirtualBox 4.2.18”测试);

  1. 观察virtualbox文件的磁盘格式,如果不是*.vdi,则将磁盘格式从*.wmdk转换为*.vdi。打开 Windows 终端:
    $ VBoxManage clonehd --format VDI "path_of_wmdk_file" "path_of_vdi_file"

  2. 调整 vdi 文件的磁盘大小。打开 Windows 终端。例如,磁盘大小 ~500 GB => 512000;
    $ VBoxManagemodifymedium "path_of_vdi_file" --resize 512000

  3. 选择 *.vdi 文件而不是 *.wmdk 文件作为磁盘
    虚拟机 ->设置->存储->控制器:SATA(右键单击 *.wmdk 文件)->删除附件->添加硬盘并选择新创建的*.vdi文件

  4. http://gparted.sourceforge.net/download.php。将此 iso 文件安装为 CD。
    虚拟机 ->设置->存储->控制器 IDE(右键单击)->添加 CD/DVD ->选择 gparted-live-x.xx.xx-ixxx.iso 文件

  5. 运行虚拟机,虚拟机将从这张CD启动。按“Enter”、“Enter”选择默认值...直到 Gpart ISO GUI 启动。选择工具gpart程序并启动。

  6. 如下扩展磁盘大小;

    • 右键单击分区,如果“可能”,请单击“禁用活动分区”。
    • 通过 GUI 尽可能扩展分区(本例为 500GB)。
    • 右键单击已禁用的分区,然后选择“启用活动分区”。
    • 应用并等待操作完成。
    • 关闭虚拟机。
    • 卸载 gparted-live-x.xx.xx-ixxx.iso。
      虚拟机 ->设置->存储->控制器 IDE(右键单击 gparted-live-x.xx.xx-ixxx.iso)->删除附件
    • 启动虚拟机。
  7. 打开 Linux 终端并以 root 身份登录。运行下面的命令;

 lvm vgdisplay
       => Free  PE / Size       122880 / 480.00 GiB
 lvm lvdisplay /dev/VolGroup/lv_root
       => Current LE             3978
  • 计算上述值的总和。在这种情况下: 122880 + 3978 = 126858 <- 将在下一个命令中使用
 lvm lvresize -l 126858 /dev/VolGroup/lv_root
 resize2fs  /dev/VolGroup/lv_root   
 lsblk
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sr0                          11:0    1  1024M  0 rom  
    sda                           8:0    0   500G  0 disk 
        +¦sda1                        8:1    0   500M  0 part /boot
        L¦sda2                        8:2    0 499.5G  0 part 
            +¦VolGroup-lv_root (dm-0) 253:0    0   480G  0 lvm  /
            L¦VolGroup-lv_swap (dm-1) 253:1    0     4G  0 lvm  [SWAP]
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  • 检查文件系统是否通过创建大文件进行扩展:
 fallocate -l 480G /test_file
  • 当然删除测试文件:
 rm -rif /test_file

It can be done in 4 steps :

  1. Clone your VMDK to VDI format with VBoxManage Tool.
  2. Resize the disk to create free space with VBoxManage Tool.
  3. Modify the filesystem to allocate free space for your drive with GParted.
  4. Add created disk space to Linux FileSystem.

The detailed steps are below (tested with "Virtual Machine CentOS 6.4" and "VirtualBox 4.2.18");

  1. Observe disk format of the virtualbox file, if it is not *.vdi, convert disk format from *.wmdk to *.vdi. Open windows terminal:
    $ VBoxManage clonehd --format VDI "path_of_wmdk_file" "path_of_vdi_file"

  2. Resize disk size of vdi file. Open windows terminal. For example to do disk size ~500 GB => 512000;
    $ VBoxManage modifymedium "path_of_vdi_file" --resize 512000

  3. Choose *.vdi file instead of *.wmdk file as disk
    Virtual Machine -> Settings -> Storage -> Controller : SATA (Right Click on *.wmdk file) -> Remove Attachment -> Add HardDisk and choose newly created *.vdi file

  4. Download "gparted-live-x.xx.x-x-ixxx.iso" file from http://gparted.sourceforge.net/download.php. Mount this iso file as CD.
    Virtual Machine -> Settings -> Storage -> Controller IDE (Right Click) -> Add CD/DVD -> Select gparted-live-x.xx.x-x-ixxx.iso file

  5. Run virtual machine, Virtual Machine will boot from this CD. Choose default values with pressing "Enter", "Enter" ... until Gpart ISO GUI starts. Select tool gpart program and start.

  6. Extend disk size as below;

    • Right click on partitions and if "possible" click on "Disable Active Partion".
    • Extend Partition as much as possible from GUI (for this case 500GB).
    • Right click the partition which is disabled and select "Enable Active Partion".
    • Apply and wait until the operations finished.
    • Shut down virtual machine.
    • Unmount gparted-live-x.xx.x-x-ixxx.iso.
      Virtual Machine -> Settings -> Storage-> Controller IDE (Right Click on gparted-live-x.xx.x-x-ixxx.iso) -> Remove Attachement
    • Start the virtual machine.
  7. Open linux terminal and login as root. Run commands below;

 lvm vgdisplay
       => Free  PE / Size       122880 / 480.00 GiB
 lvm lvdisplay /dev/VolGroup/lv_root
       => Current LE             3978
  • Calculate the sum of the values above. In this case : 122880 + 3978 = 126858 <- will be used in the next command
 lvm lvresize -l 126858 /dev/VolGroup/lv_root
 resize2fs  /dev/VolGroup/lv_root   
 lsblk
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sr0                          11:0    1  1024M  0 rom  
    sda                           8:0    0   500G  0 disk 
        +¦sda1                        8:1    0   500M  0 part /boot
        L¦sda2                        8:2    0 499.5G  0 part 
            +¦VolGroup-lv_root (dm-0) 253:0    0   480G  0 lvm  /
            L¦VolGroup-lv_swap (dm-1) 253:1    0     4G  0 lvm  [SWAP]
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  • Check whether the filesystem extended or not with creating a huge file:
 fallocate -l 480G /test_file
  • Remove the test file of course:
 rm -rif /test_file
老旧海报 2024-12-22 16:56:39

我使用的是 CentOS7 virtualbox,最后我扩大了分区 /dev/mapper/centos-root - gparted 对我不起作用,因为我在 CentOS7 virtualbox 上没有桌面。

  1. 关闭 CentOS 虚拟机电源
  2. 进入 *.vdi 映像的目录。如果您不知道它在哪里,请查看 Virtualbox Manager GUI virtualbox ->;设置->存储-> *.vdi->位置 例如我的位于~/VirtualBox VMs/CentOS7/CentOS.vdi
  3. 备份您的映像,以防万一出现问题

    $ cp CentOS7.vdi CentOS7.backup.vdi

  4. 调整虚拟存储大小,例如 200 GB

    $ VBoxManagemodifyhd CentOS7.vdi --resize 204800

  5. 启动 CentOS 虚拟机,发出问题

    $ sudo fdisk -l

 设备引导开始结束块 ID 系统
    /dev/sda1 * 2048 1026047 512000 83 Linux
    /dev/sda2 1026048 209715199 104344576 8e Linux LVM
  1. 使用fdisk实用程序删除/创建分区

    $ sudo fdisk /dev/sda

  2. 您位于fdisk实用程序交互模式,发出以下命令:(大多数情况下只需遵循默认建议)

    d - 删除分区

    2 - 选择要删除的分区(此处为 /dev/sda2)

    n - 创建一个新分区

    p - 使其成为主分区

    2 - 使其与我们删除的分区号相同

    - 设置起始块(默认)

    - 设置结束块(默认)

    w - 写入分区并离开 fdisk 交互模式

  3. 重新启动 CentOS 机器

    $ sudo restart

  4. 调整物理卷大小并验证新大小

    $ sudo pvresize /dev/sda2

    $ sudo pvscan

  5. 看看你的逻辑映射卷,看看你想扩大哪个卷,在我的例子中,/dev/mapper/centos-root

  6. 通过添加-r选项来调整文件系统的大小,它会照顾为您调整大小

    $lvextend -r -l +100%FREE /dev/mapper/centos-root

  7. 调整文件系统大小:

    $resize2fs /dev/mapper/fedora-root

    对于 CentOS 7:$xfs_growfs /dev/mapper/fedora-root

  8. 最后检查:

    $df -h

参考:https://blog.jyore.com/2013/06/virtualbox-increase-size-of-rhelfedoracentosscientificos-guest-file-system/#comment-2879

I'm using a CentOS7 virtualbox, and I finally enlarged my partition /dev/mapper/centos-root - gparted doesn't work for me because I do not have a desktop on CentOS7 virtualbox.

  1. Power off your CentOS virtual machine
  2. Go into the directory of your *.vdi image. If you don't know where it is, look at your Virtualbox Manager GUI virtualbox -> settings -> storage -> *.vdi -> location e.g. mine is located under ~/VirtualBox VMs/CentOS7/CentOS.vdi
  3. Back up your image just in case anything goes wrong

    $ cp CentOS7.vdi CentOS7.backup.vdi

  4. Resize your virtual storage size, e.g. 200 GB

    $ VBoxManage modifyhd CentOS7.vdi --resize 204800

  5. Power on your CentOS virtual machine, issue

    $ sudo fdisk -l

   Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048   209715199   104344576   8e  Linux LVM
  1. Use fdisk utility to delete/create partitions

    $ sudo fdisk /dev/sda

  2. You are in the fdisk utility interactive mode, issue following commands: (mostly just follow the default recommendation)

    d - delete a partition

    2 - select a partition to delete (/dev/sda2 here)

    n - create a new partition

    p - make it a primary partition

    2 - make it on the same partition number as we deleted

    <return> - set the starting block (by default)

    <return> - set end ending block (by default)

    w - write the partition and leave the fdisk interactive mode

  3. Reboot your CentOS machine

    $ sudo reboot

  4. Resize the physical volume and verify the new size

    $ sudo pvresize /dev/sda2

    $ sudo pvscan

  5. Take a look at your logical mapping volume to see what volume you want to enlarge, in my case, /dev/mapper/centos-root

  6. Resize the file system by adding -r option, it will take care of resizing for you

    $lvextend -r -l +100%FREE /dev/mapper/centos-root

  7. Resize the file system:

    $resize2fs /dev/mapper/fedora-root

    For CentOS 7: $xfs_growfs /dev/mapper/fedora-root

  8. Last check:

    $df -h.

Reference:https://blog.jyore.com/2013/06/virtualbox-increase-size-of-rhelfedoracentosscientificos-guest-file-system/#comment-2879

简单爱 2024-12-22 16:56:39

我在下面的链接中找到了这个金块。我的工作非常适合我,只花了 5 秒钟。

从 VirtualBox 4 开始,他们添加了对扩展的支持。

VBoxManage modifyhd filename.vdi --resize 46080

这会将虚拟磁盘映像的大小调整为 45GB。

https://superuser.com/questions/172651/increasing-disk-space-on-virtualbox< /a>

I found this nugget at the link following. I worked perfect for me and only took 5 seconds.

As of VirtualBox 4 they added support for expansion.

VBoxManage modifyhd filename.vdi --resize 46080

That will resize a virtual disk image to 45GB.

https://superuser.com/questions/172651/increasing-disk-space-on-virtualbox

掩耳倾听 2024-12-22 16:56:39

可以通过 3 个步骤完成:

  • 使用 VBoxManage 将 VMDK 克隆为 VDI 格式 使用 VBoxManage
  • 调整磁盘大小以创建可用空间 使用 GParted
  • 修改文件系统以将可用空间分配给驱动器

不要忘记最后一部分,否则,您将有未分配的可用空间,您的磁盘仍将显示为已满。

我在这里写了一个教程来调整虚拟机磁盘大小

It can be done with 3 steps :

  • cloning your VMDK to VDI format using VBoxManage
  • resize the disk to create free space using VBoxManage
  • modify the filesystem to allocate free space to your drive, using GParted

Don't forget the last part, otherwise, you will have unallocated free space and your disk will still appear as full.

I wrote a tutorial here to resize your VM Disk

很快妥协 2024-12-22 16:56:39

在某些时候,VBoxManage 实用程序稍微改变了语法。值得注意的是,这并不适用于所有虚拟机类型,因此如果您有 *.vmdk,请小心。将 HD 更改为 40GB 的示例命令是:

$ VBoxManage modifyhd MyVirtualImage --resize 40960

仅供参考,我使用的是 VirtualBox 4.2.1、Mac 10.8.2

At some point the VBoxManage utility changed the syntax a little bit. It's worth noting that this doesn't work on all vm types so beware if you have a *.vmdk. An example command to change your HD to 40GB is:

$ VBoxManage modifyhd MyVirtualImage --resize 40960

For reference I am on VirtualBox 4.2.1, Mac 10.8.2

萌︼了一个春 2024-12-22 16:56:39

来自 VirtualBox 常见问题解答

您必须将数据从已有的 VDI 克隆到新的、更大的 VDI 并扩展分区。您可以使用 CloneZilla 等工具将虚拟硬盘克隆到更大的硬盘,并使用 Gparted 等工具来增加分区大小。另一种方法是通过 mpack 使用 CloneVDI 并克隆更大大小的 VDI,然后使用 Gparted 调整分区大小。

从 4.0.0 开始,您可以使用 VBoxManagemodifyhd --resize 来调整 VDI 的最大大小。你只能把它做得更大。之后,使用 Gparted 增加 VDI 内的分区大小。

或者,您可以附加另一个 VDI 并将 /home 安装在那里。

From the VirtualBox FAQ:

You have to clone the data from the VDI you already have to a new, larger VDI and expand the partition(s). You can use tools like CloneZilla to clone the virtual hard drive to the bigger one and Gparted to increase the partition size. Another method is to use CloneVDI by mpack and clone the VDI with a larger size, then resize the partition(s) with Gparted.

Since 4.0.0, you can use VBoxManage modifyhd --resize to resize the max size of the VDI. You can only make it bigger. After that, use Gparted to increase the partition size inside the VDI.

Alternatively you could attach another VDI and mount your /home there.

流星番茄 2024-12-22 16:56:39

在 Oracle VirtualBox 论坛上搜索 CloneVDI 工具。它对我很有用,对于任何对命令行感到紧张的人来说,它都是一个更简单的基于 GUI 的程序。还允许从固定模式转换为动态模式,VBoxManage.exe 尚不支持。

https://forums.virtualbox.org/viewtopic.php?f= 6&t=22422

Search for CloneVDI tool on the Oracle VirtualBox forums. It worked for me and is a much easier GUI based program for anyone nervous at the command line. Also allows conversion from fixed to dynamic mode which VBoxManage.exe doesn't support (yet).

https://forums.virtualbox.org/viewtopic.php?f=6&t=22422

世态炎凉 2024-12-22 16:56:39

我花了很长时间谷歌搜索,终于让它对我有用。 (在我发现这个之前)我想要一个地方来保存我的工作

使用vboxmanage为磁盘映像添加空间

使用 gparted 调整大小,以便使用所有空间

使用 blivet-gui 创建一个新卷:

下面是我从 fedora 终端复制的命令:

dnf install blivet-gui  
blivet-gui  
lvremove /dev/mapper/fedora00-00  
lvextend -l +100%FREE /dev/mapper/fedora00-root

I spent a long time googling and finally got it working for me. ( before I found this ) And I wanted a place to save my work

use vboxmanage to add space to the disk image

use gparted to resize so all space is used

use blivet-gui to create a new volume :

Below is commands I copied from terminal in fedora :

dnf install blivet-gui  
blivet-gui  
lvremove /dev/mapper/fedora00-00  
lvextend -l +100%FREE /dev/mapper/fedora00-root
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文