Sunday, 6 September 2009

How To Create LVM Partition

My friend asked me a query regarding the LVM Creation with a new harddisk. So i thought that it might be helpfull to all my friends using LVM on Linux.

To create LVM partition when we have a new hard disk installed on our server/system.

STEP 1. fdisk /dev/hdb    // create a partition in second HD

Now show the partition table on your system using p command.

Command (m for help): p          // show partition table

OUTPUT
Disk /dev/hdb: ---.- GB, xxxxxxxxxx bytes
xxxx heads, xx sectors/track, xxxxxx cylinders
Units = cylinders of xxxxx * xxx = xxxxxxxx bytes

Device Boot   Start   End   Blocks   Id   System

// nothing

Create a new partition using n option

Command (m for help): n     // create partition

Command action
e    extended
p    primary partition (1-4)

p    // primary

Partition number (1-4): 1   // partition number

First cylinder (x-xxxxx, default 1):   // First cylinder

Using default value 1  Last cylinder or +size or +sizeM or +sizeK (x-xxxxx, default xxxxx):    // Last cylinder

Using default value xxxxx

After creation of new partition we need to see our partition table.

Command (m for help):  p   // show partition table

OUTPUT

Disk /dev/hdb: xxx.x GB, xxxxxxxxxxxx bytes
xxx heads, xx sectors/track, xxxxx cylinders
Units = cylinders of xxxxxxx * xxx = xxxxxxx bytes

Device Boot Start End      Blocks   Id  System
/dev/hdb1      x   xxxxx  xxxxxxxxxx 83  Linux     // created

Command (m for help): t      // change partition type

Selected partition 1    // number

Hex code (type L to list codes): L    // show list of type

Hex code (type L to list codes): 8e    // Linux LVM

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p    // show partition table

OUTPUT

Disk /dev/hdb: xxx.x GB, xxxxxxxxxxx bytes
xxx heads, xx sectors/track, xxxxx cylinders
Units = cylinders of xxxxx * xxx = xxxxxxxxx bytes

Device Boot Start  End       Blocks         Id      System

/dev/hdb1     x     xxxxx    xxxxxxxx   8e   Linux LVM    // changed

Command (m for help):  w    // save and exit

STEP 2. fdisk -l /dev/hdb // show status

STEP 3. Now we need to create Physical Volume

pvcreate /dev/hdb1      // create Physical Volume

If we need to specify partition size, use command as below

pvcreate --setphysicalvolumesize 100G /dev/hdb1

To display status of Physical volume (Optional)

pvdisplay /dev/hdb1        // display status

STEP 4. We can change the volume size of Physical volume (Optional)

pvresize --setphysicalvolumesize 100G /dev/hdb1

STEP 5. To show the physical volume

pvs /dev/hdb1

STEP 6. To Scan the Physical volume

pvscan  /dev/hdb1

Now we can create Logical Volume, using the following steps.

1.     lvcreate –L 10G –n lvm1 vg0

2.     lvdisplay // to display the logical volumes.

3.     lvextend –L 20G /dev/vg0/lvm1

4.      resize2fs /dev/vg0/lvm1   //Most important thing to do in last

Note: Here i have used xxx for any number, depands on the size of the harddisk.

No comments:

Post a Comment