Skip to Content

You are here

Extend Virtualbox Hard disk on CentOS-5

I have been struggling to increase the Hard disk size of my Development Enviornment on Virtualbox with CentOS-5.
Found some nice steps to increase the space of hard disk.
Follow these steps in order to increase the hard disk space.
A) First lets increase the size of current vdi file.
Download the tool CloneVDI in the attachment to copy the current hard disk.
1. Extract the tool and Browse the current .vdi file. suppose cent-os.v1.vdi is your current OS hdd.
2. Give the output name of the vdi file for increased HDD suppose cent-os.v2.vdi.
3. DONT FORGET to check two checkboxes
    a. increase virtual drive size to SIZE GB.
    b. increase partition size ( this will be disabled till you check the first one )
4. Once you select the options hit PROCEED button.
5. It will clone your current vdi file into another vdi ie. in our case its cent-os.v.2.vdi the hard disk with incrased hard disk.
6. Now the problem will be your UUID of the virtual machine and the added RAW space in the virtual hard disk. Its neither partitioned nor of any file system it will be considered as non-partitioned space in the system.
7. To avoid the problem of UUID you have to create new virtual machine and then to solve the problem of unpartitioned space you have to format the current partition inth ext3 format and add the same into current system hard disk. Follow procedure B
 
B ) To partition the space you need to know what partitions you have available you need to be root in order to do all these system level changes :
Use su root and password to login as super user.
a. check the partitions using
/sbin/fdisk -l
Output :
Disk /dev/sda: 30.0 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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        2610    20860402+  8e  Linux LVM

you will find /dev/sda size as added in this case its 22.6 GB.
b. format the hard disk with fdisk
/sbin/fdisk /dev/sda
it will enter into the fdisk console in order to format your hard disk.
you have to enter following commands one by one :
n - new partition
p- primary partition
3- number of parition ( default there will be 2 partitions available so we have to choose 3 if you have more u can use+1 more than parition numbers )
It will create /dev/sda3 in our case.
Now you have to specify logical volume type ie. 8e. HEXADECIMAL number identifier
t - specify type
3 - paritition number
8e (set type to LVM)
It will set the partition of the type 8e.
p (view the new partitions layout)
w (write out the new partitions layout to disk)
Now you must reboot to display into the logical volume manager the parititions.
 
c. Once you reboot you should login as root or with su :
check whether /dev/sda3 added into your
/sbin/fdisk -l
Disk /dev/sda: 30.0 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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        2610    20860402+  8e  Linux LVM
/dev/sda3            2611        6527    31463302+  8e  Linux LVM

Convert /dev/sda3 partition into a Physical Volume so LVM can make use of it:
/usr/sbin/pvcreate /dev/sda3
Add the new Physical Volume to the Volume Group as additional free space:
/usr/sbin/vgextend VolGroup00 /dev/sda3
/usr/sbin/vgdisplay (note the free space now in the Volume Group which can now be assigned to a Logical Volume)
this will display
Alloc PE / Size       1596 / 8.00 GB
Free  PE / Size       960 / 22.00 GB
in your output terminal.
Now we have to add the same into our logical volume
/usr/sbin/lvextend -l +100%FREE /dev/VolGroup00/LogVol00
once its done try to
/usr/sbin/vgdisplay
Alloc PE / Size       1596 / 30.00 GB
Free  PE / Size       960 / 00.00 GB
Trigger online resizing of the live and mounted filesystem so the new disk space can be utilized immediately:
resize2fs -p /dev/mapper/VolGroup00-LogVol00
Now, the system has a bigger diskspace to play around with.
df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
45G  3.2G   40G   8% /
/dev/sda1              99M   19M   76M  20% /boot
tmpfs                1014M     0 1014M   0% /dev/shm
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
30G  8.2G   22.7G   18% /
/dev/sda1              99M   19M   76M  20% /boot
tmpfs                1014M     0 1014M   0% /dev/shm

AttachmentSize
Package icon CloneVDI-exe-2.05.zip116.42 KB
Tags: