Before creating partition you must chose in which way you want to manage your partition.

Way 1: You can create one or more primary partition and one extended partition on a disk . And now create as much as logical partition on that extended partition. All you need to do is format those logical partition and mount it to a . You can add multiple primary/logical partition (i.e. sdb1,sdb2 etc) on to a filesystem and by this way you can increase sie of filesystem (i.e /mydisk) .

Way 2:

a. create a pv for whole disk. b. Now create vg on it with appropriate requirement (use man for vgcreate). c. Create LV on it with appropriate requirement (use man for lvcreate). d. Format that lv e. Mount it to a filesystem

***The way 2 is better for partition management. Here you can extend/reduce/split your VG and LV.

A Simple Hard Disk Partitions Overview

A hard disk can be divided into several partitions. Each partition functions as if it were a separate hard disk. The idea is that if you have one hard disk, and want to have, say, two operating systems on it, you can divide the disk into two partitions. Each uses its partition as it wishes and doesn't touch the other ones. This way the two operating systems can co‐exist peacefully on the same hard disk. Without partitions one would have to buy a hard disk for each operating system.

Different type of Partitions

1.Primary

2.Extended and

3.Logical Partitions

There can be maximum 4 primary partition. That mean 4 OS can be reside on a hard disk at time. To overcome the limit we can use extended partition which can contain up to 24 partition. Each partition can be use as one logical viloume (i.e. c,d drive for windows or lv (i.e. sda1,sdb1) for linux or aix). The partition structure of a hard disk might look like that in Figure 5‐2. The disk is divided into three primary partitions, the second of which is divided into two logical partitions. Part of the disk is not partitioned at all. The disk as a whole and each primary partition has a boot sector.

Figure 5-2. A sample hard .

Difference between primary and a logical partition

There are only two main differences between a primary and a logical partition or volume. The first is that a primary partition can be set as bootable (active) while a logical cannot. The second is that DOS assigns drive letters (C:, D: etc.) differently to primary and logical volumes.

Here's an example to hopefully make all of this a bit more clear. Let's suppose you are setting up a new system and starting with an empty 60 GB hard disk. You could create a single 60 GB partition, which would be a primary DOS partition. However, in many cases dividing up such a large disk will make it easier to manage the space, will reduce lost disk space due to slack, and will reduce defragmentation time on partitions containing more actively‐used data. (See here for much more on the issues involved in partitioning.) So instead, let's say you want to split up this drive as follows:

One 8 GB primary partition for Windows and other operating system and program files.

One 12 GB partition for data. One 16 GB partition for games.

The rest of the disk in a 24 GB partition for large multimedia files, short‐term backups and "future expansion".

I'm assuming no complicating factors here, just a simple example. To do this, you will first set up a primary DOS partition 8 GB in size. This is the first of your four partitions. You will then create an extended DOS partition that is 52 GB in size. This is the second partition on the hard disk. Within the extended DOS partition you will create three logical volumes: one 12 GB, one 16 GB and one 24 GB. These are your second, third and fourth volumes (logical partitions). The first partition will be your C: drive from which you boot the machine, and DOS will (normally) assign D:, E: and F: to the other three logical partitions. Your hard disk will have one primary DOS partition, and one extended DOS partition containing three logical DOS volumes.

Graphical depiction of the partitioning of a 60 GB hard disk, as described in the example above. Each square represents

1 GB of space on the hard disk. The blue squares are the 8 GB primary partition; the green, red and purple squares are the

12 GB, 16 GB and 24 GB partitions respectively. The latter three partitions are logical partitions contained within an extended

DOS partition, indicated by the larger, gray‐shaded rectangle.

Some useful linux command

How do I add a new hard drive in Linux and create a primary partition?

Important Notes:

• This guide is for customers who have purchased an additional hard drive and need help configuring it to work with their Linux Server.

Getting Started:

1. Check to see how many drives are installed: You can do this using the command.

[root@default]# fdisk -l | grep '^Disk'

You should output similar to the following:

Disk /dev/sda: 251.0 GB, 251000193024 bytes

Disk /dev/sdb: 251.0 GB, 251000193024 bytes

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings .

