{"id":1306,"date":"2012-09-05T14:43:33","date_gmt":"2012-09-05T06:43:33","guid":{"rendered":"http:\/\/rmohan.com\/?p=1306"},"modified":"2012-09-05T14:43:33","modified_gmt":"2012-09-05T06:43:33","slug":"managing-physical-and-logical-volumes","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1306","title":{"rendered":"Managing Physical and Logical Volumes"},"content":{"rendered":"<p>Contents<\/p>\n<p>\u00a0\u00a0\u00a0 Introduction<br \/>\u00a0\u00a0\u00a0 Create Logical Volumes<br \/>\u00a0\u00a0\u00a0 Delete Logical Volumes<\/p>\n<p>Introduction<\/p>\n<p>The following article presents an overview of the commands used to manage physical and logical volumes for use with Logical Volume Manager (LVM) in Linux.<\/p>\n<p>Before considering the various commands for LVM, lets first look at just what is meant by some of the terminology of LVM.<\/p>\n<p>A logical volume lives in a volume group that is made up of one or more physical volumes. All volume groups are part of the Logical Volume Manager. Here is a table that lists the three types of Logical Volume&#8217;s.<\/p>\n<p>Logical Volume Types Logical Volume \u00a0\u00a0 \u00a0Physical Device \u00a0\u00a0 \u00a0File System<br \/>volume group \u00a0\u00a0 \u00a0one or more disks \u00a0\u00a0 \u00a0vgdisplay<br \/>physical volume group \u00a0\u00a0 \u00a0physical extents on a drive \u00a0\u00a0 \u00a0pvdisplay<br \/>logical volume group \u00a0\u00a0 \u00a0multiple physical volume groups, one or more disks \u00a0\u00a0 \u00a0lvdisplay<\/p>\n<p>The following table provides an overview of some of the commands used in LVM and the functions they service.<\/p>\n<p>LVM Commands Command \u00a0\u00a0 \u00a0LVM Function<br \/>vgcreate \u00a0\u00a0 \u00a0Create a Volume Group. (Create a subset of the overall LVM)<br \/>pvcreate \u00a0\u00a0 \u00a0Create a Physical Volume, assign to Volume Group. (Specify a disk for inclusion in the overall LVM)<br \/>vgextend \u00a0\u00a0 \u00a0Add a new physical disk to a volume group.<br \/>lvcreate \u00a0\u00a0 \u00a0Create a Logical Volume. (Storage area for related files that is part of a Volume Group. A Volume Group consists of many logical volumes)<br \/>lvextend \u00a0\u00a0 \u00a0Increase the size of a Logical Volume.<br \/>lvreduce \u00a0\u00a0 \u00a0Decrease the size of a Logical Volume.<br \/>lvremove \u00a0\u00a0 \u00a0Removes a Logical Volume. (Frees the storage area set aside for a logical volume)<br \/>vgreduce \u00a0\u00a0 \u00a0Reduce a Volume Group. (Reduces the number of disks in a Volume Group)<br \/>vgremove \u00a0\u00a0 \u00a0Remove a Volume Group. (Removes the designation of a group of disks as a Volume Group)<br \/>vgdisplay \u00a0\u00a0 \u00a0Volume Group Display. (Displays information about one or more Volume Groups)<br \/>pvdisplay \u00a0\u00a0 \u00a0Physical Volume Display. (Displays information about one or more Volume Groups)<br \/>lvdisplay \u00a0\u00a0 \u00a0Logical Volume Display. (Displays information about one or more Logical Volumes)<br \/>Create Logical Volumes<\/p>\n<p>The following subsections describe the commands used for creating logical volumes.<br \/>Partition Types<\/p>\n<p>Before using a hard disk as a physical volume, decide if the physical volume will use the entire disk (\/dev\/sdc) or a disk partition (\/dev\/sdc1).<\/p>\n<p>To create the physical volume using a partition, set the partition type to 0x8e (Linux LVM) using fdisk or some other similar program.<\/p>\n<p>Each logical volume in this section will use the entire hard disk. This requires that no partition table exists on the disk. When using the whole disk, the partition table must be erased, which will effectively destroy all data on that disk. An existing partition table can be removed by zeroing the first sector on the disk using the dd command.<\/p>\n<p>\u00a0 \u00a0\u00a0 \u00a0<\/p>\n<p>The following commands will destroy the partition table on the disk being operated on. Be very sure it is the correct disk before continuing.<\/p>\n<p>[root@testnode1 ~]# dd if=\/dev\/zero of=\/dev\/sdc bs=512 count=1<br \/>1+0 records in<br \/>1+0 records out<br \/>512 bytes (512 B) copied, 0.00379734 seconds, 135 kB\/s<\/p>\n<p>[root@testnode1 ~]# dd if=\/dev\/zero of=\/dev\/sdd bs=512 count=1<br \/>1+0 records in<br \/>1+0 records out<br \/>512 bytes (512 B) copied, 0.00200099 seconds, 256 kB\/s<\/p>\n<p>Verify that the partition table has been removed from both hard disks.<\/p>\n<p>[root@testnode1 ~]# fdisk -l | grep &#8216;^Disk \\\/dev\\\/sd[cd][^:]&#8217;<br \/>Disk \/dev\/sdc doesn&#8217;t contain a valid partition table<br \/>Disk \/dev\/sdd doesn&#8217;t contain a valid partition table<br \/>Disk \/dev\/dm-0 doesn&#8217;t contain a valid partition table<br \/>Disk \/dev\/dm-1 doesn&#8217;t contain a valid partition table<\/p>\n<p>Initialize Physical Volumes<\/p>\n<p>Use the pvcreate command to initialize a block device to be used as a physical volume. The following commands will initialize the whole disk for each hard disk.<\/p>\n<p>[root@testnode1 ~]# pvcreate \/dev\/sdc<br \/>\u00a0 Physical volume &#8220;\/dev\/sdc&#8221; successfully created<\/p>\n<p>[root@testnode1 ~]# pvcreate \/dev\/sdd<br \/>\u00a0 Physical volume &#8220;\/dev\/sdd&#8221; successfully created<\/p>\n<p>\u00a0 \u00a0\u00a0 \u00a0<\/p>\n<p>When using a partition, run pvcreate on the partition.<\/p>\n<p>[root@testnode1 ~]# pvcreate \/dev\/sdc1<br \/>\u00a0 Physical volume &#8220;\/dev\/sdc1&#8221; successfully created<\/p>\n<p>[root@testnode1 ~]# pvcreate \/dev\/sdd1<br \/>\u00a0 Physical volume &#8220;\/dev\/sdd1&#8221; successfully created<\/p>\n<p>This creates a volume group descriptor at the start of the \/dev\/sdc1 and \/dev\/sdd1 partition.<\/p>\n<p>Use the lvmdiskscan command to scan for block devices and verify that the two hard disks can be used as physical volumes.<\/p>\n<p>[root@testnode1 ~]# lvmdiskscan | grep &#8216;\\\/dev\\\/sd[cd]&#8217;<br \/>\u00a0 \/dev\/sdc\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 36.00 GB] LVM physical volume<br \/>\u00a0 \/dev\/sdd\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 36.00 GB] LVM physical volume<\/p>\n<p>Create Volume Group<\/p>\n<p>Use the vgcreate command to create a volume group from one or more physical volumes. The vgcreate command creates a new volume group by name (vg_oradata and vg_orafra for example) and adds at least one physical volume to it. Create a new volume group on each hard disk.<\/p>\n<p>[root@testnode1 ~]# vgcreate vg_oradata \/dev\/sdc<br \/>\u00a0 Volume group &#8220;vg_oradata&#8221; successfully created<\/p>\n<p>[root@testnode1 ~]# vgcreate vg_orafra \/dev\/sdd<br \/>\u00a0 Volume group &#8220;vg_orafra&#8221; successfully created<\/p>\n<p>This creates a volume group descriptor at the start of each disk. When using partitions, run the vgcreate command on the partition (for example, vgcreate vg_oradata \/dev\/sdc1) which will create a volume group descriptor at the start of the partition.<br \/>Create Logical Volumes<\/p>\n<p>With the new volume groups in place, use the lvcreate command to create the appropriate logical volumes (lv_oradata and lv_orafra). Logical volumes can be created as linear volumes, striped volumes, and mirrored volumes. For the purpose of this example, create a single linear volume within each of the volume groups that uses all of the unallocated space within the volume group.<\/p>\n<p>[root@testnode1 ~]# lvcreate -l 100%FREE -n lv_oradata vg_oradata<br \/>\u00a0 Logical volume &#8220;lv_oradata&#8221; created<\/p>\n<p>[root@testnode1 ~]# lvcreate -l 100%FREE -n lv_orafra vg_orafra<br \/>\u00a0 Logical volume &#8220;lv_orafra&#8221; created<\/p>\n<p>Verify LVM Configuration<\/p>\n<p>Use the vgscan and lvscan commands to verify the new volume groups and logical volumes respectively.<\/p>\n<p>[root@testnode1 ~]# vgscan<br \/>\u00a0 Reading all physical volumes.\u00a0 This may take a while&#8230;<br \/>\u00a0 Found volume group &#8220;vg_orafra&#8221; using metadata type lvm2<br \/>\u00a0 Found volume group &#8220;vg_oradata&#8221; using metadata type lvm2<br \/>\u00a0 Found volume group &#8220;vg_orasoftware&#8221; using metadata type lvm2<br \/>\u00a0 Found volume group &#8220;VolGroup00&#8221; using metadata type lvm2<\/p>\n<p>[root@testnode1 ~]# lvscan<br \/>\u00a0 ACTIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;\/dev\/vg_orafra\/lv_orafra&#8217; [36.00 GB] inherit<br \/>\u00a0 ACTIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;\/dev\/vg_oradata\/lv_oradata&#8217; [36.00 GB] inherit<br \/>\u00a0 ACTIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;\/dev\/vg_orasoftware\/lv_orasoftware&#8217; [35.97 GB] inherit<br \/>\u00a0 ACTIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;\/dev\/VolGroup00\/LogVol00&#8217; [30.97 GB] inherit<br \/>\u00a0 ACTIVE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;\/dev\/VolGroup00\/LogVol01&#8217; [4.91 GB] inherit<\/p>\n<p>LVM volume groups and underlying logical volumes are included in the device special file directory tree in the \/dev directory with the following layout.<\/p>\n<p>\u00a0 \/dev\/vg\/lv\/<\/p>\n<p>For example:<\/p>\n<p>\u00a0 \/dev\/vg_oradata\/lv_oradata<br \/>\u00a0 \/dev\/vg_orafra\/lv_orafra<\/p>\n<p>Delete Logical Volumes<\/p>\n<p>Before describing how to drop physical and logical volumes, note that it is very common to only want to remove a logical volume from a volume group. For example, if users no longer need the logical volume lv_orafra. The logical volume can be removed and its physical extents placed back in the empty pool for the volume group. First, the file system will need to be unmounted (if it is mounted). Next, deactive it with lvchange and finally delete it with lvremove. Here is an example that removes the lv_orafra.<\/p>\n<p>[root@testnode1 ~]# umount \/u04\/oracle\/fast_recovery_area<\/p>\n<p>[root@testnode1 ~]# lvchange -a n \/dev\/vg_orafra\/lv_orafra<\/p>\n<p>[root@testnode1 ~]# lvremove \/dev\/vg_orafra\/lv_orafra<br \/>lvremove &#8212; do you really want to remove &#8220;\/dev\/vg_orafra\/lv_orafra&#8221;? [y\/n]: y<br \/>lvremove &#8212; doing automatic backup of volume group &#8220;vg_orafra&#8221;<br \/>lvremove &#8212; logical volume &#8220;\/dev\/vg_orafra\/lv_orafra&#8221; successfully removed<\/p>\n<p>Use the following to delete all physical and logical volumes created in this guide.<\/p>\n<p>[root@testnode1 ~]# umount \/u03\/oracle\/oradata<\/p>\n<p>[root@testnode1 ~]# lvchange -a n \/dev\/vg_oradata\/lv_oradata<br \/>[root@testnode1 ~]# lvremove \/dev\/vg_oradata\/lv_oradata<\/p>\n<p>[root@testnode1 ~]# vgchange -a n \/dev\/vg_oradata<br \/>[root@testnode1 ~]# vgchange -a n \/dev\/vg_orafra<\/p>\n<p>[root@testnode1 ~]# vgremove \/dev\/vg_oradata<br \/>[root@testnode1 ~]# vgremove \/dev\/vg_orafra<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents<\/p>\n<p> Introduction Create Logical Volumes Delete Logical Volumes<\/p>\n<p>Introduction<\/p>\n<p>The following article presents an overview of the commands used to manage physical and logical volumes for use with Logical Volume Manager (LVM) in Linux.<\/p>\n<p>Before considering the various commands for LVM, lets first look at just what is meant by some of the terminology [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1306"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1306"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1306\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1306\/revisions\/1307"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}