In my last post I explained about the concepts of the Logical Volume Manager (LVM). If you need some background on Logical Volume Manager (LVM) or you are new to LINUX you can read the post Understanding The Concept Of Logical Volume Manager – LVM. Now hope you have a fair background with linux and the LVM lets try to setup it on a Ubuntu Linux Machine, you can use any LINUX distribution to set Setup Logical Volume Manager (LVM). The commands are almost same.
The setup of my machine is :-
1.) Primary Disk 20 Gb (dev/sda).
2.) Secondary Disk 10 GB (dev/sdb) [Will be used for LVM].
3.) Third Disk 6GB (dev/sdc) [Will be used for LVM].
Now to find the partitions or drives in your machine you can use the following command.
sudo fdisk -l
Now as per my previous post I want to use the same partition size for secondary disk as 10Gb but 3 Gb for Third disk because I also want to show how to extend the LVM partition. So we start by formatting the drives.
STEP1.) Partitioning the 10 Gb drive
sudo fdisk /dev/sdb
Note:- The hard drive name can be different in your system.
Now press n to create a new partition .
Now press p to make it a primary partition.
Now it will ask you to specify the starting cylinder as it is a raw disk and we need to use it the full capacity simply press enter.
Now enter the last cylinder. Just simply press enter as we need to use the whole disk. The drive has been initialized and read to be formatted.
You can check the partition information by pressing the p. All the steps are explained in the following image.
Now after finishing the above step we see that the above partition type is LINUX (Code 83) so we need to make it type LVM.
Now press t
Select the partition ( In this case we have only single partition on the disk so one will be automatically selected)
Now we need to enter the HEX code for the partition type . To find the Codes we can use l.
Now from the list we know the code is 8e. So type8e. The partition type is now LVM. Now to write the changes press w.
Now to make the kernel aware of the changes use partprobe command.
sudo partprobe /dev/sdb
Now we need to have our third hard-drive ready for the LVM we repeat the same step again but not taking the default start and finish cylinder number instead we specify the size as according to our need. I am using 4 GB ( the previous post explaining mentioned 6GB but to show how to extend LVM I am using 4GB.
So lets start again with the new drive :-
sudo fdisk /dev/sdc
Type n for new partition.
Now type p for making it a primary partition.
Now press enter as we are starting from a raw disk
Now on the finishing cylinder type +4G as we need the size 4GB.
Press t and type 8e (LINUX LVM partition code)
Press w to write changes. You can also issue the command
sudo partprobe /dev/sdc
your basic work is done. The drives are ready to be used to setup LVM.
STEP2.) Create the Physical Volumes
sudo pvcreate /dev/sdb1 /dev/sdc1
Now Create the Volume Group the name of the volume group is routemybrain
sudo vgcreate routemybrain /dev/sdb1 /dev/sdc1
You can verify the LOGICAL GROUP using the command vgdisplay
Creating the Logical volume
sudo lvcreate routemybrain -L +14G -n akash
routemybrain -> The name of the volume group
-L -> To specify the size of the partition in our case 14GB
-n -> To specify the name of the Logical volume in our case akash.
we can see the logical volume with the help of lvdisplay.
The LVM setup is done and finally we have created a LVM parition of 14gb now the final step just to mount it.
STEP3.) Make a directory for mounting the share
sudo mkdir /home/newtrojan/Lvm-Mount
now format the LVM partition.
sudo mkfs.ext3 /dev/routemybrain/akash
Now mount the partition
sudo mount /dev/routemybrain/akash /home/newtrojan/Lvm_Mount
you can verify the mount by issuing df -h command
That was really a long post. In the next post I will be explaining how to extend, resize or delete a Logical Volume Manager (LVM) partition