Expanding a Linux disk with gparted (and getting swap out of the way)

Over the past year or so there have been a few times where I've need to expand a disk attached to a Debian system.  Now this isn't a hard task by any means, and may not even warrant a blog post, but the matter of it is that I always seem to forget the steps I need to take to get that unallocated space that I've added next to my actual EXT3 partition since the swap partition is always in the way!  So, I thought I would just throw up how I've done it in the past in hopes to maybe help a few others that visit, but more-so for myself and my memory (or lack there of).  Now keep in mind I'm sure there are ways to perform this exact same thing without taking the VM online, or I'm sure there are other 'better' ways to achieve the same results, but this way has worked for me consistently so it's what I chose to do.  Any other suggestions are certainly welcome in the comment box below.

First off, you will need to expand your drive from within the vSphere Client, not rocket science here, pretty simple to do.  Next, get yourself a copy of gparted and mount the ISO to your VM and reboot booting into the gparted interface (accept all defaults for keymap, X, and resolutions, unless of course you like playing…).  So the first thing you will notice inside gparted is that the swap partition is right smack in the middle of your EXT3 partition and the unallocated space. Normally, you could just resize the EXT3 partition and consume the unallocated space, but with swap there you can't.  

So, the goal is to migrate the unallocated space to precede the swap partition.  This is done so using the following procedure..

First, resize your extended partition (not the one labeled linux-swap) to include the free space.  In my case this is done by selecting /dev/sda2 and then selecting the Resize/Move button.  In the popup, simply drag the arrow on the right side of the bar to include all of the free space available and again select Resize/Move.  

Just to note, we are not actually performing and moves or resizes at this point, we are simply just creating a chain of commands that gparted will follow once it is applied.  You can either apply at the end of each step, or wait till the bitter end and do it, its up to you.  Either way when you are done, you should see your unallocated space move into /dev/sda2 as shown below.

