How to increase Virtualbox disk size

Problem

If the size of your virtual disk inside Virtualbox is not big enough to save all your data you can always increase its size and resize the partition.

Solution

First resize the your virtual hard drive, you have to indicate the final size in MB.
user@hostpc:myvm$ VBoxManage modifyhd disk.vdi --resize 16000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Now start the virtual machine and log into it.
You can check that the hard disk size has not changed yet:
root@vm:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 1.5G 1.3G 124M 92% /

But you can see that the disk has more space available:
root@vm:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 15.6G 0 disk
`-sda1 8:1 0 1.5G 0 part /

So now, you have to resize the size of the partition sda1. This can be done with fdisk by removing and creating the same partition with a different last sector:


root@vm:~# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 16.8 GB, 16777216000 bytes
228 heads, 28 sectors/track, 5132 cylinders, total 32768000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002c086

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 3211263 1604608 83 Linux

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-32767999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-32767999, default 32767999):
Using default value 32767999

Command (m for help): p

Disk /dev/sda: 16.8 GB, 16777216000 bytes
228 heads, 28 sectors/track, 5132 cylinders, total 32768000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002c086

Device Boot Start End Blocks Id System
/dev/sda1 2048 32767999 16382976 83 Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Reboot to changes take effect:

root@vm:~# reboot

After reboot you must resize the filesystem:

root@vm:~# resize2fs /dev/sda1
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/sda1 is now 4095744 blocks long.


root@vm:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 16G 1.3G 14G 9% /

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s