I have Ubuntu installed on a drive. The problem is it is running low on disk space. This is installed on vmware. I expanded the virtual drive and booted into ubuntu. But when I opened gparted(sudo gparted), the move/resize option is unavailable. This is the partition Ubuntu is installed on, but I need to resize it. Any ideas? I am comfortable using command line

  • You can see how they do it in raspi-config for the Raspberry Pi, where expanding the root file system is something you do almost every time you set up a new Raspberry Pi. github.com/RPi-Distro/raspi-config/blob/… – sshow Jan 25 '18 at 13:08

You are almost there.
You can not resize the partition using GParted while Ubuntu is running.
You will need to attach the GParted ISO's as a CD to the VM machine and reboot the machine so that the GParted will be loaded instead of Ubuntu (I think you can boot from the virtual CD by pressing F12 immediately after machine is started).
Once you booted into GParted the option to move/resize will be enabled as Ubuntu is not currently running.


As a matter of fact, you CAN enlarge the root filesystem while Ubuntu is running (I learned this recently myself here) - this sounds incredible but it's true :)

Here's the list of steps for a simple scenario where you have two partitions, /dev/sda1 is an ext4 partition the OS is booted from and /dev/sdb2 is swap. For this exercise we want to remove the swap partition an extend /dev/sda1 to the whole disk.

  1. As always, make sure you have a backup of your data - since we're going to modify the partition table there's a chance to lose all your data if you make a typo, for example.

  2. Run sudo fdisk /dev/sda

    • use p to list the partitions. Make note of the start cylinder of /dev/sda1
    • use d to delete first the swap partition (2) and then the /dev/sda1 partition. This is very scary but is actually harmless as the data is not written to the disk until you write the changes to the disk.
    • use n to create a new primary partition. Make sure its start cylinder is exactly the same as the old /dev/sda1 used to have. For the end cylinder agree with the default choice, which is to make the partition to span the whole disk.
    • use a to toggle the bootable flag on the new /dev/sda1
    • review your changes, make a deep breath and use w to write the new partition table to disk. You'll get a message telling that the kernel couldn't re-read the partition table because the device is busy, but that's ok.
  3. Reboot with sudo reboot. When the system boots, you'll have a smaller filesystem living inside a larger partition.

  4. The next magic command is resize2fs. Run sudo resize2fs /dev/sda1 - this form will default to making the filesystem to take all available space on the partition.

That's it, we've just resized a partition on which Ubuntu is installed, without booting from an external drive.

  • @EliahKagan: Please have a look at the answer (from Gilles) I linked to. The idea is that it is possible to use fdisk to enlarge the partition, while the OS continues to use the smaller filesystem. Then. after a reboot, after kernel re-reads the updated partition table, we can resize the filesystem because it now lives in a larger partition. – Sergey Mar 15 '14 at 21:47
  • @EliahKagan: ok, you're right, I need to try it myself :) Let's see if I have a spare HDD to play with... – Sergey Mar 16 '14 at 11:30
  • 1
    @Isaac: Yes, we still have to reboot to make the kernel to re-read the partition table. However, a quick reboot in many scenarios is a much smaller problem than booting from an external medium (think of remote machines, headless machines, VPSes etc.) – Sergey Apr 20 '15 at 5:15
  • 2
    Two quick notes: 1. You can use df to show the "resulting" space after this (confirm that it worked), and 2. remember to recreate some swap space! – Christian Rondeau May 23 '17 at 18:48
  • 1
    Thanks so much. Ubuntu never used the space I gave the VirtualBox vdisk. Now I know why. Many thanks! – penderi Jun 19 '17 at 9:47

After extending the volume in vmWare ESXi (shutdown vm, backup/export vm, remove all snapshots, then increased number in disk size, take snapshot of vm again before following the next steps so you can revert mistake/error).