So, as you can see from the screen capture, the next thing we need to do is move that swap partition to the end of /dev/sda2.  This will allow us to proceed with the next few steps that we need to perform in order to accomplish our end goal of expanding /dev/sda1.  This time we will need to select the linux-swap partition (/dev/sda5) and select Resize/Move.  Inside the popup, this time click the actual white space inside the partition and drag the complete box over to the right (don't use the arrows).  This will move the swap partition to the end of /dev/sda2 for us which we will next resize.  Once your looking like the below images, again, click 'Resize/Move'.

Alright, now we are getting somewhere, you should be looking pretty similar to the shot below by now.  And yes you guessed it, now we need to move that unallocated space right outside of /dev/sda2 in order to make it available for the expansion of /dev/sda1.

So, once again select /dev/sda2 and select 'Resize/Move'.  This time we will use the arrows.  What we want is to move the left arrow this time to the right all the way over to edge of the yellow box (swap).  This will resize the complete /dev/sda2 to the same size as the swap it contains (/dev/sda5) and in turn, create that unallocated space in between the partitions.  Once done, click 'Resize/Move'.

Alright, almost there, you should be somewhat similar to the screenshot below.  Our unallocated space is now directly next to our EXT3 partition and no long a member of /dev/sda2.

At this point I usually apply the first three operations before the expansion.  I've noticed sometimes the process will error out if trying to do the following steps without applying first, so go ahead and apply those operations (Hit 'Apply')

So we are now able to simply extend /dev/sda1 into that unallocated space.  Similar to when we extended /dev/sda2, this time select /dev/sda1, click 'Resize/Move'.  In the popup as we did earlier, select the arrow at the right side of the partition, and drag it to the right to merge sda1 with the unallocated space, when done, select 'Resize/Move'.

So, there you have it!  We have moved that unallocated space into our EXT3 partition.  Go ahead and hit apply again to commit that final change and at the end of the process you should have a larger /dev/sda1.

Now, like I said at the beginning, I'm sure there are ways to do this while the VM is online, or I could be doing things completely wrong, but this way has consistently worked for me for both Linux and Windows guests.  That being said, I'm open to other suggestions, leave them your comments, concerns, thoughts, etc below in the comments … 🙂

  • Azeem151

    very helpful thanks

  • Foo

    Thank you!  Helpful.

    • mwpreston

      your welcome….no real step by step post on this had bothered me for a while!

  • Axl

    thanks! it was helpful!

    • mwpreston

      no problem, glad it helped

  • Jux

    Just awesome, thanks a lotttt

    • mwpreston

      No problem. Glad it helped!

  • great..

  • Chuck Martin

    Thanks. Very helpful.

    I just wanted to add you can safely ignore the warnings from gparted related to moving the extended and swap space.

    • mwpreston

      Thanks for the info. Much appreciated

  • Nissl

    This worked flawlessly. Thanks a ton for posting such clear, detailed instructions.

  • bDIS

    Thank you very much!! Exactly what I was looking for!

  • Jesus del Valle

    As everyone said: THANK YOU!

  • Thanks! Well written, very helpful. The only thing that made me nervous was the warning message from GParted, but Chuck mentioned we can ignore it. Maybe add that small bit into the article.

  • pclacerda

    Worked gracefully!

  • RDX

    All detailed steps worked great!!

  • Jonathan Engelsma

    Very helpful, thanks!

  • Best Explaination .. Thank you . It helped me to partition a machine with Crucial data

  • Rob

    You just saved me a TON of time and heartache. One note for my case: when booting from an Ubuntu ISO image rather than a gparted-specific image, my extended & linux-swap partitions were locked. I had to right-click linux-swap and select “Unswap” from the menu. Then worked like a charm. Thanks!!

    • Thanks for the tip and glad it helped

  • uhru

    Dude, I love you!!!!

  • SleepyInSeattle

    awesome thank you!

  • Arun Coder

    Awesome article . I salute you.



    Sri lanka

  • disqus_NdAdHRPkZA

    Exactly what I was looking for! Great explanation! Thank you! 🙂

    • Your welcome. Comments like that make everything worthwhile

  • Mike

    gparted reported success when I expanded a partition on my fedora 17 box (running under vmware on a win7-64 machine). However, df still reports the smaller size, as does the graphical disk usage analyzer utility. Is there a final step I need to perform?

  • Mike

    figured it out. gparted must be followed by lvresize -l +100%FREE , followed by resize2fs

  • Mike

    ignore the automatic xml expansion in my last post. arrgh.

    • mwpreston


  • mazikwyry

    Thanks a lot.

  • Pingback: Resizing VirtualBox VHD | bradford's blog()

  • Juan Cortez

    This is awesome! Thank you!

  • Pingback: Fixing the “No space left on disk error” – Ubuntu | T3CH PAG3()

  • thebestarticles

    Thanks! This helped me resize my Linux VM!

  • Taavi

    Thank you very much! Excellent tutorial for doing that kind of rocket science!

  • Edh

    Thank you for this excellent and flawless explanation. You saved my day!

  • Giovanni

    This was the right way to do it! Thanks!!!

    • mwpreston

      no problem – thanks for visiting

  • Ross

    Many Thanks, just the job

  • demon5

    Awesome tutorial! Exactly what I needed to know.
    Bonus points for making it simple and easy to understand!

  • Peter H.

    nice tutorial! It might be worth to mention that the swap space sometimes needs to be turned off in GParted (“Swappoff”) before it can be moved, if it is used by some live CD image or so…

  • Eric Der Pfähler

    Thanks, I always forget to add the unallocated space to the extended partition first!

    • mwpreston

      honestly I forget this stuff all the time – that’s why I blog about it – I’ve went back to this post so many times

  • Casper


    I treid everything, this is finaly something that works 😀

    • mwpreston

      your welcome!

  • buckdossey

    Thanks so much for this. Been looking for it for a few days!

    • mwpreston

      no problem – glad it helped!

  • Pingback: Linux Dashboard – Kodi's Blog()

  • Tigran Avetyan

    working fine.did not lose any data.nice toturials.also will be better input some tags for user that search how to extend(encrease) ext2,3,4 partition on their Android phone sd cards,when found 2nd partition previously greated was not enough…

  • Andrew Davis

    Thanks more than I can say. The steps helped me out ALOT.

  • world

    I have this to do in my VMware with Linux and now all is gut!! , I had before any Time to fight about space , Now i have many space to work , very thanks!

  • Matija Ponikvar

    Many thanks!