DEV Community

schollii
schollii

Posted on

Expand disk in virtualbox Ubuntu 18 guest

I needed to expand the virtual disk drive of several Ubuntu 18.10 vm guests I had. I looked around the web a bit and found that the posts explaining how to do that involve more steps that is now necessary on Ubuntu 18. So here is what was sufficient on 3 separate VM's:

  1. Resize virtual disk in VirtualBox:
    1. Power down the VM
    2. Go to Virtual Media Manager (VMM)
    3. Select the disk that corresponds to your VM and resize the disk file (this is possible only on powered down VM)
    4. Start VM
  2. Resize partition in guest:

    1. Install gparted: sudo apt install gparted
    2. Start gparted
    3. Select partition
    4. Select resize
    5. Stretch it to desired size
    6. Check the details to confirm it did what you want
    7. Make OS see the entire partition using pvresize:

      $ sudo pvresize /dev/sda1
        Physical volume "/dev/sda1" changed
        1 physical volume(s) resized / 0 physical volume(s) not resized
      
  3. Resize the logical volume using lvresize:

    $ sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-root
      Size of logical volume ubuntu-vg/root changed from 29.03 GiB (7432 extents) to <48.85 GiB (12505 extents).
      Logical volume ubuntu-vg/root successfully resized.
    
  4. Resize the filesystem:

    $ sudo resize2fs /dev/mapper/ubuntu--vg-root
    $ df -h
    /dev/mapper/ubuntu--vg-root   48G   21G   26G  45% /
    

Two of the pages that helped a lot:

Top comments (3)

Collapse
 
clubside profile image
Chris Rowley

Howdy! I know this is an old post but I had to ask... I'm not a Linux guy but I have a VirtualBox Ubuntu for some WordPress development and needed to resize my disk that I stupidly set up with just 20GB. I found your post to be the clearest of those I looked at until...Step 7. After resizing with GParted and checking multiple utilities they already show the proper size. Are the other steps necessary If so how do I get my equivilents to "/dev/sda1" and "/dev/mapper/ubuntu--vg-root"? Or is that only something you do with an Ubuntu host?

Collapse
 
schollii profile image
schollii • Edited

Sorry Chris I never saw your comment until now. I gather you figured it out. I created an updated post with latest gparted, see my other comment.

Collapse
 
schollii profile image
schollii

I have created an updated post at devops.sentianse.com/notes/resizin.... Thanks to the newer gparted (1.0), everything (except the first part involving the virtualbox media manager of course) can be done in the gparted GUI.