How to Increase Hard Disk Size with Virtualbox

1.  Create a new virtual hard disk

If you are running out of space with your gridseed virtual machine and if this virtual machine was partitioned with lvm software, you can incraese your virtual hard disk by creating a new hd and merging the two hard disks together.

1.1  Add a new virtual hard disk via GUI

NOTE From version 4.x of Virtualbox you cannot use the graphical user interface to create a new hard disk

  • Open the Virtualbox GUI
  • Select the Virtual Media Manager
  • Create a new virtual disk
  • Select to dynamically expanding storage
  • Choose the name and the size of the new hard disk (in our case extension-01 and 2,40GB)
  • Now the new hard disk is created.
  • Go to the virtual machine on which you want to attach the hard disk, and open the settings window.
  • Go to Storage -> SATA Controller -> Add
  • Choose the previously created hard disk.
  • Now your hard disk is attached to the Virtual machine

1.2  Add a new virtual hard disk via CLI

  • Open a Terminal on your host system
  • Create a new hard disk:
vbox@neon:~$ VBoxManage createhd --filename /vm/harddisk/extension-01.vmdk --size 2500 \
 --variant Standard --format VMDK
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8
(C) 2005-2010 Oracle Corporation
All rights reserved.

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: 913bdd47-0a3b-4449-943c-729e34edb383
You have just created a new hard disk named extension-01 with size 2500 MB in

vmdk format.

  • Add the new hard disk to the Virtual Media Manager (NOTE: this commando shouldn't work on Virtualbox 4.x, skip to the next point):
vbox@zenith:~$ VBoxManage openmedium --type normal disk /vm/harddisk/extension-01.vmdk
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8
(C) 2005-2010 Oracle Corporation
All rights reserved.
  • Add the hard disk to the virtual machine
vbox@neon:~$ VBoxManage storageattach <VM> --storagectl "SATA Controller" --port 1 --device 0 \
--type hdd --medium extension-01.vmdk 
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8
(C) 2005-2010 Oracle Corporation
All rights reserved.
This is more complicated that previous commands:
  • storagectl is the name of the storage controller. You can find out what si you contrlooer name with
vbox@neon:~$ VBoxManage showvminfo <VM>
  • port is the port on which you wish to attach the hard disk. In our caseis 1 because on port 0 is already a hard disk.
  • device is the storage controller instance number.
  • type is the type of device that you wish to attach. In our case is hdd.

2.  Extend the virtual machines hard disk

  • Now the hard disk is attached to the virtual machine. Run that machine and login.
  • Check if the OS finds your new hd
[root@localhost ~]# fdisk -l

Disk /dev/sda: 2621 MB, 2621440000 bytes
255 heads, 63 sectors/track, 318 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         318     2449912+  8e  Linux LVM

Disk /dev/sdb: 2621 MB, 2621440000 bytes
255 heads, 63 sectors/track, 318 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
As you see, there is a /dev/sdb without a valid partion table, that is the new hard disk
  • Create a new partition table for that hard disk. Enter the fdisk utility:
[root@localhost ~]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-318, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-318, default 318): 
Using default value 318

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 2621 MB, 2621440000 bytes
255 heads, 63 sectors/track, 318 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         318     2554303+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


We have create a new partition with 'n' command (primary, first cylinder 1, last
318), changed the type with 't' command (to 8e value, Linux LVM), print the
partition table with 'p' and write the changes to hard disk with 'w'.
  • Create a new physical volume:
[root@localhost ~]# pvdisplay 
  /dev/hdc: open failed: No medium found
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               2.34 GB / not usable 24.49 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              74
  Free PE               0
  Allocated PE          74
  PV UUID               bZ829X-q5Du-wtEn-Xq5M-D0JT-Yuxm-MjHa4a

[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               2.34 GB / not usable 24.49 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              74
  Free PE               0
  Allocated PE          74
  PV UUID               bZ829X-q5Du-wtEn-Xq5M-D0JT-Yuxm-MjHa4a

  "/dev/sdb1" is a new physical volume of "2.44 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               2.44 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               M4CU6H-k7KU-O2hM-P00d-b2RI-obU9-tSeRaR
  • Extend the previous volume group
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.31 GB
  PE Size               32.00 MB
  Total PE              74
  Alloc PE / Size       74 / 2.31 GB
  Free  PE / Size       0 / 0   
  VG UUID               BxtAUT-o807-UfVo-CEav-onVy-v8qp-3Imbb0
[root@localhost ~]# vgextend VolGroup00 /dev/sdb1
  Volume group "VolGroup00" successfully extended
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               4.72 GB
  PE Size               32.00 MB
  Total PE              151
  Alloc PE / Size       74 / 2.31 GB
  Free  PE / Size       77 / 2.41 GB
  VG UUID               BxtAUT-o807-UfVo-CEav-onVy-v8qp-3Imbb0
  • Extend the logical volume
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                UrbkHL-pKOm-riZ1-ZZPc-6c6C-MPuY-nNzqRd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.88 GB
  Current LE             60
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fu122V-Y3VR-IoIc-24LL-00UX-7emq-1zmXGd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                448.00 MB
  Current LE             14
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
[root@localhost ~]# lvextend -l +100%FREE /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 4.28 GB
  Logical volume LogVol00 successfully resized
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                UrbkHL-pKOm-riZ1-ZZPc-6c6C-MPuY-nNzqRd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                4.28 GB
  Current LE             137
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fu122V-Y3VR-IoIc-24LL-00UX-7emq-1zmXGd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                448.00 MB
  Current LE             14
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  • Resize the filesystem
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      1.9G  719M  1.1G  41% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm

[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00 
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 1122304 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 1122304 blocks long.

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      4.2G  720M  3.3G  18% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm
Now your system have 4.2G of totale space.