LVM(Logical Volume Manager)
LVM is the logical volume manager for the linux kernel. It manages disk drives and similar mass storage devices. The term volume refers to a disk drive or partition. LVM helps in managing large hard disk farms by letting you add disks, replace disks, copy and share contents from one disk to another without disrupting service (hot swapping). It also supports the backup support by taking the snapshot of existing data. It allows to resize the logical volume online.
Creating a logical volume:
If you want to create a logical volume on your machine, follow the steps below, you can modify the steps according to your need.
1. First of all you will need to create a partition, you can create the lvm from single partition and more than one partition as well:
# fdisk /dev/sda
/dev/sda may vary according to hard disk type.
press n for new partition, suppose sda6 is new partition created. Also we need to change the type of partition, for that press t and then type 8e for linux lvm and enter. Now save the changes using w.
To see the new partition created, use
# fdisk -l
Now reboot the system for the partition table to change.
2. Once partition is created, we will go through three steps for creating the LVM.
Step 1: Creating the Physical Volume.
From the partition created, we will create the physical volume using the command:
# pvcreate /dev/sda6
If you are creating the physical volume from more than one partitions:
# pvcreate /dev/sda6 /dev/sda7
This way we can create physical volume from multiple partitions. You can see the created physical volume using the command:
# pvdisplay
or
# pvscan
Step 2: Creating Volume Group
From physical volumes, we need to create the volume group:
# vgcreate vg_name /dev/sda6
# vgcreate vg_name /dev/sda6 /dev/sda7
These commands are used to create volume groups, however this command will create the volume groups of the default size 4 MB. However, we can change this size using the option -s
# vgcreate -s 16M vg_name /dev/sda6
where 16M is the size of physical extend. This means that the smallest block in the lvm will be of the size 16M.
This must be in the multiple of two.
To see the created volume groups, use the command:
# vgdisplay
or
# vgscan
These commands will display the Physical extend size.
Step 3: Creating the Logical volume
Now lvm can be created from volume group, we can do it in two ways as well.
# lvcreate -L 10G -n lv_name vg_name
or
# lvcreate -l 4000 -n lv_name vg_name
The first command will create the lvm of the size 10GB from the Volume group, and the second command will create the lvm of 16x4000=64000MB from volume group.
But before specifying the size of the lvm, make sure that you have created the volume group of that much size.
Now lvm is created, you need to format the lvm and mount on some directory as;
# mkfs.ext4 lv_name
# mount lv_name directory_name
For mounting permanently, make entry in /etc/fstab as directed in my post creating partitions.
LVM is the logical volume manager for the linux kernel. It manages disk drives and similar mass storage devices. The term volume refers to a disk drive or partition. LVM helps in managing large hard disk farms by letting you add disks, replace disks, copy and share contents from one disk to another without disrupting service (hot swapping). It also supports the backup support by taking the snapshot of existing data. It allows to resize the logical volume online.
Creating a logical volume:
If you want to create a logical volume on your machine, follow the steps below, you can modify the steps according to your need.
1. First of all you will need to create a partition, you can create the lvm from single partition and more than one partition as well:
# fdisk /dev/sda
/dev/sda may vary according to hard disk type.
press n for new partition, suppose sda6 is new partition created. Also we need to change the type of partition, for that press t and then type 8e for linux lvm and enter. Now save the changes using w.
To see the new partition created, use
# fdisk -l
Now reboot the system for the partition table to change.
2. Once partition is created, we will go through three steps for creating the LVM.
Step 1: Creating the Physical Volume.
From the partition created, we will create the physical volume using the command:
# pvcreate /dev/sda6
If you are creating the physical volume from more than one partitions:
# pvcreate /dev/sda6 /dev/sda7
This way we can create physical volume from multiple partitions. You can see the created physical volume using the command:
# pvdisplay
or
# pvscan
Step 2: Creating Volume Group
From physical volumes, we need to create the volume group:
# vgcreate vg_name /dev/sda6
# vgcreate vg_name /dev/sda6 /dev/sda7
These commands are used to create volume groups, however this command will create the volume groups of the default size 4 MB. However, we can change this size using the option -s
# vgcreate -s 16M vg_name /dev/sda6
where 16M is the size of physical extend. This means that the smallest block in the lvm will be of the size 16M.
This must be in the multiple of two.
To see the created volume groups, use the command:
# vgdisplay
or
# vgscan
These commands will display the Physical extend size.
Step 3: Creating the Logical volume
Now lvm can be created from volume group, we can do it in two ways as well.
# lvcreate -L 10G -n lv_name vg_name
or
# lvcreate -l 4000 -n lv_name vg_name
The first command will create the lvm of the size 10GB from the Volume group, and the second command will create the lvm of 16x4000=64000MB from volume group.
But before specifying the size of the lvm, make sure that you have created the volume group of that much size.
Now lvm is created, you need to format the lvm and mount on some directory as;
# mkfs.ext4 lv_name
# mount lv_name directory_name
For mounting permanently, make entry in /etc/fstab as directed in my post creating partitions.
No comments:
Post a Comment