2. To partition the disk fdisk /dev/sdb, enter:

[root@default root]# fdisk /dev/sdb

• For help using the partitioner, use the “m” command:

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

Command (m for help):

• partitions using the command “p”:

Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes

255 heads, 63 sectors/track, 6081 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

• To create a new partition, issue the command “n” and then select “p” for primary and 1-4 depending on which partition on the drive this is (first, second, third, or fourth):

n(creates a new partition)

p(creates a primary partition)

1(the number 1 denotes the partition will be /dev/sdb1) Command (m for help):

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-6081, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081

• To save the partition, use the “w” command:

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks. [root@default root]#

3. Format the new disk using mkfs.ext3 command:

To format Linux partions using ext2fs on the new disk, issue the following command:

[root@default]#mkfs.ext3 /dev/sdb1

4. Mount the new disk using the mount command:

First, you'll need to create a mount point. We'll use /disk1. This is where we'll mount /dev/sdb1. Enter the following commands:

[root@default]# mkdir /disk1 [root@default]# mount /dev/sdb1 /disk1 [root@default]# df -H

5. Edit /etc/fstab so the new drive will automatically mount to /disk1 on reboot

How do I create a extended partition and create multiple logical partition?

Important Notes:

• This guide is for customers who have purchased an additional hard drive from us, and need help configuring it to work with their Linux Server.

Getting Started:

2. Check to see how many drives are installed: You can do this using the fdisk command.

[root@default]# fdisk -l | grep '^Disk'

You should output similar to the following:

Disk /dev/sda: 251.0 GB, 251000193024 bytes Disk /dev/sdb: 251.0 GB, 251000193024 bytes

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings .

3. To partition the disk fdisk /dev/sdb, enter:

[root@default root]# fdisk /dev/sdb

• For help using the partitioner, use the “m” command:

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

Command (m for help):

• partitions using the command “p”:

Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes

255 heads, 63 sectors/track, 6081 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

• To create a new partition, issue the command “n” and then select “p” for primary and 1-4 depending on which partition on the drive this is (first, second, third, or fourth):

n(creates a new partition)

e(creates a extended partition)

1(the number 1 denotes the partition will be /dev/sdb1) Command (m for help):

Command (m for help): n

Command action

e extended

p primary partition (1-4) e

Partition number (1-4): 2

First cylinder (1-6081, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081

To create logical partition on newly created extended partion

n(creates a new partition)

e(creates a extended partition)

1(the number 1 denotes the partition will be /dev/sdb1) Command (m for help):

Command (m for help): n

Command action

l logical (5 or over)

p primary partition (1-4)

l

Partition number (1-4): 5

First cylinder (1-6081, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): +4G

• To save the partition, use the “w” command:

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@default root]#

Following Procedure will show how to create pv,volume group,lv.

*****Please ignore size and sda7 here***** Select the Physical Storage Devices for LVM – Use pvcreate, pvscan, pvdisplay Commands

In this step, we need to choose the physical volumes that will be used to create the LVM. We can create the physical volumes using pvcreate command as shown below.

$ sudo pvcreate /dev/sdb1 /dev/sda7

Physical volume "/dev/sdb1" successfully created

Physical volume "/dev/sda7" successfully created As shown above two physical volumes are created – /dev/sdb1 and /dev/sda7.

If the physical volumes are already created, you can view them using the pvscan command as shown below.

$ sudo pvscan

PV /dev/sdb1 lvm2 [1.86 GB]

PV /dev/sda7 lvm2 [1.86 GB]

Total: 2 [3.72 GB] / in use: 0 [0 ] / in no VG: 2 [3.72 GB]

You can view the list of physical volumes with attributes like size, physical extent size, total physical extent size, the free space, etc., using pvdisplay command as shown below.

$ sudo pvdisplay

--- Physical volume ---

PV Name /dev/sdb1

VG Name

PV Size 1.86 GB / not usable 2.12 MB

Allocatable yes

PE Size (KByte) 4096

Total PE 476

Free PE 456

Allocated PE 20

PV UUID m67TXf-EY6w-6LuX-NNB6-kU4L-wnk8-NjjZfv

