{"id":5851,"date":"2015-01-31T13:10:00","date_gmt":"2015-01-31T05:10:00","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5851"},"modified":"2023-04-28T09:47:19","modified_gmt":"2023-04-28T09:47:19","slug":"create-lvm-in-linux-centos","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/create-lvm-in-linux-centos\/","title":{"rendered":"How to Create LVM in Linux CentOS 7 \/ RHEL 7 \/ Oracle Linux 7"},"content":{"rendered":"<p>Storage technology plays a important role in improving the availability, performance, and ability to manage Linux servers.<\/p>\n<p>One of the most useful and helpful technology to linux system administrator is Linux Logical Volume Manager(LVM), version 2 (or LVM 2).<\/p>\n<p>LVM is a widely-used technique and extremely flexible disk management scheme for deploying logical rather than physical storage. With LVM, system administrator can easily resize and extend the logical drive when it is required.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5870 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/lvm-diagram1.jpg\" alt=\"Create Lvm\" width=\"600\" height=\"338\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/lvm-diagram1.jpg 600w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/lvm-diagram1-300x169.jpg 300w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/338;\" \/><\/p>\n<p>The following steps will describe how to create LVM in Linux CentOS 7 or RHEL 7 or Oracle Linux 7.<\/p>\n<h2>How to Create Lvm in Linux Step by Step<\/h2>\n<p>1. Add the new 20GB vdisk from the ESXi or vCenter :<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5863 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/Create-new-LVM-CentOS7-1.png\" alt=\"Create Lvm\" width=\"600\" height=\"533\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/Create-new-LVM-CentOS7-1.png 600w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/01\/Create-new-LVM-CentOS7-1-300x267.png 300w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/533;\" \/><\/p>\n<p>2. create a new Partiton using fdisk tool and select partition type LVM :<\/p>\n<pre>[root@centos7 ~]# fdisk \/dev\/sdb\nWelcome to fdisk (util-linux 2.23.2).\n\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\n\nDevice does not contain a recognized partition table\nBuilding a new DOS disklabel with disk identifier 0xfd3bf27d.\n\nCommand (m for help): n\nPartition type:\n   p   primary (0 primary, 0 extended, 4 free)\n   e   extended\nSelect (default p): p\nPartition number (1-4, default 1): 1\nFirst sector (2048-41943039, default 2048):\nUsing default value 2048\nLast sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):\nUsing default value 41943039\nPartition 1 of type Linux and of size 20 GiB is set\n\nCommand (m for help): p\n\nDisk \/dev\/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk label type: dos\nDisk identifier: 0xfd3bf27d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sdb1            2048    41943039    20970496   83  Linux\n\nCommand (m for help): t\nSelected partition 1\nHex code (type L to list all codes): L\n\n 0  Empty           24  NEC DOS         81  Minix \/ old Lin bf  Solaris\n 1  FAT12           27  Hidden NTFS Win 82  Linux swap \/ So c1  DRDOS\/sec (FAT-\n 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS\/sec (FAT-\n 3  XENIX usr       3c  PartitionMagic  84  OS\/2 hidden C:  c6  DRDOS\/sec (FAT-\n 4  FAT16 &lt;32M      40  Venix 80286     85  Linux extended  c7  Syrinx\n 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data\n 6  FAT16           42  SFS             87  NTFS volume set db  CP\/M \/ CTOS \/ .\n 7  HPFS\/NTFS\/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility\n 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt\n 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access\n a  OS\/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R\/O\n b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD\/OS          e4  SpeedStor\n c  W95 FAT32 (LBA) 52  CP\/M            a0  IBM Thinkpad hi eb  BeOS fs\n e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT\n f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12\/16\/\n10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux\/PA-RISC b\n11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor\n12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor\n14  Hidden FAT16 &lt;3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary\n16  Hidden FAT16    63  GNU HURD or Sys af  HFS \/ HFS+      fb  VMware VMFS\n17  Hidden HPFS\/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE\n18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto\n1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep\n1c  Hidden W95 FAT3 75  PC\/IX           be  Solaris boot    ff  BBT\n1e  Hidden W95 FAT1 80  Old Minix\nHex code (type L to list all codes): 8e\nChanged type of partition 'Linux' to 'Linux LVM'\n\nCommand (m for help): p\n\nDisk \/dev\/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk label type: dos\nDisk identifier: 0xfd3bf27d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sdb1            2048    41943039    20970496   8e  Linux LVM\n<\/pre>\n<p>3. Initializes the partition \/dev\/sdb1 as an LVM physical volume :<\/p>\n<pre>[root@centos7 ~]# pvcreate \/dev\/sdb1\n  Physical volume \"\/dev\/sdb1\" successfully created\n<\/pre>\n<p>4. Scanning for Block Devices<\/p>\n<pre>[root@centos7 ~]# lvmdiskscan\n  \/dev\/centos\/swap [       2.00 GiB]\n  \/dev\/sda1        [     500.00 MiB]\n  \/dev\/centos\/root [      27.51 GiB]\n  \/dev\/sda2        [      29.51 GiB] LVM physical volume\n  \/dev\/sdb1        [      20.00 GiB] LVM physical volume\n  2 disks\n  1 partition\n  0 LVM physical volume whole disks\n  2 LVM physical volumes\n<\/pre>\n<p>5. Displaying Physical Volumes :<\/p>\n<p>There are three commands you can use to display properties of LVM physical volumes: pvs,<br \/>\npvdisplay, and pvscan.<\/p>\n<p>The pvdisplay command provides a verbose multi-line output for each physical volume. It displays<br \/>\nphysical properties (size, extents, volume group, etc.) in a fixed format.<\/p>\n<pre>[root@centos7 ~]# pvdisplay\n  --- Physical volume ---\n  PV Name               \/dev\/sda2\n  VG Name               centos\n  PV Size               29.51 GiB \/ not usable 3.00 MiB\n  Allocatable           yes (but full)\n  PE Size               4.00 MiB\n  Total PE              7554\n  Free PE               0\n  Allocated PE          7554\n  PV UUID               JvDOto-KDiF-gtca-TveX-ne9M-frsB-qsP1aJ\n\n  \"\/dev\/sdb1\" is a new physical volume of \"20.00 GiB\"\n  --- NEW Physical volume ---\n  PV Name               \/dev\/sdb1\n  VG Name\n  PV Size               20.00 GiB\n  Allocatable           NO\n  PE Size               0\n  Total PE              0\n  Free PE               0\n  Allocated PE          0\n  PV UUID               rJ8wl7-xzIN-2qqV-ov7Z-lHKe-ELge-aAV29V\n<\/pre>\n<p>The pvscan command scans all supported LVM block devices in the system for physical volumes<\/p>\n<pre>[root@centos7 ~]# pvscan\n  PV \/dev\/sda2   VG centos          lvm2 [29.51 GiB \/ 0    free]\n  PV \/dev\/sdb1                      lvm2 [20.00 GiB]\n  Total: 2 [49.51 GiB] \/ in use: 1 [29.51 GiB] \/ in no VG: 1 [20.00 GiB]\n<\/pre>\n<p>6. Create volume group name vg_newlvm and add \/dev\/sdb1 partition into the group.<\/p>\n<pre>[root@centos7 ~]# vgcreate vg_newlvm \/dev\/sdb1\n  Volume group \"vg_newlvm\" successfully created\n<\/pre>\n<p>If you have more than one partition, you can add multiple partition in single command. This command creates a local volume named vg_newlvm that contains physical volumes \/dev\/sdb1 and \/dev\/sdc1 :<\/p>\n<pre>[root@centos7 ~]# vgcreate vg_newlvm \/dev\/sdb1 \/dev\/sdc1\n<\/pre>\n<p>7. Creates a logical volume called centos7_newvol that uses all of the unallocated space in the volume group vg_newlvm :<\/p>\n<pre>[root@centos7 ~]# lvcreate --name centos7_newvol -l 100%FREE vg_newlvm\n  Logical volume \"centos7_newvol\" created\n<\/pre>\n<p>You can see more example of lvcreate command in article &#8220;<strong><a href=\"https:\/\/webhostinggeeks.com\/howto\/4-lvcreate-command-examples-on-linux\/\" target=\"_blank\" rel=\"noopener\">4 lvcreate Command Examples on Linux<\/a><\/strong>&#8221;<\/p>\n<p>8. Display the created logical volumes :<\/p>\n<pre>[root@centos7 ~]# lvdisplay\n<\/pre>\n<pre>..\n..\n  --- Logical volume ---\n  LV Path                \/dev\/vg_newlvm\/centos7_newvol\n  LV Name                centos7_newvol\n  VG Name                vg_newlvm\n  LV UUID                szlkNP-0lwe-f59Z-PJVU-X7pG-unBL-qN10D4\n  LV Write Access        read\/write\n  LV Creation host, time centos7.ehowstuff.local, 2015-01-25 15:15:48 +0800\n  LV Status              available\n  # open                 0\n  LV Size                20.00 GiB\n  Current LE             5119\n  Segments               1\n  Allocation             inherit\n  Read ahead sectors     auto\n  - currently set to     8192\n  Block device           253:2\n<\/pre>\n<p>9. Use the mkfs command to format a newly created LVM :<\/p>\n<pre>[root@centos7 ~]# mkfs.ext4 \/dev\/vg_newlvm\/centos7_newvol\nmke2fs 1.42.9 (28-Dec-2013)\nFilesystem label=\nOS type: Linux\nBlock size=4096 (log=2)\nFragment size=4096 (log=2)\nStride=0 blocks, Stripe width=0 blocks\n1310720 inodes, 5241856 blocks\n262092 blocks (5.00%) reserved for the super user\nFirst data block=0\nMaximum filesystem blocks=2153775104\n160 block groups\n32768 blocks per group, 32768 fragments per group\n8192 inodes per group\nSuperblock backups stored on blocks:\n        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,\n        4096000\n\nAllocating group tables: done\nWriting inode tables: done\nCreating journal (32768 blocks): done\nWriting superblocks and filesystem accounting information: done\n<\/pre>\n<p>10. Create the mount point and mount the new LVM :<\/p>\n<pre>[root@centos7 ~]# mkdir -p \/data\n[root@centos7 ~]# mount \/dev\/vg_newlvm\/centos7_newvol \/data\n<\/pre>\n<p>11. Verify thew new disk layout :<\/p>\n<pre>[root@centos7 ~]# df\nFilesystem                           1K-blocks    Used Available Use% Mounted on\n\/dev\/mapper\/centos-root               28260132 9191032  17610516  35% \/\ndevtmpfs                               1935888       0   1935888   0% \/dev\ntmpfs                                  1941892       0   1941892   0% \/dev\/shm\ntmpfs                                  1941892    8728   1933164   1% \/run\ntmpfs                                  1941892       0   1941892   0% \/sys\/fs\/cgroup\n\/dev\/sda1                               487634   73191    384747  16% \/boot\ntmpfs                                  1941892    8728   1933164   1% \/var\/named\/chroot\/run\/named\n\/dev\/mapper\/vg_newlvm-centos7_newvol  20507216   45080  19397384   1% \/data\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Storage technology plays a important role in improving the availability, performance, and ability to manage Linux servers. One of the most useful and helpful technology to linux system administrator is&#8230;<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,1002,2058],"tags":[1258,1556,1717],"class_list":["post-5851","post","type-post","status-publish","format-standard","hentry","category-centos","category-lvm","category-rhel","tag-centos-7","tag-lvm","tag-rhel-7"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5851"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5851\/revisions"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}