Build LVM

<p class="shortdesc"></p> <p class="p">The LVM architecture diagram in the previous chapter shows the procedures of managing EBS disks through LVM are as follows: </p> <ol class="ol" id="BuildLVM__ol_yqt_vss_slb"> <li class="li"><a class="xref" href="#BuildLVM__p_xhm_xvj_tlb">Install LVM</a>. </li> <li class="li"><a class="xref" href="#BuildLVM__p_sx1_jsj_tlb">Create physical volumes for EBS disks</a>. </li> <li class="li"><a class="xref" href="#BuildLVM__p_tnv_xvj_tlb">Create a volume group for the physical volumes</a>. </li> <li class="li"><a class="xref" href="#BuildLVM__p_cgc_yvj_tlb">Create logical volumes in the volume group</a>. </li> <li class="li"><a class="xref" href="#BuildLVM__p_hhh_yvj_tlb">Create file systems on logical volumes</a>. </li> </ol> <section class="section" id="BuildLVM__section_lcb_mx3_tlb"><h2 class="doc-tairway">Background Information</h2> <p class="p">This chapter takes three EBS disks, namely /dev/vdb, /dev/vdc, and /dev/vdd, as examples to illustrate how to create LVM. As shown below, the system has mounted with three EBS disks, and each of them is roughly 20GB in size. </p> <img class="image" id="BuildLVM__image_t3n_xrj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171842-1e8b35809223.png"> </section> <section class="section" id="BuildLVM__section_gkz_mx3_tlb"><h2 class="doc-tairway">Prerequisites</h2> <p class="p">You have created EBS disks and mounted them to the corresponding cloud servers. For more information, see <span class="xref">Create an EBS Disk</span>. </p> </section> <section class="section" id="BuildLVM__section_kdt_nx3_tlb"><h2 class="doc-tairway">Usage Guidelines </h2> <p class="p">When a single instance has mounted with multiple EBS disks to create LVM, snapshots can only be created for each independent EBS disk. Therefore, after using LVM, you may cause data differences when using snapshots to roll back the EBS disk. </p> </section> <section class="section" id="BuildLVM__section_cj2_4x3_tlb"><h2 class="doc-tairway">Procedures</h2> <p class="p" id="BuildLVM__p_xhm_xvj_tlb"><strong class="ph b">Step 1: Install LVM</strong></p> <ol class="ol" id="BuildLVM__ol_jgv_csj_tlb"> <li class="li">Run the following command to check whether LVM is installed. <pre class="pre codeblock"><code>rpm -qa |grep 1vm2</code></pre><ul class="ul" id="BuildLVM__ul_j5w_2sj_tlb"> <li class="li">If the following information is displayed, LVM has been installed. Skip Step 1 and go to <a class="xref" href="#BuildLVM__p_sx1_jsj_tlb">Step 2</a>. <img class="image" id="BuildLVM__image_gyq_kwj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-13ab74c49051.png"></li> <li class="li">If the above information is not displayed, go to <a class="xref" href="#BuildLVM__p_sx1_jsj_tlb">Step 2</a>.</li> </ul></li> <li class="li">Run the following command to install LVM.<pre class="pre codeblock"><code>yum install 1vm2</code></pre><p class="p">When the following information is displayed, LVM is successfully installed.</p><img class="image" id="BuildLVM__image_izf_mwj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-103e504f9be5.png"></li> </ol> <p class="p" id="BuildLVM__p_sx1_jsj_tlb"><strong class="ph b">Step 2: Create physical volumes for EBS disks</strong></p> <ol class="ol" id="BuildLVM__ol_m4t_wtj_tlb"> <li class="li">Log in to the cloud server as user root.</li> <li class="li">Run the following command to view the EBS disks mounted to the current device. <pre class="pre codeblock"><code>fdisk -l</code></pre><img class="image" id="BuildLVM__image_jfg_nwj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-11c3ae80980a.png"><p class="p">In the above information displayed, we can see three EBS disks are mounted to the current system, namely /dev/vdb, /dev/vdc, and /dev/vdd. </p></li> <li class="li">Create physical volumes for all partitions or EBS disks you want to add to the volume group. The command of creating physical volumes for the entire disk is:<pre class="pre codeblock"><code>pvcreate <Disk device name 1> <Disk device name 2>… <Disk device name n></code></pre><p class="p">Separate multiple disks with spaces. </p><p class="p">In this example, run the command <code class="ph codeph">pvcreate /dev/vdb /dev/vdc /dev/vdd</code>, and the following information is displayed. </p><img class="image" id="BuildLVM__image_f2h_4wj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-136ddcc6922a.png"></li> <li class="li">Run the following command to view details of the newly created physical volumes. <pre class="pre codeblock"><code>pvdisplay</code></pre><img class="image" id="BuildLVM__image_ctx_4wj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-16874bff9670.png"><p class="p">In the information displayed, we can see the three new physical volumes, namely /dev/vdb, /dev/vdc, and /dev/vdd.</p></li> </ol> <p class="p" id="BuildLVM__p_tnv_xvj_tlb"><strong class="ph b">Step 3: Create a volume group </strong></p> <ol class="ol" id="BuildLVM__ol_ghn_25j_tlb"> <li class="li">Create a volume group for the physical volumes.<pre class="pre codeblock"><code>vgcreate <Volume group name> <Physical volume name 1> <Physical volume name 2>...<Physical volume name n> </code></pre><p class="p">In this example, run the command <code class="ph codeph">vgcreate lvm_example /dev/vdb /dev/vdc /dev/vdd</code>. </p><img class="image" id="BuildLVM__image_iyz_pwj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-16f3969a9c92.png"><p class="p">If the above prompt is displayed, the volume group is successfully created. </p></li> <li class="li">View details of the volume group. <pre class="pre codeblock"><code>vgdisplay</code></pre><img class="image" id="BuildLVM__image_ccx_qwj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-194869c89cc9.png"></li> <li class="li">(Optional) If you want to add a new physical volume to the volume group that has been created, run the following command. <pre class="pre codeblock"><code>vgextend <Volume group name> <Physical volume name 1></code></pre></li> </ol> <p class="p" id="BuildLVM__p_cgc_yvj_tlb"><strong class="ph b">Step 4: Create a logical volume in the volume group</strong></p> <ol class="ol" id="BuildLVM__ol_gqc_gvj_tlb"> <li class="li">Create a logical volume. <pre class="pre codeblock"><code>Lvcreate -L <Logical volume size> -n <Logical volume name> <Volume group name> </code></pre><p class="p">In this example, run the command <code class="ph codeph">lvcreate -L 20G -n lv1 lvm_example</code>. </p><img class="image" id="BuildLVM__image_tzc_ywj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-1ebe70559ade.png"></li> <li class="li">View details of the logical volume. <pre class="pre codeblock"><code>1vdisplay</code></pre><img class="image" id="BuildLVM__image_pdw_ywj_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-10415e67937a.png"></li> </ol> <p class="p" id="BuildLVM__p_hhh_yvj_tlb"><strong class="ph b">Step 5: Create and mount a file system </strong></p> <ol class="ol" id="BuildLVM__ol_k1q_kvj_tlb"> <li class="li">Create a file system. <pre class="pre codeblock"><code>mkfs. <File system format> <Logical volume path> </code></pre><p class="p">In this example, run the command <code class="ph codeph">mkfs.ext3 /dev/lvm_example/lv1</code>. </p></li> <li class="li">Create a mount directory. <pre class="pre codeblock"><code>mkdir <Mount directory> </code></pre><p class="p">For example, run the command: </p><pre class="pre codeblock"><code>mkdir /Data</code></pre></li> <li class="li">Mount the logical volume.<pre class="pre codeblock"><code>mount <Logical volume path> <Mount directory> </code></pre><p class="p">For example, run the command: </p><pre class="pre codeblock"><code>mount /dev/lvm_example/1v1 /Data</code></pre></li> <li class="li">Check whether the mount succeeds. <pre class="pre codeblock"><code>df -h</code></pre><img class="image" id="BuildLVM__image_dyz_qn4_tlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171843-1252357e9f45.png" width="800"><p class="p">You can see the logical volume has been successfully mounted to the /Data. </p></li> </ol> </section>
Did the above content solve your problem? Yes No
Please complete information!

Call us

400-151-8800

Email us

cloud@pingan.com

Online customer service

Instant reply

Technical Support

cloud products