本文轉(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)绅作,如下圖所示。
圖中頂部蛾派,首先是實際的物理磁盤及其劃分的分區(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;">
-
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;">
Command (m for help): n ## 新建
Command action
e extended
p primary partition (1-4)
p ## 主分區(qū)
Partition number (1-4): 1 ## 分區(qū)號
First cylinder (1-1044, default 1): ## 回車用默認(rèn)的1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +1G ## 大小
Command (m for help): t ## 改變類型
Selected partition 1
Hex code (type L to list codes): 8e ## LVM 的分區(qū)代碼
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;">
-
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;">
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 132 1060258+ 8e Linux LVM
- /dev/sdb2 133 264 1060290 8e Linux LVM
- /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;">
-
pvcreate /dev/sdb1
-
pvcreate /dev/sdb2
-
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;">
-
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;">
- --- NEW Physical volume ---
- PV Name /dev/sdb2
- VG Name
- PV Size 1.01 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- 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;">
-
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;">
-
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;">
-
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;">
- --- Volume group ---
- VG Name volume-group1
- System ID
- Format lvm2
- Metadata Areas 3
- Metadata Sequence No 1
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 0
- 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 0 / 0
- Free PE / Size 774 / 3.02 GiB
- 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;">
-
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;">
-
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;">
-
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;">
- --- Logical volume ---
- LV Name /dev/volume-group1/lv1
- VG Name volume-group1
- LV UUID YNQ1aa-QVt1-hEj6-ArJX-I1Q4-y1h1-OFEtlW
- LV Write Access read/write
- LV Status available
-
open 0
- LV Size 100.00 MiB
- Current LE 25
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- currently set to 256
- 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;">
-
mkfs.ext4 /dev/volume-group1/lv1
-
mkdir /lvm-mount
-
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;">
-
umount /lvm-mount/
-
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;">
-
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;">
-
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;">
-
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;">
-
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;">
-
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;">
- --- Logical volume ---
- LV Name /dev/volume-group1/lv1
- VG Name volume-group1
- LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa
- LV Write Access read/write
- LV Status available
-
open 0
- LV Size 200.00 MiB
- Current LE 50
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- currently set to 256
- 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;">
-
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;">
-
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;">
-
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;">
-
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;">
-
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;">
- --- Logical volume ---
- LV Name /dev/volume-group1/lv1
- VG Name volume-group1
- LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa
- LV Write Access read/write
- LV Status available
-
open 0
- LV Size 100.00 MiB
- Current LE 25
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- currently set to 256
- 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源哩。
希望對你有幫助鞋吉。