Linux LVM簡明教程

本文轉(zhuǎn)自:Linux LVM簡明教程

邏輯卷管理LVM是一個多才多藝的硬盤系統(tǒng)工具愁铺。無論在Linux或者其他類似的系統(tǒng),都是非常的好用稚晚。傳統(tǒng)分區(qū)使用固定大小分區(qū)绎巨,重新調(diào)整大小十分麻煩做祝。但是,LVM可以創(chuàng)建和管理“邏輯”卷鸡岗,而不是直接使用物理硬盤剖淀。可以讓管理員彈性的管理邏輯卷的擴大縮小纤房,操作簡單纵隔,而不損壞已存儲的數(shù)據(jù)∨谝蹋可以隨意將新的硬盤添加到LVM捌刮,以直接擴展已經(jīng)存在的邏輯卷。LVM并不需要重啟就可以讓內(nèi)核知道分區(qū)的存在舒岸。

LVM使用分層結(jié)構(gòu)绅作,如下圖所示。

image

圖中頂部蛾派,首先是實際的物理磁盤及其劃分的分區(qū)和其上的物理卷(PV)俄认。一個或多個物理卷可以用來創(chuàng)建卷組(VG)。然后基于卷組可以創(chuàng)建邏輯卷(LV)洪乍。只要在卷組中有可用空間眯杏,就可以隨心所欲的創(chuàng)建邏輯卷。文件系統(tǒng)就是在邏輯卷上創(chuàng)建的壳澳,然后可以在操作系統(tǒng)掛載和訪問岂贩。

LVM測試說明

本文將介紹怎么在linux中創(chuàng)建和管理LVM卷。我們將會分成兩個部分巷波。第一個部分萎津,我們首先要在一個硬盤上創(chuàng)建多個邏輯卷,然后將它們掛載在/lvm-mount目錄抹镊。然后我們將要對創(chuàng)建好的卷調(diào)整大小锉屈。而第二部分,我們將會從另外一塊硬盤增加額外的卷到LVM中垮耳。

準(zhǔn)備磁盤分區(qū)

通過使用fdisk颈渊,創(chuàng)建磁盤分區(qū)。我們需要創(chuàng)建3個1G分區(qū)氨菇,注意儡炼,并不要求分區(qū)的大小一致。同樣查蓉,分區(qū)需要使用‘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 ## 主分區(qū)

  6. Partition number (1-4): 1 ## 分區(qū)號

  7. First cylinder (1-1044, default 1): ## 回車用默認(rèn)的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 的分區(qū)代碼

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

</pre>

重復(fù)上面的操作來創(chuàng)建其他兩個分區(qū)。分區(qū)創(chuàng)建完成后豌研,我們應(yīng)該有類似如下的輸出:

<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>

準(zhǔn)備物理卷(PV)

剛創(chuàng)建的分區(qū)是用來儲存物理卷的妹田。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>

使用下列命令檢查物理卷的創(chuàng)建情況。下面截取部分輸出鬼佣。"/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>

準(zhǔn)備卷組(VG)

下列命令用來創(chuàng)建名為'volume-group1'的卷組晶衷,使用/dev/sdb1, /dev/sdb2 和 /dev/sdb3創(chuàng)建蓝纲。

<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>

從輸出中晌纫,我們可以看見卷組的使用量/總量税迷。物理卷給卷組提供空間。只要在這個卷組中還有可用空間锹漱,我們就可以隨意創(chuàng)建邏輯卷箭养。

使用下列命令刪除卷組。

<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>

創(chuàng)建邏輯卷(LV)

下列命令創(chuàng)建一個名為'1v1'哥牍、大小為100MB的邏輯卷毕泌。我們使用小分區(qū)減少執(zhí)行時間。這個邏輯卷使用之前創(chuàng)建的卷組的空間嗅辣。

<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>

現(xiàn)在邏輯卷已經(jīng)準(zhǔn)備好了,我們可以格式化和掛載邏輯卷辩诞,就像其它ext2/3/4分區(qū)一樣坎弯!

<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/ 上讀寫了译暂。要創(chuàng)建和掛載其它的邏輯卷,我們重復(fù)這個過程撩炊。

最后外永,使用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卷

調(diào)整邏輯卷大小的功能是LVM最有用的功能拧咳。這個部分會討論我們怎么樣擴展一個存在的邏輯卷伯顶。下面,我們將會擴展先前創(chuàng)建的邏輯卷‘lv1’擴大到200MB骆膝。