--- Physical volume ---

PV Name /dev/sda7

VG Name

PV Size 1.86 GB / not usable 2.12 MB

Allocatable yes

PE Size (KByte) 4096

Total PE 476

Free PE 476

Allocated PE 0

PV UUID b031x0-6rej-BcBu-bE2C-eCXG-jObu-0Boo0x

Note : PE – Physical Extents are nothing but equal-sized chunks. The default size of extent is 4MB.

Create the Volume Group – Use vgcreate, vgdisplay Commands

Volume groups are nothing but a pool of storage that consists of one or more physical volumes. Once you create the physical volume, you can create the volume group (VG) from these physical volumes (PV).

In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.

$ sudo vgcreate vol_grp1 /dev/sdb1 /dev/sda7

Volume group "vol_grp1" successfully created LVM processes the storage in terms of extents. We can also change the extent size (from the default size 4MB) using -s flag.

vgdisplay command lists the created volume groups.

$ sudo vgdisplay

--- Volume group ---

VG Name vol_grp1

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 2

Act PV 2

VG Size 3.72 GB

PE Size 4.00 MB

Total PE 952

Alloc PE / Size 0 / 0 Free PE / Size 952 / 3.72 GB

VG UUID Kk1ufB-rT15-bSWe-5270-KDfZ-shUX-FUYBvR

LVM Create: Create Logical Volumes – Use lvcreate, lvdisplay command

Now, everything is ready to create the logical volumes from the volume groups. lvcreate command creates the logical volume with the size of 80MB.

$ sudo lvcreate -l 20 -n logical_vol1 vol_grp1

Logical volume "logical_vol1" created

Use lvdisplay command as shown below, to view the available logical volumes with its attributes.

$ sudo lvdisplay

--- Logical volume ---

LV Name /dev/vol_grp1/logical_vol1

VG Name vol_grp1

LV UUID ap8sZ2-WqE1-6401-Kupm-DbnO-2P7g-x1HwtQ

LV Write Access read/write

LV Status available

# open 0

LV Size 80.00 MB

Current LE 20

Segments 1 Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 252:0

After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.

$ sudo mkfs.ext3 /dev/vol_grp1/logical_vol1

$sudo mkdir mydisk

$ sudo mount /dev/vol_grp1/logical_vol1 /mydisk

LVM resize: Change the size of the logical volumes – Use lvextend Command

Before doing extension or reduction always unmount that lv

We can extend the size of the logical volumes after creating it by using lvextend utility as shown below. The changes the size of the logical volume from 80MB to 100MB.

$sudo umount /mydisk

$ sudo lvextend -L +20M /dev/vol_grp1/logical_vol1

Extending logical volume logical_vol1 to 100.00 MB

Logical volume logical_vol1 successfully resized

$ lvdisplay

--- Logical volume ---

LV Name /dev/vol_grp1/logical_vol1 VG Name vol_grp1

LV UUID ap8sZ2-WqE1-6401-Kupm-DbnO-2P7g-x1HwtQ

LV Write Access read/write

LV Status available

# open 0

LV Size 100.00 MB

Current LE 20

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 252:0

***But if you mount it on then you will see file system is still 80 MB as extended 20 Mb not yet formatted. So to use newly added space but also want keep data you need to follow following procedure.

Method

Overview

Resizing is performed using the resize2fs command, however there are some preparatory steps that you can take which will reduce the risk of data loss:

1. Ensure that you have an up to date backup.

2. Unmount the filesystem.

3. Check the filesystem.

. umount /mydisk

fsck -f /dev/vol_grp1/logical_vol1

resize2fs /dev/vol_grp1/logical_vol1

mount /dev/vol_grp1/logical_vol1 /mydisk

check with df -m

***Similarly you can extend/reduce/resize VG also. You can also include multiple PV in your VG. There are many vg command like

vgcfgbackup vgck vgdb vgextend vgmerge vgremove vgscan

vgcfgrestore vgconvert vgdisplay vgimport vgmknodes vgrename vgsplit vgchange vgcreate vgexport vgimportclone vgreduce vgs

Use man command for usage.