The following example is extending volume on root partition on a system that is already using LVM.

  1. SSH to the system, switch to root and run cfdisk
    # cfdisk

  2. enter image description here

  3. enter image description here

  4. enter image description here

  5. enter image description here

  6. enter image description here

  7. enter image description here

  8. enter image description here

  9. enter image description here

  10. enter image description here

  11. enter image description here

  12. enter image description here

  13. After exiting cfdisk

     # fdisk -l /dev/sda 
     Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
     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: 0xc8b647ff
     Device     Boot    Start      End  Sectors  Size Id Type
     /dev/sda1  *        2048   999423   997376  487M 83 Linux
     /dev/sda2        1001470 16775167 15773698  7.5G  5 Extended
     /dev/sda3       16775168 41943039 25167872   12G 8e Linux LVM (***** See new partition /dev/sda3*****)
     /dev/sda5        1001472 16775167 15773696  7.5G 8e Linux LVM
  14. Reboot system before next step (or else you might get Device /dev/sda3 not found (or ignored by filtering))

     # shutdown now -r
  15. Initialize the new volume

     # pvcreate /dev/sda3
       Physical volume "/dev/sda3" successfully created
  16. Get the name of volume to extend

     # vgdisplay
       --- Volume group ---
       VG Name               linuxetc1-vg (***** this is vg i'm extending*****)
       System ID             
       Format                lvm2
       Metadata Areas        1
       Metadata Sequence No  3
       VG Access             read/write
       VG Status             resizable
       MAX LV                0
       Cur LV                2
       Open LV               2
       Max PV                0
       Cur PV                1
       Act PV                1
       VG Size               7.52 GiB
       PE Size               4.00 MiB
       Total PE              1925
       Alloc PE / Size       1925 / 7.52 GiB
       Free  PE / Size       0 / 0  
  17. Extend volume group

     # vgextend linuxetc1-vg /dev/sda3
       Volume group "linuxetc1-vg" successfully extended
  18. Extend root

     # lvextend -l+100%FREE /dev/linuxetc1-vg/root
       Size of logical volume linuxetc1-vg/root changed from 6.52 GiB (1669 extents) to 18.52 GiB (4741 extents).
       Logical volume root successfully resized.
     Or if you only wanted to give 5 more GB to root
     # lvextend -L +5g /dev/linuxetc1-vg/root
  19. Get filesystem name for next step

     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root  6.3G  2.5G  3.5G  42% /            (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000
  20. Extend filesystem

     # resize2fs /dev/mapper/linuxetc1--vg-root
     resize2fs 1.42.13 (17-May-2015)
     Filesystem at /dev/mapper/linuxetc1--vg-root is mounted on /; on-line resizing required
     old_desc_blocks = 1, new_desc_blocks = 2
     The filesystem on /dev/mapper/linuxetc1--vg-root is now 4854784 (4k) blocks long.
  21. See the increased size

     # df -h
     Filesystem                      Size  Used Avail Use% Mounted on
     udev                            477M     0  477M   0% /dev
     tmpfs                           100M  4.6M   95M   5% /run
     /dev/mapper/linuxetc1--vg-root   19G  2.5G   15G  15% /         (***** this line*****)
     tmpfs                           497M     0  497M   0% /dev/shm
     tmpfs                           5.0M     0  5.0M   0% /run/lock
     tmpfs                           497M     0  497M   0% /sys/fs/cgroup
     /dev/sda1                       472M  105M  343M  24% /boot
     tmpfs                           100M     0  100M   0% /run/user/1000


  • Wow. This was extremely helpful. Wish I could upvote more than once. Thanks! – Mario Tacke Feb 1 at 6:07
  • Worked perfectly on 18.10 running under ESXi. Thanks! – John Vinopal Feb 24 at 2:34
  • Absolutely fabulous, Just what I needed as a linux noob. . – bigbadmouse Mar 8 at 10:16

I succeeded in enlarging my primary ext4 partiion using the methodology described here.

Some notes from my personal experience:

  • The link example is for shrinking partition, hence the order is resize2fs first and then fdisk. When enlarging partition (as in my case) the order should be fdisk first, reboot and then resize2fs. Also, when using fdisk, the primary as well as the extended partitions should be removed and re-defined.
  • I booted the ubonto from another drive and then worked on this drive which actually was mirror (using dd) of the older drive. Made it bootable using GParted
  • The current version of resize2fs (I am using ubontu 12.04LTS) support ext4 - no need to do the actions described in the link of changing it the ext2.
  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Braiam Aug 12 '13 at 5:11

The answer from Sergey was excellent. If you have the empty space not directly in the next device, however, you will need to delete other devices. For example:

Device     Boot    Start       End  Sectors Size Id Type
/dev/sda1  *        2048  33556477 33554430  16G 83 Linux
/dev/sda2       33556478  41940991  8384514   4G  5 Extended
/dev/sda3       41940992 125829119 83888128  40G 83 Linux
/dev/sda5       33556480  41940991  8384512   4G 82 Linux swap / Solaris

In the above case, if you want to merge /dev/sda3 with /dev/sda1, you would need to remove /dev/sda1, /dev/sda2, and /dev/sda3 (with d command), and re-add /dev/sda2 and update its type (with n and t commands).

protected by Community Feb 27 '15 at 18:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.