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:
- Resize virtual disk in VirtualBox:
- Power down the VM
- Go to Virtual Media Manager (VMM)
- Select the disk that corresponds to your VM and resize the disk file (this is possible only on powered down VM)
- Start VM
-
Resize partition in guest:
- Install gparted:
sudo apt install gparted
- Start gparted
- Select partition
- Select resize
- Stretch it to desired size
- Check the details to confirm it did what you want
-
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
- Install gparted:
-
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.
-
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:
- [How to resize an Ubuntu 18.04 LVM disk][https://vander.host/knowledgebase/operating-systems/how-to-resize-an-ubuntu-18-04-lvm-disk/]
- [Ubuntu VM in VirtualBox: How to increase the size of a disk and make small(er) exports for distribution][https://technology.amis.nl/2017/01/30/ubuntu-vm-virtualbox-increase-size-disk-make-smaller-exports-distribution/]
Top comments (3)
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?
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.
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.