X
    Categories: LinuxLVM

10 Steps about How to create LVM Volume

Logical Volume Manager (LVM) is a software which provides the abstraction layer over the physical disk. Which  hides the details regarding where does data stored on the disk or from where the data comes from actual physical disk whenever it is requested.Before learning how to create lvm lets learn terms in LVM so that it will become easy to grasp the commands about LVM administration.

Terms involved in the LVM.

  1. The Physical Disk/Media: It is the raw hard disk where the actual data is going to store.  Ex: :  /dev/hda, /dev/hda6, /dev/sda.
  2. Physical Volume (PV): To bring the physical disk under LVM control we need to create the LVM data structure on the disk. once its created the its called as a PV.
  3. Physical Extents (PE):PV is divided into PE’s.
  4. Volume Group(VG): is made of number of PE coming from one or more PV’s.
  5. Logical Volume (LV): A Logical Volume is the end result of our work, and it’s there that we store our information.
  6. FileSystem:is the actual formatted LM which is formatted first and the mounted on the directory for actual storage of the information.

To understand the above terms more clearly refer to below diagrams:

Physical Volume, contains Physical Extents:

+-----[ Physical Volume ]------+
| PE | PE | PE | PE | PE | PE  |
+------------------------------+

Volume Group, containing 2 Physical Volumes (PVs) with 6 Physical Extents:

+------[ Volume Group ]-----------------+
| +--[PV]--------+ +--[PV]---------+    |
| | PE | PE | PE | | PE | PE | PE  |    |
| +--------------+ +---------------+    |
+---------------------------------------+

We now further expand this:

  +------[ Volume Group ]-----------------+
  |  +--[PV]--------+  +--[PV]---------+  |
  |  | PE | PE | PE |  | PE | PE | PE  |  |
  |  +--+---+---+---+  +-+----+----+---+  |
  |     |   |   | +-----/     |    |      |
  |     |   |   | |           |    |      |
  |   +-+---+---+-+      +----+----+--+   |
  |   |  Logical  |      |  Logical   |   |
  |   |  Volume   |      |   Volume   |   |
  |   |           |      |            |   |
  |   |  /home    |      |    /var    |   |
  |   +-----------+      +------------+   |
  +---------------------------------------+

This shows us two filesystems, spanning two disks.

The /home filesystem contains 4 Physical Extents, the /var filesystem contains 2 Physical Extents.

Practicals: Now lets learn how to create LVM volume so that it can be mounted on Linux server.

Steps to create LVM volume

1.  Checking the attached disk:

[root@mann ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00076e7f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2093 16501760 83 Linux
/dev/sda3 2093 2611 4161536 82 Linux swap / Solaris

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdd doesn't contain a valid partition table

Disk /dev/dm-1: 440 MB, 440401920 bytes
255 heads, 63 sectors/track, 53 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

2. Create LVM data structure on the disk /dev/sdc

[root@mann ~]# pvcreate /dev/sdc

Physical volume "/dev/sdc" successfully created

2a. Recheck it using pvdisply command.

[root@mann ~]# pvdisplay
--- Physical volume ---
PV Name               /dev/sdb
VG Name               vg01
PV Size               5.00 GiB / not usable 4.00 MiB
Allocatable           yes
PE Size               4.00 MiB
Total PE              1279
Free PE               1174
Allocated PE          105
PV UUID               3p2Wdk-SkZD-76ko-TQiP-IrwX-Whk5-WIzR7Q

"/dev/sdc" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name               /dev/sdc
VG Name
PV Size               2.00 GiB
Allocatable           NO
PE Size               0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               qoiBZ4-mRwV-G96p-U07x-zxwf-4iqY-wLPKUS

3. Create new VG

[root@mann ~]# vgcreate myvg /dev/sdc

Volume group "myvg" successfully created

4.Then Create new LV of size 200mb in the newly created VG.

[root@mann ~]# lvcreate -L 200 myvg

Logical volume "lvol0" created

5. Check the LV

[root@mann ~]# lvdisplay
--- Logical volume ---
LV Name                /dev/myvg/lvol0
VG Name                myvg
LV UUID                Jul8hw-3hWt-HYzM-cjiA-jysn-1YrU-4SPqgV
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                200.00 MiB
Current LE             50
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

--- Logical volume ---
LV Name                /dev/vg01/lvol0
VG Name                vg01
LV UUID                ziIOqS-WGe6-uv6X-F4GU-x7U9-MSfA-9ugZ42
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                420.00 MiB
Current LE             105
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

6. Format the newly created LV

[root@mann ~]# mkfs.ext3 -m 0 /dev/myvg/lvol0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
0 blocks (0.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

7. Add the entry in the fstab so that it will get mounted automatically while booting of the server.

[root@mann ~]# vi /etc/fstab -- > below entry

/dev/myvg/lvol0  /test ext3 defaults   0   0

8. Create mount where the filesystem need to mounted.

[root@mann ~]# mkdir /test

9. Mount the filesystem.

[root@mann ~]# mount /test

10. Recheck the mountpoint.

[root@mann ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              16G  2.0G   13G  14% /
tmpfs                1012M     0 1012M   0% /dev/shm
/dev/sda1             291M   29M  248M  11% /boot
/dev/mapper/myvg-lvol0
194M  5.6M  189M   3% /test
Related Post