Monday, November 5, 2007

Disk Space Management Using LVM

Before starting this task it is necessary to install the LVM package

Linux Kernel 2.4.x has the LVM inbuilt.

In this blog we will focus on how to create an LVM layout and then mount it under the home directory

My root partition is sda1 and sda2 is my swap

To start partitioning run fdisk on /dev/sda

#fdisk /dev/sda
Enter p to create a new primary partition , accept all the default values for the start and end cylinders.

The next step is to change the partition into LVM. This means that we need to change the disk system ID into 8e as a partition type.

The above mentioned task can be done using fdisk command

Now we will create a volume group.

Volume group is nothing but two or more physical volumes together form a volume group.To bring our disk under the volume group we will have to configure our physical volumes.

#pvcreate /dev/sda (this command will initialise the physical volume)

We will now create a volume group which uses this physical volume

# vgcreate home2 /dev/sda (home2 is the volume group)

In this manner we can have multiple physical volume under volume group home2

Now we have created the volume group, now we will create logical volumes. We can have many logical volumes under one volume group. Or we can use one complete logical group has one Logical volume.

#lvcreate -n downloads --size 1G home2

The above mentioned command will create a logical volume as download with 1GB space under volume group home2

-n is used to name the logical volume.

Before we can use the Logical Volume, we need to format it and then mount it.

We will create a directory under /mnt as mystuff.

Now we will format the logical volume (/dev/home2/download)

#mkfs ext3 /dev/home2/download

Once the formatting is over we will mount the logical volume on to the /mnt/mystuff

#mount /dev/home2/download /mnt/mystuff

To make a permanent entry

#vi /etc/fstab

/dev/home2/download /mnt/mystuff ext3 defaults 12

save the file

No comments: