Linux LVM简明教程

本文转自:Linux LVM简明教程

逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据??梢运嬉饨碌挠才烫砑拥絃VM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。

LVM使用分层结构,如下图所示。

image

图中顶部,首先是实际的物理磁盘及其划分的分区和其上的物理卷(PV)。一个或多个物理卷可以用来创建卷组(VG)。然后基于卷组可以创建逻辑卷(LV)。只要在卷组中有可用空间,就可以随心所欲的创建逻辑卷。文件系统就是在逻辑卷上创建的,然后可以在操作系统挂载和访问。

LVM测试说明

本文将介绍怎么在linux中创建和管理LVM卷。我们将会分成两个部分。第一个部分,我们首先要在一个硬盘上创建多个逻辑卷,然后将它们挂载在/lvm-mount目录。然后我们将要对创建好的卷调整大小。而第二部分,我们将会从另外一块硬盘增加额外的卷到LVM中。

准备磁盘分区

通过使用fdisk,创建磁盘分区。我们需要创建3个1G分区,注意,并不要求分区的大小一致。同样,分区需要使用‘8e’类型来使他们可用于LVM。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. fdisk /dev/sdb

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. Command (m for help): n ## 新建

  2. Command action

  3. e extended

  4. p primary partition (1-4)

  5. p ## 主分区

  6. Partition number (1-4): 1 ## 分区号

  7. First cylinder (1-1044, default 1): ## 回车用默认的1

  8. Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +1G ## 大小

  9. Command (m for help): t ## 改变类型

  10. Selected partition 1

  11. Hex code (type L to list codes): 8e ## LVM 的分区代码

  12. Changed system type of partition 1 to 8e (Linux LVM)

</pre>

重复上面的操作来创建其他两个分区。分区创建完成后,我们应该有类似如下的输出:

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. fdisk -l

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. Device Boot Start End Blocks Id System
  2. /dev/sdb1 1 132 1060258+ 8e Linux LVM
  3. /dev/sdb2 133 264 1060290 8e Linux LVM
  4. /dev/sdb3 265 396 1060290 8e Linux LVM

</pre>

准备物理卷(PV)

刚创建的分区是用来储存物理卷的。LVM可以使用不同大小的物理卷。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. pvcreate /dev/sdb1

  2. pvcreate /dev/sdb2

  3. pvcreate /dev/sdb3

</pre>

使用下列命令检查物理卷的创建情况。下面截取部分输出。"/dev/sdb2"是一个新的"1.01 GiB"物理卷。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. pvdisplay

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --- NEW Physical volume ---
  2. PV Name /dev/sdb2
  3. VG Name
  4. PV Size 1.01 GiB
  5. Allocatable NO
  6. PE Size 0
  7. Total PE 0
  8. Free PE 0
  9. Allocated PE 0
  10. PV UUID jszvzz-ENA2-g5Pd-irhV-T9wi-ZfA3-0xo092

</pre>

使用下列命令可以删除物理卷。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. pvremove /dev/sdb1

</pre>

准备卷组(VG)

下列命令用来创建名为'volume-group1'的卷组,使用/dev/sdb1, /dev/sdb2 和 /dev/sdb3创建。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. vgcreate volume-group1 /dev/sdb1 /dev/sdb2 /dev/sdb3

</pre>

使用下列命令可以来验证卷组。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. vgdisplay

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --- Volume group ---
  2. VG Name volume-group1
  3. System ID
  4. Format lvm2
  5. Metadata Areas 3
  6. Metadata Sequence No 1
  7. VG Access read/write
  8. VG Status resizable
  9. MAX LV 0
  10. Cur LV 0
  11. Open LV 0
  12. Max PV 0
  13. Cur PV 3
  14. Act PV 3
  15. VG Size 3.02 GiB
  16. PE Size 4.00 MiB
  17. Total PE 774
  18. Alloc PE / Size 0 / 0
  19. Free PE / Size 774 / 3.02 GiB
  20. VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK

</pre>

从输出中,我们可以看见卷组的使用量/总量。物理卷给卷组提供空间。只要在这个卷组中还有可用空间,我们就可以随意创建逻辑卷。

使用下列命令删除卷组。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. vgremove volume-group1

</pre>

创建逻辑卷(LV)

下列命令创建一个名为'1v1'、大小为100MB的逻辑卷。我们使用小分区减少执行时间。这个逻辑卷使用之前创建的卷组的空间。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvcreate -L 100M -n lv1 volume-group1

</pre>

逻辑卷可使用lvdisplay命令查看。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvdisplay

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --- Logical volume ---
  2. LV Name /dev/volume-group1/lv1
  3. VG Name volume-group1
  4. LV UUID YNQ1aa-QVt1-hEj6-ArJX-I1Q4-y1h1-OFEtlW
  5. LV Write Access read/write
  6. LV Status available
  7. open 0

  8. LV Size 100.00 MiB
  9. Current LE 25
  10. Segments 1
  11. Allocation inherit
  12. Read ahead sectors auto
    • currently set to 256
  13. Block device 253:2

</pre>

现在逻辑卷已经准备好了,我们可以格式化和挂载逻辑卷,就像其它ext2/3/4分区一样!

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. mkfs.ext4 /dev/volume-group1/lv1

  2. mkdir /lvm-mount

  3. mount /dev/volume-group1/lv1 /lvm-mount/

</pre>

一旦逻辑卷挂载,我们就可以到挂载点 /lvm-mount/ 上读写了。要创建和挂载其它的逻辑卷,我们重复这个过程。

最后,使用lvremove我们可以删除逻辑卷。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. umount /lvm-mount/

  2. lvremove /dev/volume-group1/lv1

</pre>

扩展一个LVM卷

调整逻辑卷大小的功能是LVM最有用的功能。这个部分会讨论我们怎么样扩展一个存在的逻辑卷。下面,我们将会扩展先前创建的逻辑卷‘lv1’扩大到200MB。

注意,调整逻辑卷大小之后,也需要对文件系统调整大小进行匹配。这个额外的步骤各不相同,取决于创建文件系统的类型。在本文中,我们使用'lv1'创建了ext4类型的文件系统,所以这里的操作是针对ext4文件系统的。(ext2/3文件系统也类同)。命令的执行顺序是很重要的。

首先,我们卸载掉lv1卷

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. umount /lvm-mount/

</pre>

然后,设置卷的大小为200M

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvresize -L 200M /dev/volume-group1/lv1

</pre>

接下来,检查磁盘错误

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. e2fsck -f /dev/volume-group1/lv1

</pre>

运行以下命令扩展文件系统以后,ext4信息就更新了。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. resize2fs /dev/volume-group1/lv1

</pre>

现在,这个逻辑卷应该已经扩展到200MB了。我们检查LV的状态来验证。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvdisplay

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --- Logical volume ---
  2. LV Name /dev/volume-group1/lv1
  3. VG Name volume-group1
  4. LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa
  5. LV Write Access read/write
  6. LV Status available
  7. open 0

  8. LV Size 200.00 MiB
  9. Current LE 50
  10. Segments 1
  11. Allocation inherit
  12. Read ahead sectors auto
    • currently set to 256
  13. Block device 253:2

</pre>

现在,这个逻辑卷可以再次挂载,同样这个方法也可用于其他分区。

缩减一个LVM卷

这章节介绍缩减LVM卷大小的方法。命令的顺序同样重要。并且,下列命令对ext2/3/4文件系统同样有效。

注意减少逻辑卷的大小值若小于储存的数据大小,存储在后面的数据会丢失。

首先,卸载掉卷。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. umount /dev/volume-group1/lv1

</pre>

然后,检测磁盘错误。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. e2fsck -f /dev/volume-group1/lv1

</pre>

接下来缩小文件系统,更新ext4信息。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. resize2fs /dev/volume-group1/lv1 100M

</pre>

完成以后,减少逻辑卷大小

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvresize -L 100M /dev/volume-group1/lv1

</pre>

WARNING: Reducing active logical volume to 100.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv1? [y/n]: y Reducing logical volume lv1 to 100.00 MiB Logical volume lv1 successfully resized

最后,验证调整后的逻辑卷大小。

<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. lvdisplay

</pre>


<pre class="prettyprint linenums prettyprinted" style="word-wrap: break-word; background-color: rgb(22, 27, 32); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAICAYAAAA4GpVBAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GBgMqHcZ0EYUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAF0lEQVQI12NgYGAwZsAECDEWBgYGBgYACpwAazfG694AAAAASUVORK5CYII="); font-size: 14px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 5px; text-shadow: rgb(0, 0, 0) 0px 1px 1px; border-radius: 6px; color: rgb(184, 255, 184); margin: 10px; padding: 1em 1em 1em 2em; white-space: pre-wrap; border: 1px solid rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --- Logical volume ---
  2. LV Name /dev/volume-group1/lv1
  3. VG Name volume-group1
  4. LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa
  5. LV Write Access read/write
  6. LV Status available
  7. open 0

  8. LV Size 100.00 MiB
  9. Current LE 25
  10. Segments 1
  11. Allocation inherit
  12. Read ahead sectors auto
    • currently set to 256
  13. Block device 253:2

</pre>

扩展一个卷组
本节将讨论扩展卷组的方法,将一个物理卷添加到卷组。让我们假设我们的卷组'volume-group1'已经满了,需要扩大。手上的硬盘(sdb)已经没有其他空闲分区,我们添加了另外一个硬盘(sdc)。我们将看到如何把sdc的分区添加到卷组以扩展。

检测现在卷组状态

vgdisplay volume-group1

--- Volume group ---
VG Name volume-group1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 3.02 GiB
PE Size 4.00 MiB
Total PE 774
Alloc PE / Size 25 / 100.00 MiB
Free PE / Size 749 / 2.93 GiB
VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
首先,我们创建一个2GB分区sdc1,类型为LVM(8e),如教程前所述。

fdisk /dev/sdc

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!
然后,我们创建一个物理卷 /dev/sdc1

pvcreate /dev/sdc1

现在,物理卷已经准备好了,我们可以简单地将它增加到已存在的卷组'volume-group1'上。

vgextend volume-group1 /dev/sdc1

使用vgdisplay来验证(可以看到卷组大小已经增大)。

vgdisplay

--- Volume group ---
VG Name volume-group1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 4
Act PV 4
VG Size 5.03 GiB
PE Size 4.00 MiB
Total PE 1287
Alloc PE / Size 25 / 100.00 MiB
Free PE / Size 1262 / 4.93 GiB
VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
注意,尽管我们使用一个单独的磁盘做示范,其实只要是‘8e’类型的磁盘分区都可以用来扩展卷组。

总结一下,LVM是一个非常给力的工具,用来创建和管理可变大小的分区。本文中,我们已经介绍了动态分区如何在LVM中创建和使用。我们也介绍了扩展/缩小逻辑卷和卷组的方法,和如何增加一个新的磁盘到LVM。

希望对你有帮助。

?著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,100评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,308评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事?!?“怎么了?”我有些...
    开封第一讲书人阅读 159,718评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,275评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,376评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,454评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,464评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,248评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,686评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,974评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,150评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,817评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,484评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,140评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,374评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,012评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,041评论 2 351

推荐阅读更多精彩内容