67

I'm running Ubuntu Desktop 14.04 as a VM on a mac with vmware fusion. I'm getting space warning issues and now want to expand from 20GB to 200GB.

I powered off the VM and on the vmware side increased the allocated disk space:

  1. Power off the VM
  2. VMWare Fusion -> Virtual Machine -> Settings -> Hard Disk (SCSI)

It then warned me that I should increase the partition size within the guest VM, which is unfortunate because I was hoping this would be automatic.

Looking at the disk usage analyzer inside of Ubuntu, it only currently sees the original 20 GB. How do I increase this to the 200 GB I allocated?

I'm looking for better direction than what is posted here.

From the Disks app, I see:

enter image description here

2
  • REsize option greyed out! ouch! this has helped though: gparted-forum.surf4.info/viewtopic.php?id=16987 as partitions were locked so I had to "deactivate them" first..
    – user171816
    Commented May 24, 2016 at 9:32
  • 1
    Right click the partition square in your Disks screen and select "Resize". I think the two overlapping ones (stacked in the UI) can both be extended, top one first. I'm using Ubuntu 20.04 and following these instructions help.ubuntu.com/stable/ubuntu-help/disk-resize.html.en. Commented Jun 15, 2020 at 1:58

5 Answers 5

51

You do not need a live CD for this to work. I'm basically summarizing the other answers given here:

  1. From Ubuntu (in VM) install gparted by executing sudo apt-get install gparted in terminal
  2. Open sudo gparted from terminal
  3. Rightclick on the swap partition, click "swapoff"
  4. Delete swap partition
  5. Extend your data partition, but leave enough space to create a new swap partition
  6. Recreate swap partition with about the same size as before, select linux-swap as file system
  7. Click that green tick in gparted to apply all operations. Then select "swapon" to enable swap again
6
  • 5
    This should be the selected answer. The selected answer doesn't mention that if there is a partition between your main filesystem and your free space, that you will have to remove it in order to extend your main fs, and then you'll have to recreate it after.
    – Nathan F.
    Commented Mar 28, 2018 at 16:44
  • @NathanFiscaletti Indeed, the selected answer doesn't mention anything about removing partition (if it is between main fs and free space) but it does mention about moving it :) Commented Mar 1, 2019 at 15:17
  • Actually, Ubuntu has been fine with Swap files for years, so I'd get rid of the swap partition, get rid of the extended partition, and then extend the first primary partition to fill the disk.
    – Auspex
    Commented Apr 26, 2019 at 14:14
  • @leosh How do you extend the data partition?
    – Nubcake
    Commented Dec 31, 2020 at 10:57
  • @Nubcake In gparted, rightclick the partition and choose Resize/Move.
    – leosh
    Commented Jan 4, 2021 at 7:07
44

From Ubuntu (in VM) Install gparted by executing sudo apt-get install gparted in Terminal.

Open gparted either from terminal or from dash. Then extend you disk, maybe you may have to move your extended partition at the end of disk.

8
  • 1
    But you can not modify a partition that's currently in use. And because it's a VM, booting from a USB stick isn't as straightforward. Can you provide any more details?
    – tarabyte
    Commented Apr 16, 2015 at 16:49
  • You can boot from iso image (live session) in VM and then modify the disks using gparted Commented Apr 17, 2015 at 2:51
  • 6
    Turns out you can modify a partition which is in use.
    – tarabyte
    Commented May 6, 2015 at 5:28
  • 1
    @tarabyte how? On my VM this doesn't seem possible
    – mitchus
    Commented Apr 3, 2020 at 8:36
  • also not possible to modify inuse partition in my vm
    – Garglesoap
    Commented Oct 6, 2020 at 1:13
18

