How to Resize a VirtualBox partition (example with Ubuntu LVM2 PV)

Initially when I created the VM I thought would be temporary. It turned out to be not so temporary.

I thought I could just get away with using GParted and resizing the blocks around, but it turned out to be more tricky than expected.




  • Make sure the VM is off
  • Find the VDI file for the drive
  • Make a copy of it



For example sake, here's my 10gb guinea pig.

Expanding the size of the drive

In your host, you have to run some commands to increase the capacity of the drive before you can do anything with partitions.

Use a calculator to calculate how much space you want to allocate in MB.

For reference, 100GB = 1024mb * 100 = 102,400mb

In command prompt, run these commands:

  • cd %PROGRAMFILES%\VirtualBox\
  • VBoxmanage modifyhd "path\to\your.vdi" --resize 51,200

This will only increase the capacity of the file itself.

You can check it in the VirtualBox VM details page, but it's not actually accessible yet.

You still have more work to do.


Lo and behold, I am now 50. Oh wait I'm not, I just look it.

Create a new VM which uses LiveCD

I used a copy of LinuxMint and configured it for Live CD usage. This was purely because I already had the ISO on hand. If you don't, you can save yourself the wait and just grab a GParted LiveCD from their website.

  • CD/DVD drive: LinuxMint or GParted ISO file
  • HDD: Select the VDI drive you want to resize

Using GParted

  • Once you're in GParted and can see the HDD, you'll notice there's a whole lot of free space now
  • If it's locked (there's an icon of a vault), right click and select "Deactivate"
  • Resize the partition (you may need to do this in multiple steps in order to get the right structure)
  • Apply changes
  • Shut down GParted VM


Remember to test the "resized" partition before continuing!

  • Load up your normal VM
  • Test that it boots and operates as normal
  • Check the amount of space remaining with df -kh


Extra steps for LVM partitions

If you're not seeing the space show up in df results, to make that space accessible to the partition you'll need to run two more commands.

The MOUNTPOINT for my VM was "/dev/mapper/ubuntu--vg-root"

  • sudo lvextend -l +100%FREE MOUNTPOINT
  • sudo resize2fs MOUNTPOINT

First command expands the LVM while the second resizes the filesystem.


Now, are you sure that you don't have too much space?


Android: Fix Black Areas in Shape Drawables

When I first experimented with LayerDrawables, I thought something was broken in the way I was loading drawables and initialising the LayerDrawable.

image image

Here's what it looks like on Android 4.1 (API 16) and Android 4.4 (API 19)

For each background and border, I had a drawable defined in XML files. Upon testing the layers individually, the background was loaded fine, however the border drawable was causing the black from appearing.

Here's an example of "cell_border_event.xml" shape drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="">
<stroke android:color="@color/cell_border_event" android:width="3dp"></stroke>

It seems that for Android 4.1 and lower, the shape drawables require a definition for the solid colour attribute. Prior to Android 4.4 the default was black.

<?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="">
<!-- Android 4.1 renders this black if this isn't specified -->
<solid android:color="@android:color/transparent" />
<stroke android:color="@color/cell_border_annual" android:width="3dp"></stroke>

After adjusting this for all the border shapes, it now looks consistent.


Eh, looks about right to me.


Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog