How to extend the Ubuntu guest OS’s hard disk for VirtualBox on Mac
Steps:
resize the VDI file on Mac OS: How to Resize a VirtualBox VDI or VHD File on Mac OS X
boot the Ubuntu with the image(ISO) and Gparted(resize the partition).
Note: firstly resize the extension partition (/dev/sda2), then resize the partition (/dev/sda5)
reboot the ubuntu with local vdi file and check the result.
references:
How to Resize a VirtualBox VDI or VHD File on Mac OS X
How to Partition, Format, and Mount a Disk on Ubuntu 20.04 Using Command Line