You should first delete all partitions between your partition and free space. You can do it using parted command.

  1. Install parted if you don't have them using :

    sudo apt-get install cloud-guest-utils
    
  2. turn off swap. we gonna remove it's partition!

    sudo swapoff -a
    
  3. run sudo parted.
  4. get partitions list with print all:

    (parted) print all
    Model: Virtio Block Device (virtblk)
    Disk /dev/vda: 752GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End    Size    Type      File system     Flags
    1      1049kB  528GB  528GB   primary   ext4            boot
    2      528GB   537GB  8588MB  extended
    5      528GB   537GB  8588MB  logical   linux-swap(v1)
    
  5. remove none root partitions with rm (part-index):

    (parted) rm 5
    Warning: Partition /dev/vda5 is being used. Are you sure you want to continue?
    Yes/No? yes
    Error: Partition(s) 5 on /dev/vda have been written, but we have been unable to
    inform the kernel of the change, probably because it/they are in use.  As a
    result, the old partition(s) will remain in use.  You should reboot now before
    making further changes.
    Ignore/Cancel? C
    (parted) print all
    Model: Virtio Block Device (virtblk)
    Disk /dev/vda: 752GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End    Size    Type      File system  Flags
     1      1049kB  528GB  528GB   primary   ext4         boot
     2      528GB   537GB  8588MB  extended
    
    
    (parted) rm 2
    Error: Partition(s) 5 on /dev/vda have been written, but we have been unable to
    inform the kernel of the change, probably because it/they are in use.  As a
    result, the old partition(s) will remain in use.  You should reboot now before
    making further changes.
    Ignore/Cancel? C
    (parted) print all
    Model: Virtio Block Device (virtblk)
    Disk /dev/vda: 752GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End    Size   Type     File system  Flags
     1      1049kB  528GB  528GB  primary  ext4         boot
    

The commands works on ubuntu 16.04 (NONE LVM) and machine is running on a kvm:

sudo growpart /dev/vda 1
sudo resize2fs /dev/vda1   
5
  • 6
    growpart and resize2fs are e.g. available via sudo apt-get install cloud-guest-utils Commented Jun 20, 2018 at 14:21
  • 1
    cloud-guest-utils (and thus growpart) is also available on Ubuntu 14.04.
    – jmidgren
    Commented Sep 27, 2018 at 8:01
  • 1
    Much better. Who's putting desktop OS's on VMs? [I know, I know; I have a bunch, too, but for the most part they should be headless]
    – Auspex
    Commented Apr 26, 2019 at 14:15
  • 2
    Works for Ubuntu server!
    – Ender
    Commented Apr 29, 2020 at 10:10
  • 1
    You can also manually using fdisk deleting the primary partition and recreate a new one with the full size. Doing so avoids the need to install cloud-gest-utils / growpart. As resze2fs already come installed on my ubuntu server. Do it with caution though!
    – some user
    Commented Oct 7, 2021 at 17:39
16
  1. Download gparted LIVECD iso from here
  2. From your VM Choose the iso file and boot as live CD

    • Add the iso into your cd-rom drive from the GuestVM settings

    or

    • Set to boot from the CDROM in BIOS (F2 when you start your VM)
  3. Once tha gparted Live Cd runs you can use gparted now
  4. Choose the partition to resize and choose the new size and then apply
  5. When end reboot and be sure to remove the iso file attached to the VM CD ROM, and boot to your Ubuntu.

enter image description here

5
  • Can you elaborate more on step 2? Choose from what? Right-click?
    – tarabyte
    Commented Apr 20, 2015 at 3:05
  • @tarabyte Choose the Gparted IO Live CD to boot from in your Virtual machine....
    – Maythux
    Commented Apr 20, 2015 at 7:32
  • So download Gparted IO Live CD on the Host OS, and NOT the guest OS (Ubuntu)?
    – tarabyte
    Commented Apr 20, 2015 at 21:13
  • Download wherever you want but use it in the CD ROM of your VM which means the guest
    – Maythux
    Commented Apr 21, 2015 at 5:17
  • In case there is a swap partition in between: askubuntu.com/a/120381/126822
    – rlcabral
    Commented Nov 19, 2016 at 19:30
-1

Extending a filesystem partition, from within the same operating system, may not be advisable, as its processes / services might still be writing into them. Also, gparted shows certain partitions as locked ( i.e. mounted ) and may not be able to un-mount them.

A Live CD comes in handy, in such situations.

Just use the Live CD from this Open Source Project, on Hosts / Guests ( this Live CD has the gparted program built in, in its Applications Menu, along with many other goodies like File Manager, Disk Mounter, Installer, Internet Browser etc.; also read the instructions on the site ) :

https://sourceforge.net/projects/live-cd-with-zerofree-utility/

P.S. A 32-Bit Version ( i686 architecture ) of this Live CD is available at: https://sourceforge.net/projects/live-cd-with-zerofree-32-bit/

For very OLD Architectures, Please try this Live CD : https://sourceforge.net/projects/live-cd-with-zerofree-x86/

Hope this helps all.

1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Petr
    Commented Sep 15, 2023 at 14:42

This site is temporarily in read-only mode and not accepting new answers.

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