Resizing disk drive in Ubuntu guest system, running on a Virtual Box Windows host sytem

Submitted by Jochus on Mon, 11/07/2016 - 10:08 | Posted in: Windows

On the host machine (Windows)

  • Release the VDI file: File -> Virtual Media Manager -> Select VDI -> Release
  • Backup the VDI file
  • Open a command prompt and browse to:
    $ cd C:\Program Files\Oracle\VirtualBox
  • Resize your .vdi file:
    $.\VBoxManage modifyhd 'C:\Users\jochen\VirtualBox VMs\Ubuntu\Ubuntu.vdi' --resize 40000 # 40 GB disk
  • Startup your virtual machine

On the guest machine (Ubuntu)

  • Install & start gparted:
    $ sudo apt-get install gparted
    $ gparted
  • Get rid of the swap partition, which prevents you from expanding the root partition. Note that you cannot harm the rest of your machine - this is all happening inside a single file. Worst case scenario you trash this file and you have to use your backup instead.
  • Make a note of the size of the linux-swap partition 4 GB in my case
  • Right click on it and swapoff
  • Right click on it and Delete
  • Apply by clicking on the checkmark (Apply all operations). Ignore the warning
  • Right click on the extended file system that once housed the swap partition (/dev/sda2 in all likelihood) and delete it
  • Right click on the root partition (/dev/sda1) and resize it. Tab to the 'Free space following' field and enter the size of the swap partition. Shift-tab and the machine will work out the new size for you automatically
  • Right click in the unallocated space at the end and make it an extended partition
  • Right click in the new partition and select linux-swap in the File system field.
  • Commit your changes as before
  • Right click on your swap partition and select swapon

Comments

Submitted by Jeff Heatwole (not verified) on Tue, 03/07/2018 - 15:51
 

Important step omitted just before "start up your virtual machine" under windows. You'll need to go into virtual box manager and add your virtual box in under Settings->Storage->SATA.

Submitted by horacio (not verified) on Sat, 11/08/2018 - 23:39
 

thanks

Submitted by prasanna (not verified) on Thu, 18/07/2019 - 13:13
 

excellent. Very detailed.

Submitted by Anonymous (not verified) on Thu, 02/01/2020 - 17:42
 

Note: By deleting / re-adding the swap partition, you may need to edit /etc/fstab to change the swap partition UUID. For example, on Ubuntu 18, you can obtain the new UUID of the swap partition with "blkid", then update /etc/fstab accordingly.

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.