Monday, April 22, 2013

Increase the size of the disk partition(s) of the required drive of the virtual machine using GParted

In my previous post, I described how to expand the virtual disk size in VMWare Workstation 7. But that is not enough for you to increase the usable disk size of your virtual machine. The size of the disk partition wont increase as observed inside the guest operating system. You must follow steps related to your specific operating system to increase the size of the disk partition or partitions. 

I recommend you that always before you meddle with your disks, partitions, memory related activities, please have a backup of your virtual machine. What I mean here as a 'backup' is a Full Clone of your virtual machine. I don't recommend having just a copy of your virtual machine folder in some other location in your computer.

Now, the problem we have in our hand is that how to add the expanded disk size to the partitions of our vmware to work with it. The tool that I have used here is GParted. Though it took some time for me to understand the concepts behind it and how it works, finally I was in the correct track. 

First of all, I would like to recommend some reference materials that I used to learn about GParted. I think they'll be help for you too. 

You'll definitely need to use the GParted website to find out the correct version of this tool which supports to the platform that you work with. here is the link for that


If you would like to watch a video to have a quick understanding of what we are supposed to do with Gparted and how it works, you can watch these two videos as reference. They helped me to learn the tool for a certain extent.
Following one shows how it works in Ubuntu platform


The video shown below is also taken from YouTube but little unclear to understand without speech demonstration. Actually It solved half of the unclear points that I had about using GParted.




Anyways, I'll explain what the tool is and how to use it as far as I learned about it. Since I too learned about Gparted and its usage as a self learner, I think I can give some help for a beginner to work with it. That is the main intention of these series of posts about virtual machines and their disk space management.

What is GParted?



GParted is a free partition editor for graphically managing your disk partitions.With GParted you can resize, copy, and move partitions without data loss, enabling you to:

  • Grow or shrink your drives
  • Create space for new operating systems
  • Attempt data rescue from lost partitions

What are the Requirements to use GParted in your machines?


GParted can be used on x86 and x86-64 based computers running Linux, Windows, or Mac OS X by booting from media containing GParted Live. A minimum of 128 MB of RAM is needed to use all of the features of the GParted application.


Installation

Though I have titled it as Installation, there should not be an installation for GParted. This is the point where I got confused and spend lot of time to search what went wrong and why. 

Actually, Gparted is a disk partitioning tool and it should not be installed and used from a disk what we are trying to partition. I did this mistake by installing GParted in my fedora 14 virtual machine using yum and tried to partition by disk. I observed from the Gparted GUI that all my disk partitions were marked with a key icon (which means, the drives are busy) and under that state, it wont allow you to resize your partitions. That's quite obvious. 

Then how should it be run? Actually I tried out three ways to run Gparted to re size partitions of my Virtual machine.

  • create a bootable USB flash drive with GParted Live
  • create a bootable CD/ DVD with GParted Live
  • Simply browse the ios image of Gparted Live in VMWare CD/DVD option 

Download GParted Live 


To install GParted Live on CD, download the .iso file and burn it as an image to a CD. I downloaded gparted-live-0.14.1-6-i486.iso which is about 133MB and burnt in to a CD. If you don't know how to make a bootable CD you can google it. If you have Windows 7 in your machine and feeling lazy to google for it, then follow the link below :) . It's simple and easy


of course you also can make a bootable USB flash drive using some tool like Universal-USB-Installer within few seconds with the same iso image that I downloaded above. Yoou can get it from here,


I had problems in setting my USB flash drive as the first in System BIOS boot sequence. So ultimately, I had to go for the CD option. You can select which ever the way you want. 

The point that you should take to your consideration here is, you have to run GParted on top of your OS. not running within it. All what we need to do is, boot your OS from some bootable device  with GParted and observe the currently available partitions you have in a GUI. Then you can select  a partition at a time and expand, shrink, move or what ever the option that is available for you in an easier manner. 

So, that's the simple magic behind GParted partitioning tool. But always keep in your mind that the tasks that you perform via GParted is so critical. If you used it without care, even your OS may crash. Believe my words because I already experienced such scenarios many times when experimenting with the tool :). Luckily, I always had backups of my virtual machine in both my desktop computer and laptop (because I'm dead scared of loosing all my efforts in a flash :p ). 

But before starting the partitioning task, let me explain what my problem is. 

Currently I am running a Fedora 14- 64 bit virtual machine in VMWare Workstation 7.1.4. I have oracle 11g installed in it and as I work with many databases within my fedora OS, the size of the disk expanding very fast. I was in a great trouble from the moment my OS prompted a warning saying my home directory is almost full. I could verify it as below. 













note that /dev/sda5 is almost 90% in the above scenario. What I wanted to do is to allocate some more space at least for that partition. Before doing that, I performed some other tasks like Performing a disk defragmentation, Compacting the virtual hard disk, expanding the size of the virtual hard disk . You can refer them if you too want to know how I did those tasks but for the re sizing of the disk partition  you just have to know how you can add some space to your virtual hard disk in VMWare. you can refer only that post if you are interested.

I believe, now you are ready with the bootable CD of GParted. Our first task is to let VMWare workstation know that we are required to boot from that CD if it is available. to do so, follow the below steps.

1.  power off your virtual machine if it is already running
2.  make sure that you are in the correct tab of your virtual machine that you are going to perform the disk partitioning



3. select VM-->settings-->CD/DVD(IDE) under Hardware tab-->select Auto Detect under Use physical drive option






















4. Make sure you have the GParted bootable CD inserted in to your CD/DVD Drive

How to change boot sequence of your virtual machine in VMWare Workstation?

1. follow the above four steps
2. Select VM-->Power-->Power On to BIOS






















3.Once you see the BIOS screen as below just click inside the screen using the mouse and there onward you have to use only the keys.


4. Use Right arrow key and select Boot tab




























5. Use up and down arrow keys to select CD-ROM Drive and click + key from the keyboard to move it up. Place in as the first in the boot sequence as shown below


6. Press F10 to save the changes. select Yes and hit Enter























How to boot the virtual machine from GParted Live CD?

1. Follow the above steps to reorder the boot sequence from the BIOS settings of your virtual machine. If you have set the CD-ROM as the first one in the list.

2. Power on your virtual machine and it will boot up in GParted as shown below























3. Select GParted Live (Default Settings) and hit Enter key























4.Select Don't touch keymap and hit Enter key



5.type 02 as the Language option and hit Enter key



6.Enter 0 as the preferd mode and hit Enter key



7.You should end up with a screen as shown below



8.wait until it auto detects the disk partitions and displays in GParted GUI





9.you can observe the partitions in different colors. Used space in yellow, unused space in white, unallocated space in grey and so on

10. select the partition that you want to re-size from the below list




11. Right click on it and select Resize/Move



12. You can either use the increment arrows to set a specific value for the parttion or just drag it to the prefered location towards the unallocated space as shown below





13. Click Resize/Move

14. note that your action has added in the bottom of the list with a green icon.It says, you have a set of action planned so far. But until you apply them, the changes won't be done. So, click on the Apply button (you can see it with a green correct mark labeled as Apply) to apply the changes



15. If the task is completed, you will see a success screen as below. click Close button to close the window (It's not mandatory to save the details in a file)



16. You should observe the applied changes as shown below




17. You can perform any task with a selected partition  but make sure that anytime any action can cause your data in the virtual machine to be corrupted. Make sure your are working with a virtual machine that has a backup already

once you have done with the resizing in GParted, you can select GParted-->Quit option to quit from the GParted GUI and then click on the Exit button on the GParted Desktop to exit. When it asks the shutting down options, select shutdown. Then it'll automatically shutdown your virtual machine meanwhile ejecting your GParted Live CD from the CD/DVD drive.

You  can power on your virtual machine , open  a new terminal and type df -h  to check whether the disk partitions are re sized as you applied.

Note: I could repartiiton my home directory's partition successfully in this way. It is not that difficult because whenever you add space to your virtual disk, the unallocated space positions just after the /dev/sda5 partition  where it's easy for you to add the unallocated space to /dev/sda5. but think that you want to add more space to your root partition  It's not that easy, right. You have to move the unallocated space just beside the root partition and add to it.

As far as I tried, that was a bit tedious task because moving partitions can end up with data loss. Moving partitions take more time and while you are waiting, the process may stop and the partition may become inconsistent.

I am not discouraging you not to use those features but be really careful with the actions that you are performing when repartitioning. you don't need to worry if your partitions doesn't contain any data but if it has sensitive data, they have to be handled with more care.

OK, that is the end of this long post :) Hope it was helpful and please leave a comment if  you have any suggestions about my posts.