Yesterday, I decided that my CentOS VM has become just too tight for my needs and I urgently need to expand it to be able to perform some benchmarks with Sybase IQ and Oracle. Using these simple steps I have added 40 GB to the root filesystem in less than 30 minutes, including reboots of my laptop etc. You don't have to be an experienced Linux sysadmin to accomplish the task, I'm surely don't :).
Of course, expanding of a filesystem this way is not my own invention, I have compiled this list from a number of posts over the Internet. I just hope that putting all steps together will be useful for someone and will save a lot of time of research and peeking the right suggestions from different places.
So, here are the steps I did:
1. Normally, I run my Linux VM on Windows using VMware Player, which, thanks to VMware, is available for free. Unfortunately, VMware Player cannot add disks to VMs. Unfortunately, VMware Player cannot co-exist with other VMware products, such as VMware Server or VMware Workstation on the same PC, and I was forced to uninstall it.
2. Both VMware Server and VMware Workstation are capable of adding of a new hardware, including virtual disks, to existing VMs. I assume that there are much more VMware products with the same capabilities, but I didn't research this area. Previously, I used freely available VMware Server, but now I have discovered that VMware Server chose to EOL it. It is still available, but VMware recommends using something else. So, I decided to evaluate VMware Workstation. The functionality related to adding of new virtual disks appeared to be pretty much the same as in VMware Server.
3. When, WMware Workstation is installed, choose "Edit Machine Properties" and add new virtual disk of required length. I would recommend to choose to split the new disks into chunks of 2GB. In my case it was the default. Choose a new name for the new disk. When finished, virify that you see the new disk in the list of devices used by the VM.
4. Start the VM and connect with root. CentOS provides a GUI interface to volume management and I'm quite sure that most of other Linux flavours have this capability too. Open the GUI by choosing System -> Administration -> Logical Volume Management from the menu and find the newly added disk under "Uninitialized Entities". The name should be like /dev/sd*. In my case, this was the third virtual disk in the system, so the name was /dev/sdc.
5. Open a command prompt with root and create a new disk partition with fdisk as follows:
fdisk /dev/sdc
You will receive a long informational message that the device is currently not partitioned and an interactive prompt. Choose "n" and put a new partition on the whole device. My outputs looks like this:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221):
Using default value 5221
Then, fdisk displays interactive prompt again. Choose "w":
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
6. Verify with fdisk -l that the new partition (/dev/sdc1 in my case) has been created on /dev/sdc.
7. Create a physical volume for the corresponding logical volume:
pvcreate /dev/sdc1
8. Extend the existing volume group to the new physical volume. Find the name of the volume group via vgdisplay. You can also see it in Logical Volume Management GUI.
vgextend vg_fedoravm /dev/sdc1
9. Extend the existing logical volume with 100% of the free space from the new physical volume. Find the name of the logical volume with lvdisplay or via GUI. See "man lvm" for more commands.
lvextend -l +100%FREE /dev/VolGroup00/LogVol00
10. Extend the existing filesystem on the logical volume:
resize2fs /dev/VolGroup00/LogVol00
11. That's all. Verify with df -h that the space has been added indeed. Enjoy :)
Excellent job, helped me a ton!
Posted by: Chris Tritz | 20 February 2014 at 19:02