VirtualBox: extend partition

2019-03-08 00:46发布

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!

8条回答
Evening l夕情丶
2楼-- · 2019-03-08 01:08

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

查看更多
Ridiculous、
3楼-- · 2019-03-08 01:09

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

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-03-08 01:13

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

查看更多
走好不送
5楼-- · 2019-03-08 01:13

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
查看更多
时光不老,我们不散
6楼-- · 2019-03-08 01:22

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

查看更多
戒情不戒烟
7楼-- · 2019-03-08 01:28

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
查看更多
登录 后发表回答