3

I have a Ubuntu virtual machine on VirtualBox on a Windows host operating system. I want to increase the available disk space on the virtual machine.

I tried following this guide but I can't make the final resizing of the partition.

I first increased the disk space of the virtual machine from 20 GB to 40 GB.

img

I then ran the command on the command prompt.

enter image description here

Then I added a bootable iso image of GParted on the virtual optical disk and booted into GParted. From GParted I can see the unused disk space on the right of my partition, but when I try to resize the partition I do not have the option to increase it, I can only shrink it.

enter image description here

Does anybody know what i am doing wrong?

4 Answers 4

3

Your sda5 is inside the sda2 extended partition container. This is a necessary artifact of MBR partition tables when you might want to have more than four partitions.

  1. Extend sda2 (the "extended" partition)
  2. Extend sda5 (the ext4 partition)
  3. Extend the filesystem on sda5 (resize2fs /dev/sda5)
3

I had a similar issue for:

  • Host macOS
  • Guest Ubuntu Desktop 22.04

The procedure for other Host with Windows 10 and with the same Guest was:

  • expand first the extended partition
  • expand second the ext4 partition

It because the former contains the latter.

But in this situation - with a slight variation - I got an error message indicating that the ext4 partition is read-only (btw the extended partition was resized in peace)

It seems according with this post:

Because the ext4 partition contains \ and it is mounted therefore is not possible accomplish the resize goal - but as I indicated: in the other Host with the same guest the procedure was accomplished successfully - even when the ext4 partition contains \ and it is mounted too.

Well the other post is not related with VirtualBox, but the solution is correct:

  • Boot a GParted Live CD/USB.

Therefore for our case working with VirtualBox

Solution

  • Shutdown your VM
  • Download the GParted .iso file from its homepage.
  • Select your VM
  • Open Settings
  • Select Storage
  • At Controller IDE the CD must be empty.
  • Select empty, and in the right, at Attributes do click in the cd icon
  • Through the Choose a disk file item proceed to select the downloaded GParted .iso file.
  • Check the Live CD/DVD checkbox
  • Press OK button
  • Start the VM

Now GParted is loaded and the ext4 partition can be resized to fit with the same size of the extended partition. It worked in my side.

Once accomplished all the process, is straightforward remove the GParted .iso file.

2
  • 1
    I followed instructions above on a Windows guest, with an Oracle VirtualBox machine hosting a LightUbuntu system, and I solved my issue of having low disk space for the device holding the root files system. Thank you.
    – luisa rosi
    Jan 10 at 13:12
  • @luisarosi you're welcome :) Jan 11 at 21:07
0

Sorry, I just saw your question now, and I will try my best to help you.

You know,

Principle-A: Size(vm_disk) == Size(primary/main partition) + Size(extended partition);

Principle-B: Size(extended partition) == All of the Size(logical partition);

Principle-C: Size(logical partiton) <= Size(extended parition);

As your GParted show, the primary/main partition is /dev/sda1; the extended partition is /dev/sda2; and logical partition is /dev/sda5.

If you want to expand logical partition/dev/sda5, firstly, you should expand extended parition /dev/sda2 because priciple-C, and if you just use sudo cfdisk -l to check the usage of all your partition on yout VM's terminal, I guess your VM's terminal show below:

Disk /dev/sda: 40 GiB, 42212254720 bytes, 82914560 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x50c8fe86

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *           1     512M  1102880  512M  c W95 FAT32 (LBA)
/dev/sda2           512M      20G 39902880 19.5G  5 Extended
/dev/sda5           512M      20G 39902880 19.5G 82 Linux swap / Solaris
free space           20G      40G 41162880   20G  

Also, I guess you want to get below output via sudo cfdisk after you expand the logical partition /dev/sda5:

Disk /dev/sda: 40 GiB, 42212254720 bytes, 82914560 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x50c8fe86

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *           1     512M  1102880  512M  c W95 FAT32 (LBA)
/dev/sda2           512M      40G 81066760 39.5G  5 Extended
/dev/sda5           512M      40G 81066760 39.5G 82 Linux swap / Solaris

So the solution is clear. I do highly recommend you use cfdisk instead of ISO APPGParted. Also, just use cfdisk for an example.

Solution:

1.please log in your VM via terminal;

2.use sudo cfdisk to enter the permission of cfdisk;

Just use up and down direction button to choose the target partition, use right and left direction button to choose the cfdisk operation, use enter button to make sure.

3.use the Resize button of cfdisk to expand the extended partition /dev/sda2, clean the default disk size and input 39.5GB, then ok;

4.use the Resize button of cfdisk to expand the logical partition /dev/sda5, also, clean the default disk size and input 39.5GB, then ok;

5.use the Write button of cfdisk to write the operation to the Disk, then use Quit button to quit cfdisk;

6.Set all of the expanded logical partition /dev/sda5 into ext4 via sudo resize2fs /dev/sda5;

7.Restart or reboot your virtual machine: sudo reboot.

Have fun!!!

OVER!

0

You need to resize the top level (empty top level) first sda2 extented, then resize again your partition containing data.

1
  • Please note that your answer seems to reiterate what was already stated in the @roaima's answer. You may want to consider expanding it so that the difference to that answer becomes more visible; otherwise it would be best placed as a comment to that answer (once you have sufficient reputation).
    – AdminBee
    Mar 27, 2023 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .