VirtualBox:扩展分区 [英] VirtualBox: extend partition

查看:58
本文介绍了VirtualBox:扩展分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

实际上在 centos 中,我的主目录等有一个 root fs,所以这个分区最终需要调整大小.

提前感谢您的建议!

解决方案

可以分4步完成:

  1. 使用 VBoxManage Tool 将您的 VMDK 克隆为 VDI 格式.
  2. 使用 VBoxManage Tool 调整磁盘大小以创建可用空间.
  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;
    $ VBoxManage modifymedium "path_of_vdi_file" --resize 512000

  3. 选择*.vdi文件而不是*.wmdk文件作为磁盘
    Virtual Machine -> Settings -> Storage -> Controller : SATA (Right Click on *.wmdk file) -> Remove Attachment -> Add HardDisk 并选择新创建的 *.vdi 文件

  4. 下载gparted-live-x.xx.xx-ixxx.iso"文件http://gparted.sourceforge.net/download.php.将此iso文件挂载为CD.
    Virtual Machine -> Settings -> Storage -> Controller IDE (Right Click) -> Add CD/DVD -> 选择 gparted-live-x.xx.xx-ixxx.iso 文件

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

  6. 如下扩展磁盘大小;

    • 右键单击分区,如果可能"单击禁用活动分区".
    • 尽可能从 GUI 扩展分区(在本例中为 500GB).
    • 右键单击禁用的分区并选择启用活动分区".
    • 申请并等待操作完成.
    • 关闭虚拟机.
    • 卸载 gparted-live-x.xx.x-x-ixxx.iso.
      Virtual Machine -> Settings -> Storage -> Controller IDE (右键点击gparted-live-x.xx.x-x-ixxx.iso) -> 删除附件
    • 启动虚拟机.

  7. 打开 linux 终端并以 root 身份登录.运行下面的命令;

<前>lvm vgdisplay=> 免费 PE/大小 122880/480.00 GiB

<前>lvm lvdisplay/dev/VolGroup/lv_root=> 当前 LE 3978

  • 计算上述值的总和.在这种情况下: 122880 + 3978 = 126858 <- 将在下一个命令中使用
<前>lvm lvresize -l 126858/dev/VolGroup/lv_root

<前>resize2fs/dev/VolGroup/lv_root

<前>lsblk++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++名称 MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 1024M 0 ROMsda 8:0 0 500G 0 磁盘+|sda1 8:1 0 500M 0 部分/bootL|sda2 8:2 0 499.5G 0 部分+|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

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!

解决方案

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

这篇关于VirtualBox:扩展分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