Hello Friends,
This post will cover how to increase the disk space for a VMware virtual
machine running Linux that is using logical volume manager (LVM). Firstly we
will add a new disk to the virtual machine and then extend the original LVM
over this additional space.
As there are a number of different ways to increase disk space but I have
also posted simple and step by step method. Using this method I am sure you will increase the space easily.
1. First of all before adding any hard disk please run the below command to check the how much space is currently left on the VG group.
#vgdisplay
If you see above image you can found the volume group name, in my case it is "rootvg".
2. Now run the below command to see the existing LVM disk is currently used in LVM.
#fdisk -l
You can see the above output, the /dev/sda2 hard disk is in used for existing LVM. Now you can add new hard disk on the server.
3. Once you added the new hard disk on the server to increase the size on Linux LVM, lets assume the new hard disk labelled is /dev/sdb. In this step we will need to partition the new hard disk so we can use it.
#fdisk /dev/sdb
It should show us below message to us for next selection.
root@localhost:~# fdisk /dev/sdb
Command (m for help): n
Please select the "n" for adding a new partition. Once we will select the "n" for new partition it is show to us below screen.
Command action
e extended
p primary partition (1-4)p
We will select the "p" for primary partition so we will add new had disk /dev/sdb as a primary partition.
----------------------------------------------------------------------------------------
Partition number (1-4): 1
First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter"
Using default value 2610
----------------------------------------------------------------------------------------
In above screen, we will select 1 for primary partition and make a default settings.
‘t’ is selected to change to a partitions system ID, in this case we change to ’1′ automatically as this is currently our only partition.
----------------------------------------------------------------------------------------
Command (m for help): t
Selected partition 1
----------------------------------------------------------------------------------------
The hex code ’8e’ was entered as this is the code for a Linux LVM which is what we want this partition to be, as we will be joining it with the original Linux LVM which is currently using /dev/sda4.
----------------------------------------------------------------------------------------
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
----------------------------------------------------------------------------------------
‘w’ is used to write the table to disk and exit, all changes that have been done will be saved and then you will be exited from fdisk.
----------------------------------------------------------------------------------------
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
By using “fdisk -l” now you will be able to see that /dev/sdb1 is listed, this is the new partition created on our newly added /dev/sdb disk.
4. Now we will create a physical volume with this newly added hard disk /dev/sdb1. For physical volume creation we will use "pvcreate" command.
#pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
In above command output, you can see the /dev/sdb1 physical volume group has been created.
5. Now the most important steps of this post is using physical volume you can extend or create a new volume group.
If you want to extend the logical volume size of existing Volume group then please use the below command and method.
#vgextend test /dev/sdb1
In my case my VG name is "test" so I will extend the space in existing VG "test".
If you want to create the new logical voume and want to add physical volume in new VG, please use the below command and method.
#vgcreate rootvg /dev/sdb1
In this case my new VG name is "rootvg".
So, as per my this post, you can add new hard disk in to existing volume group or newly created volume group. Using this volume group you can create or extend the Linux LVM size.
If you see above image you can found the volume group name, in my case it is "rootvg".
2. Now run the below command to see the existing LVM disk is currently used in LVM.
#fdisk -l
You can see the above output, the /dev/sda2 hard disk is in used for existing LVM. Now you can add new hard disk on the server.
3. Once you added the new hard disk on the server to increase the size on Linux LVM, lets assume the new hard disk labelled is /dev/sdb. In this step we will need to partition the new hard disk so we can use it.
#fdisk /dev/sdb
It should show us below message to us for next selection.
root@localhost:~# fdisk /dev/sdb
Command (m for help): n
Please select the "n" for adding a new partition. Once we will select the "n" for new partition it is show to us below screen.
Command action
e extended
p primary partition (1-4)p
We will select the "p" for primary partition so we will add new had disk /dev/sdb as a primary partition.
----------------------------------------------------------------------------------------
Partition number (1-4): 1
First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter"
Using default value 2610
----------------------------------------------------------------------------------------
In above screen, we will select 1 for primary partition and make a default settings.
‘t’ is selected to change to a partitions system ID, in this case we change to ’1′ automatically as this is currently our only partition.
----------------------------------------------------------------------------------------
Command (m for help): t
Selected partition 1
----------------------------------------------------------------------------------------
The hex code ’8e’ was entered as this is the code for a Linux LVM which is what we want this partition to be, as we will be joining it with the original Linux LVM which is currently using /dev/sda4.
----------------------------------------------------------------------------------------
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
----------------------------------------------------------------------------------------
‘w’ is used to write the table to disk and exit, all changes that have been done will be saved and then you will be exited from fdisk.
----------------------------------------------------------------------------------------
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------
By using “fdisk -l” now you will be able to see that /dev/sdb1 is listed, this is the new partition created on our newly added /dev/sdb disk.
4. Now we will create a physical volume with this newly added hard disk /dev/sdb1. For physical volume creation we will use "pvcreate" command.
#pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
In above command output, you can see the /dev/sdb1 physical volume group has been created.
5. Now the most important steps of this post is using physical volume you can extend or create a new volume group.
If you want to extend the logical volume size of existing Volume group then please use the below command and method.
#vgextend test /dev/sdb1
In my case my VG name is "test" so I will extend the space in existing VG "test".
If you want to create the new logical voume and want to add physical volume in new VG, please use the below command and method.
#vgcreate rootvg /dev/sdb1
In this case my new VG name is "rootvg".
So, as per my this post, you can add new hard disk in to existing volume group or newly created volume group. Using this volume group you can create or extend the Linux LVM size.
No comments:
Post a Comment