注意祭衩,調(diào)整邏輯卷大小之后,也需要對文件系統(tǒng)調(diào)整大小進行匹配阅签。這個額外的步驟各不相同掐暮,取決于創(chuàng)建文件系統(tǒng)的類型。在本文中政钟,我們使用'lv1'創(chuàng)建了ext4類型的文件系統(tǒng)路克,所以這里的操作是針對ext4文件系統(tǒng)的樟结。(ext2/3文件系統(tǒng)也類同)。命令的執(zhí)行順序是很重要的精算。

首先瓢宦,我們卸載掉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>

然后,設(shè)置卷的大小為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>

運行以下命令擴展文件系統(tǒng)以后驮履,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>

現(xiàn)在廉嚼,這個邏輯卷應(yīng)該已經(jīng)擴展到200MB了疲吸。我們檢查LV的狀態(tài)來驗證。

<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>

現(xiàn)在前鹅,這個邏輯卷可以再次掛載摘悴,同樣這個方法也可用于其他分區(qū)。

縮減一個LVM卷

這章節(jié)介紹縮減LVM卷大小的方法舰绘。命令的順序同樣重要蹂喻。并且,下列命令對ext2/3/4文件系統(tǒng)同樣有效捂寿。

注意減少邏輯卷的大小值若小于儲存的數(shù)據(jù)大小口四,存儲在后面的數(shù)據(jù)會丟失。

首先秦陋,卸載掉卷蔓彩。

<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>

接下來縮小文件系統(tǒng)赤嚼,更新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

最后更卒,驗證調(diào)整后的邏輯卷大小。

<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>

擴展一個卷組
本節(jié)將討論擴展卷組的方法稚照,將一個物理卷添加到卷組蹂空。讓我們假設(shè)我們的卷組'volume-group1'已經(jīng)滿了,需要擴大果录。手上的硬盤(sdb)已經(jīng)沒有其他空閑分區(qū)上枕,我們添加了另外一個硬盤(sdc)。我們將看到如何把sdc的分區(qū)添加到卷組以擴展弱恒。

檢測現(xiàn)在卷組狀態(tài)

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
首先辨萍,我們創(chuàng)建一個2GB分區(qū)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!
然后蘸泻,我們創(chuàng)建一個物理卷 /dev/sdc1

pvcreate /dev/sdc1

現(xiàn)在,物理卷已經(jīng)準(zhǔn)備好了嘲玫,我們可以簡單地將它增加到已存在的卷組'volume-group1'上悦施。

vgextend volume-group1 /dev/sdc1

使用vgdisplay來驗證(可以看到卷組大小已經(jīng)增大)。

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’類型的磁盤分區(qū)都可以用來擴展卷組。

總結(jié)一下土陪,LVM是一個非常給力的工具昼汗,用來創(chuàng)建和管理可變大小的分區(qū)。本文中鬼雀,我們已經(jīng)介紹了動態(tài)分區(qū)如何在LVM中創(chuàng)建和使用顷窒。我們也介紹了擴展/縮小邏輯卷和卷組的方法,和如何增加一個新的磁盤到LVM源哩。

希望對你有幫助鞋吉。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市励烦,隨后出現(xiàn)的幾起案子谓着,更是在濱河造成了極大的恐慌,老刑警劉巖坛掠,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赊锚,死亡現(xiàn)場離奇詭異,居然都是意外死亡屉栓,警方通過查閱死者的電腦和手機舷蒲,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來系瓢,“玉大人阿纤,你說我怎么就攤上這事∫穆” “怎么了?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵胰锌,是天一觀的道長骗绕。 經(jīng)常有香客問我,道長资昧,這世上最難降的妖魔是什么酬土? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮格带,結(jié)果婚禮上撤缴,老公的妹妹穿的比我還像新娘刹枉。我一直安慰自己,他們只是感情好屈呕,可當(dāng)我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布微宝。 她就那樣靜靜地躺著,像睡著了一般虎眨。 火紅的嫁衣襯著肌膚如雪蟋软。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天嗽桩,我揣著相機與錄音岳守,去河邊找鬼。 笑死碌冶,一個胖子當(dāng)著我的面吹牛湿痢,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播扑庞,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼譬重,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了嫩挤?” 一聲冷哼從身側(cè)響起害幅,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎岂昭,沒想到半個月后以现,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡约啊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年邑遏,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片恰矩。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡记盒,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出外傅,到底是詐尸還是另有隱情纪吮,我是刑警寧澤,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布萎胰,位于F島的核電站碾盟,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏技竟。R本人自食惡果不足惜冰肴,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧熙尉,春花似錦联逻、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至攀细,卻和暖如春箫踩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背谭贪。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工境钟, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人俭识。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓慨削,卻偏偏與公主長得像,于是被迫代替她去往敵國和親套媚。 傳聞我的和親對象是個殘疾皇子缚态,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內(nèi)容