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 … π
very helpful thanks
Thank you! Β Helpful.
your welcome….no real step by step post on this had bothered me for a while!
thanks! it was helpful!
no problem, glad it helped
Just awesome, thanks a lotttt
No problem. Glad it helped!
great..
Thanks. Very helpful.
I just wanted to add you can safely ignore the warnings from gparted related to moving the extended and swap space.
Thanks for the info. Much appreciated
This worked flawlessly. Thanks a ton for posting such clear, detailed instructions.
Thank you very much!! Exactly what I was looking for!
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.
Worked gracefully!
Thanks
All detailed steps worked great!!
Very helpful, thanks!
Best Explaination .. Thank you . It helped me to partition a machine with Crucial data
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
Dude, I love you!!!!
Hmmmmmmmmm
awesome thank you!
Np. Glad it was useful
Awesome article . I salute you.
Thanks,
Arun
Sri lanka
Thx
Exactly what I was looking for! Great explanation! Thank you! π
Your welcome. Comments like that make everything worthwhile
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?
figured it out. gparted must be followed by lvresize -l +100%FREE , followed by resize2fs
ignore the automatic xml expansion in my last post. arrgh.
:_)
Thanks a lot.
This is awesome! Thank you!
No problem. Glad it helped
Thanks! This helped me resize my Linux VM!
Glad it helped!
Thank you very much! Excellent tutorial for doing that kind of rocket science!
Thank you for this excellent and flawless explanation. You saved my day!
This was the right way to do it! Thanks!!!
no problem – thanks for visiting
Many Thanks, just the job
Awesome tutorial! Exactly what I needed to know.
Bonus points for making it simple and easy to understand!
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…
Thanks, I always forget to add the unallocated space to the extended partition first!
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
OMG THANK YOU SO MUCH!!!! <3
I treid everything, this is finaly something that works π
your welcome!
Thanks so much for this. Been looking for it for a few days!
no problem – glad it helped!
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…
Thanks more than I can say. The steps helped me out ALOT.
Thanks!
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!
Many thanks!
great tutorial. I had the exat same partition names as you. What I did end up with 2MB before and 1MB after the swap partition. Yes, I am sure I properly dragged until 0MB in the guide.
Anyways not a biggie, but why was that? If I expand to the left, I will get 3MB on the right, and vice versa.
Fantastic, just what I needed and found this by googling for “ubuntu can’t resize partition as swap is in the way” which I wasn’t expecting to find much π
Thanks a lot, mwpreston! Your tutorial worked OK; sorry, my English is limited, but my thanks are infinite… have a nice day! π