LVM

基本概念:

         LVM(Logical Volume Manager,邏輯卷管理器)是Linux下對磁盤分區進行管理的一種機制。LVM是建立在磁盤分區和文件系統之間的一個邏輯層,利用LVM可以在磁盤不用重新分區的情況下動態調整分區的大小


術語:

(1)物理存儲設備(physical media):指的是系統的存儲設備文件,如/dev/sda

(2)物理卷(Physical Volume,PV):指的是硬盤分區或從邏輯上看和硬盤分區類似的設備。

(3)卷組(Volume Group,VG):一個LVM卷組由一個或多個物理卷(PV)組成。

(4)邏輯卷(Logical Volume,LV):邏輯卷建立在卷組上,可以在LV上創建文件系統。

(5)PE(Physical Extent):PV中可以分配的最小存儲單元,默認爲4MB

(6)LE(Logical Extent):LV中可以分配的最小存儲單元,同一卷組中,LE的大小和PE是一樣的,且一一對應。


安裝LVM工具

包括lvm、e2fsprogs、xfsprogs

[root@localhost ~]# rpm -qa | grep lvm
mesa-private-llvm-3.5.0-1.el7.x86_64
lvm2-libs-2.02.130-5.el7_2.1.x86_64
lvm2-2.02.130-5.el7_2.1.x86_64
[root@localhost ~]# rpm -qa | grep e2fsprogs
e2fsprogs-libs-1.42.9-7.el7.x86_64
e2fsprogs-1.42.9-7.el7.x86_64
[root@localhost ~]# rpm -qa | grep xfsprogs
xfsprogs-3.2.1-6.el7.x86_64

LVM的創建與管理

1.創建物理分區

          在虛擬機分別掛載兩塊20G硬盤

[root@localhost ~]# fdisk -l
可以查看到新的物理存儲設備/dev/sdb和/dev/sdc

開始進行分區

/dev/sdb硬盤劃分爲一個擴展分區和四個邏輯分區,分區類型均爲Linux KVM(8e)

[root@localhost ~]# fdisk /dev/sdb 
n--> e  --> Enter --> Enter(創建擴展分區)

n --> l --> Enter --> +5G --> t --> 本分區的編號 --> 8e

n --> l --> Enter --> +5G --> t --> 本分區的編號 --> 8e

n --> l --> Enter --> +5G --> t --> 本分區的編號 --> 8e

n --> l --> Enter --> +5G --> t --> 本分區的編號 --> 8e

w

[root@localhost ~]# partx  -a /dev/sdb(兩次)
/dev/sdc硬盤劃分爲一個擴展分區和兩個邏輯分區,分區類型均爲Linux KVM(8e)

[root@localhost ~]# fdisk /dev/sdc
n--> e  --> Enter --> Enter(創建擴展分區)

n --> l --> Enter --> +10G --> t --> 本分區的編號 --> 8e

n --> l --> Enter --> +10G --> t --> 本分區的編號 --> 8e

w

[root@localhost ~]# partx  -a /dev/sdc(兩次)
這裏僅僅進行了分區操作,磁盤分區後沒有格式化


2.創建物理卷

創建物理卷(PV)的命令是pvcreate,可以將希望添加到卷組VG的所有磁盤分區或者整個磁盤創建爲物理卷。

[root@localhost dev]# pvcreate /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8 /dev/sdc5 /dev/sdc6
  Physical volume "/dev/sdb5" successfully created
  Physical volume "/dev/sdb6" successfully created
  Physical volume "/dev/sdb7" successfully created
  Physical volume "/dev/sdb8" successfully created
  Physical volume "/dev/sdc5" successfully created
  Physical volume "/dev/sdc6" successfully created


3.創建卷組

創建卷組(VG)的命令是vgcreate

格式:vgcreate 卷組名 物理卷

[root@localhost dev]# vgcreate myvg1 /dev/sdb5 /dev/sdb6 /dev/sdc5
  Volume group "myvg1" successfully created
[root@localhost dev]# vgcreate myvg2 /dev/sdb7 /dev/sdb8 /dev/sdc6
  Volume group "myvg2" successfully created
創建兩個卷組myvg1和myvg2,卷組myvg1由sdb5、sdb6、sdc5組成;而卷組myvg2由sdb7、sdb8、sdc6組成。


4.激活卷組

卷組(VG)創建完畢後,可以通過vgchange命令激活卷組。

格式:

vgchange -a y 卷組名(激活卷組)
vgchange -a n 卷組名(停用卷組)
[root@localhost dev]# vgchange -a y myvg1
  0 logical volume(s) in volume group "myvg1" now active
[root@localhost dev]# vgchange -a y myvg2
  0 logical volume(s) in volume group "myvg2" now active

5.顯示卷組、物理卷屬性信息

vgdisplay 卷組名
pvdisplay 物理卷名

[root@localhost dev]# vgdisplay myvg1
  --- Volume group ---
  VG Name               myvg1
  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               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5117
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5117 / 19.99 GiB
  VG UUID               ijE12l-SFpo-24u0-cRlU-zPLo-xkKe-L93xqg

6.創建邏輯卷

格式: lvcreate [ -L 邏輯卷大小 | -l PE數 ] -n 邏輯卷名稱 所屬的卷組名

[root@localhost dev]# lvcreate -L 4G -n mylv11 myvg1   通過邏輯卷大小
  Logical volume "mylv11" created.
[root@localhost dev]# vgdisplay myvg1 | grep "Free PE"
[root@localhost dev]# vgdisplay myvg1 | grep "Free  PE"
  Free  PE / Size       4093 / 15.99 GiB
[root@localhost dev]# lvcreate -l 4093 -n mylv12 myvg1  通過PE數量
  Logical volume "mylv12" created.
[root@localhost dev]# vgdisplay myvg2 | grep "Free  PE"
  Free  PE / Size       5116 / 19.98 GiB
[root@localhost dev]# lvcreate -l 5116 -n mylv2 myvg2
  Logical volume "mylv2" created.
在卷組myvg1下創建兩個邏輯卷mylv11和mylv12;在myvg2下創建一個邏輯卷mylv2;


7.格式化邏輯卷,創建文件系統

[root@localhost dev]#  mke2fs -t ext4 -b 1024 -L MYLV11 /dev/myvg1/mylv11
[root@localhost dev]#  mke2fs -t ext4 -b 1024 -L MYLV12 /dev/myvg1/mylv12
[root@localhost dev]#  mke2fs -t ext4 -b 1024 -L MYLV2 /dev/myvg2/mylv2
最後,簡歷掛載目錄,掛載邏輯卷

[root@localhost dev]# mkdir /mylv11
[root@localhost dev]# mkdir /mylv12
[root@localhost dev]# mkdir /mylv2
[root@localhost dev]# mount /dev/myvg1/mylv11 /mylv11
[root@localhost dev]# mount /dev/myvg1/mylv12 /mylv12
[root@localhost dev]# mount /dev/myvg2/mylv2 /mylv2
[root@localhost dev]# df -h | grep mylv
/dev/mapper/myvg1-mylv11  4.0G  3.3M  3.7G    1% /mylv11
/dev/mapper/myvg1-mylv12   16G  3.8M   15G    1% /mylv12
/dev/mapper/myvg2-mylv2    20G  4.3M   19G    1% /mylv2

到這裏爲止,新增的磁盤設備已經可以使用了。


8.添加新的物理捲到卷組

格式:vgextend 卷組名 新加入的物理卷

在虛擬機增加了第四塊硬盤/dev/sdd

<span style="font-size:18px;">[root@localhost ~]# fdisk /dev/sdd </span>
n--> e  --> Enter --> Enter(創建擴展分區)

n --> l --> Enter --> +5G --> t --> 本分區的編號 --> 8e

w

[root@localhost ~]# partx  -a /dev/sdd(兩次)
<pre name="code" class="html">[root@localhost devp]# pvcreate /dev/sdd5
  Physical volume "/dev/sdd5" successfully created
[root@localhost dev]# vgextend myvg2 /dev/sdd5
  Volume group "myvg2" successfully extended
[root@localhost dev]# vgdisplay myvg2 | grep "Free  PE"
  Free  PE / Size       1279 / 5.00 GiB


9.修改邏輯卷大小

LVM最主要的功能就是能動態調整分區的大小,其實就是修改邏輯卷的大小。修改邏輯卷的命令:

lvextend(擴展邏輯卷)、lvreduce(縮減邏輯卷)以及resize2fs(修改文件系統大小)

lvextend [-L (+size) -l (+PE數)] 邏輯卷名稱
lvreduce [-L (-size) -l (-PE數)] 邏輯卷名稱
1)先進行邏輯卷的擴展
[root@localhost dev]# df -h | grep mylv2
/dev/mapper/myvg2-mylv2    20G  4.3M   19G    1% /mylv2
[root@localhost dev]# lvextend -l +1279 /dev/myvg2/mylv2
  Size of logical volume myvg2/mylv2 changed from 19.98 GiB (5116 extents) to 24.98 GiB (6395 extents).
  Logical volume mylv2 successfully resized.
2)修改文件系統大小以實現空間擴展
[root@localhost dev]# resize2fs /dev/myvg2/mylv2  
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg2/mylv2 is mounted on /mylv2; on-line resizing required
old_desc_blocks = 160, new_desc_blocks = 200
The filesystem on /dev/myvg2/mylv2 is now 26193920 blocks long.

[root@localhost dev]# df -h | grep mylv2
/dev/mapper/myvg2-mylv2    25G  3.9M   24G    1% /mylv2
擴展成功了。

減小邏輯空間

[root@localhost dev]# df -h | grep mylv2
/dev/mapper/myvg2-mylv2    25G  3.9M   24G    1% /mylv2
 1)卸載已經掛載的邏輯卷分區
[root@localhost dev]# umount /mylv2
2)執行e2fsck檢查
[root@localhost dev]# e2fsck -f /dev/myvg2/mylv2 
e2fsck 1.42.9 (28-Dec-2013)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結構
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
MYLV2: 11/1637376 files (0.0% non-contiguous), 456029/26193920 blocks
3)修改文件系統大小以實現空間縮減
[root@localhost dev]# resize2fs /dev/myvg2/mylv2 22G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/myvg2/mylv2 to 23068672 (1k) blocks.
The filesystem on /dev/myvg2/mylv2 is now 23068672 blocks long.
4)減小邏輯卷空間
[root@localhost dev]# lvreduce -L -3G /dev/myvg2/mylv2
  WARNING: Reducing active logical volume to 21.98 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv2? [y/n]: y
  Size of logical volume myvg2/mylv2 changed from 24.98 GiB (6395 extents) to 21.98 GiB (5627 extents).
  Logical volume mylv2 successfully resized.
5)掛載邏輯卷分區
[root@localhost dev]# mount /dev/myvg2/mylv2 /mylv2
mount: 文件系統類型錯誤、選項錯誤、/dev/mapper/myvg2-mylv2 上有壞超級塊、
       缺少代碼頁或助手程序,或其他錯誤

       有些情況下在 syslog 中可以找到一些有用信息- 請嘗試
       dmesg | tail  這樣的命令看看。
[root@localhost dev]# mount /dev/myvg2/mylv2 /mylv2
mount: 文件系統類型錯誤、選項錯誤、/dev/mapper/myvg2-mylv2 上有壞超級塊、
       缺少代碼頁或助手程序,或其他錯誤

       有些情況下在 syslog 中可以找到一些有用信息- 請嘗試
       dmesg | tail  這樣的命令看看。

[root@localhost dev]# mke2fs -S /dev/myvg2/mylv2 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標籤=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1441792 inodes, 5762048 blocks
288102 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=4294967296
176 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: 完成                            
Writing superblocks and filesystem accounting information: 完成   

[root@localhost dev]# mke2fs -n /dev/myvg2/mylv2 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標籤=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1441792 inodes, 5762048 blocks
288102 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=4294967296
176 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000
  
[root@localhost dev]# e2fsck -b 32768 /dev/myvg2/mylv2
e2fsck 1.42.9 (28-Dec-2013)
/dev/myvg2/mylv2 contains a file system with errors, 強制檢查.
Resize inode not valid.  重建<y>? 是
第一步: 檢查inode,塊,和大小
根inode不是一個目錄.  清除<y>? 是
Inode 172033 has EXTENTS_FL flag set on 文件系統 without extents support.
清除<y>? 是
Inode 368649 has EXTENTS_FL flag set on 文件系統 without extents support.
清除<y>? 是
Inode 1114129 has EXTENTS_FL flag set on 文件系統 without extents support.
清除<y>? 是
第二步: 檢查目錄結構
第3步: 檢查目錄連接性
根inode not allocated.  分配<y>? 是
/lost+found未找到.創建<y>? 是
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
塊位圖差異:  +(0--1539) +(32768--34306) +(65536--66049) -(73728--75807) +(98304--99842) +(131072--131585) -(139264--141343) +(163840--165378) +(196608--197121) -(204800--206879) +(229376--230914) +(262144--262657) -(270336--272415) +(294912--296450) +(327680--328193) -(335872--337951) +(360448--360961) -(368640--370719) +(393216--393729) -(401408--403487) +(425984--426497) -(434176--436255) +(458752--459265) -(466944--469023) +(491520--492033) -(499712--501791) +(524288--524801) -(532480--534559) +(557056--557569) -(565248--567327) +(589824--590337) -(598016--600095) +(622592--623105) -(630784--632863) +(655360--655873) -(663552--665631) +(688128--688641) -(696320--698399) +(720896--721409) -(729088--731167) +(753664--754177) -(761856--763935) +(786432--786945) -(794624--796703) +(819200--820738) +(851968--852481) -(860160--862239) +(884736--886274) +(917504--918017) -(925696--927775) +(950272--950785) -(958464--960543) +(983040--983553) -(991232--993311) +(1015808--1016321) -(1024000--1026079) +(1048576--1049089) -(1056768--1058847) +(1081344--1081857) -(1089536--1091615) +(1114112--1114625) -(1122304--1124383) +(1146880--1147393) -(1155072--1157151) +(1179648--1180161) -(1187840--1189919) +(1212416--1212929) -(1220608--1222687) +(1245184--1245697) -(1253376--1255455) +(1277952--1278465) -(1286144--1288223) -(1294336--1294752) +(1310720--1311233) -(1318912--1320991) +(1343488--1344001) -(1351680--1353759) +(1376256--1376769) -(1384448--1386527) +(1409024--1409537) -(1417216--1419295) +(1441792--1442305) -(1449984--1452063) +(1474560--1475073) -(1482752--1484831) +(1507328--1507841) -(1515520--1517599) +(1540096--1540609) -(1548288--1550367) +(1572864--1573377) -(1581056--1583135) +(1605632--1607170) +(1638400--1638913) -(1646592--1648671) +(1671168--1671681) -(1679360--1681439) +(1703936--1704449) -(1712128--1714207) +(1736704--1737217) -(1744896--1746975) +(1769472--1769985) -(1777664--1779743) +(1802240--1802753) -(1810432--1812511) +(1835008--1835521) -(1843200--1845279) +(1867776--1868289) -(1875968--1878047) +(1900544--1901057) -(1908736--1910815) +(1933312--1933825) -(1941504--1943583) +(1966080--1966593) -(1974272--1976351) +(1998848--1999361) -(2007040--2009119) +(2031616--2032129) -(2039808--2041887) +(2064384--2064897) -(2072576--2074655) +(2097152--2097665) -(2105344--2107423) +(2129920--2130433) -(2138112--2140191) +(2162688--2163201) -(2170880--2172959) +(2195456--2195969) -(2203648--2205727) +(2228224--2228737) -(2236416--2238495) +(2260992--2261505) -(2269184--2271263) +(2293760--2294273) -(2301952--2304031) +(2326528--2327041) -(2334720--2336799) +(2359296--2359809) -(2367488--2369567) +(2392064--2392577) -(2400256--2402335) +(2424832--2425345) -(2433024--2435103) +(2457600--2458113) -(2465792--2467871) +(2490368--2490881) -(2498560--2500639) +(2523136--2523649) -(2531328--2533407) +(2555904--2556417) -(2564096--2566175) +(2588672--2589185) -(2596864--2598943) -(2605056--2621439) +(2621440--2621953) -(2629632--2631711) +(2654208--2655746) +(2686976--2687489) -(2695168--2697247) +(2719744--2720257) -(2727936--2730015) +(2752512--2753025) -(2760704--2762783) +(2785280--2785793) -(2793472--2795551) +(2818048--2818561) -(2826240--2828319) +(2850816--2851329) -(2859008--2861087) +(2883584--2884097) -(2891776--2893855) +(2916352--2916865) -(2924544--2926623) +(2949120--2949633) -(2957312--2959391) +(2981888--2982401) -(2990080--2992159) +(3014656--3015169) -(3022848--3024927) +(3047424--3047937) -(3055616--3057695) +(3080192--3080705) -(3088384--3090463) +(3112960--3113473) -(3121152--3123231) +(3145728--3146241) -(3153920--3155999) +(3178496--3179009) -(3186688--3188767) +(3211264--3211777) -(3219456--3221535) +(3244032--3244545) -(3252224--3254303) +(3276800--3277313) -(3284992--3287071) +(3309568--3310081) -(3317760--3319839) +(3342336--3342849) -(3350528--3352607) +(3375104--3375617) -(3383296--3385375) +(3407872--3408385) -(3416064--3418143) +(3440640--3441153) -(3448832--3450911) +(3473408--3473921) -(3481600--3483679) +(3506176--3506689) -(3514368--3516447) +(3538944--3539457) -(3547136--3549215) +(3571712--3572225) -(3579904--3581983) +(3604480--3604993) -(3612672--3614751) +(3637248--3637761) -(3645440--3647519) +(3670016--3670529) -(3678208--3680287) +(3702784--3703297) -(3710976--3713055) +(3735552--3736065) -(3743744--3745823) +(3768320--3768833) -(3776512--3778591) +(3801088--3801601) -(3809280--3811359) +(3833856--3834369) -(3842048--3844127) +(3866624--3867137) -(3874816--3876895) +(3899392--3899905) -(3907584--3909663) +(3932160--3932673) -(3940352--3942431) +(3964928--3965441) -(3973120--3975199) +(3997696--3998209) -(4005888--4007967) +(4030464--4030977) -(4038656--4040735) +(4063232--4063745) -(4071424--4073503) +(4096000--4097538) +(4128768--4129281) -(4136960--4139039) +(4161536--4162049) -(4169728--4171807) +(4194304--4194817) -(4202496--4204575) +(4227072--4227585) -(4235264--4237343) +(4259840--4260353) -(4268032--4270111) +(4292608--4293121) -(4300800--4302879) +(4325376--4325889) -(4333568--4335647) +(4358144--4358657) -(4366336--4368415) +(4390912--4391425) -(4399104--4401183) +(4423680--4424193) -(4431872--4433951) +(4456448--4456961) -(4464640--4466719) +(4489216--4489729) -(4497408--4499487) +(4521984--4522497) -(4530176--4532255) +(4554752--4555265) -(4562944--4565023) +(4587520--4588033) -(4595712--4597791) +(4620288--4620801) -(4628480--4630559) +(4653056--4653569) -(4661248--4663327) +(4685824--4686337) -(4694016--4696095) +(4718592--4719105) -(4726784--4728863) +(4751360--4751873) -(4759552--4761631) +(4784128--4784641) -(4792320--4794399) +(4816896--4817409) -(4825088--4827167) +(4849664--4850177) -(4857856--4859935) +(4882432--4882945) -(4890624--4892703) +(4915200--4915713) -(4923392--4925471) -(4931584--4932000) +(4947968--4948481) -(4956160--4958239) +(4980736--4981249) -(4988928--4991007) +(5013504--5014017) -(5021696--5023775) +(5046272--5046785) -(5054464--5056543) +(5079040--5079553) -(5087232--5089311) +(5111808--5112321) -(5120000--5122079) +(5144576--5145089) -(5152768--5154847) +(5177344--5177857) -(5185536--5187615) +(5210112--5210625) -(5218304--5218317) -(5218320--5218333) -(5218336--5220127) +(5242880--5243393) -(5251072--5253151) +(5275648--5276161) -(5283840--5285919) +(5308416--5308929) -(5316608--5318687) +(5341184--5341697) -(5349376--5351455) +(5373952--5374465) -(5382144--5384223) +(5406720--5407233) -(5414912--5416991) +(5439488--5440001) -(5447680--5449759) +(5472256--5472769) -(5480448--5482527) +(5505024--5505537) -(5513216--5515295) +(5537792--5538305) -(5545984--5548063) +(5570560--5571073) -(5578752--5580831) +(5603328--5603841) -(5611520--5613599) +(5636096--5636609) -(5644288--5646367) +(5668864--5669377) -(5677056--5679135) +(5701632--5702145) -(5709824--5711903) +(5734400--5734913) -(5742592--5744671)
處理<y>? 是
Free 塊s count wrong for 簇 #0 (31227, counted=31226).
處理<y>? 是
Free 塊s count wrong (5660307, counted=5660306).
處理<y>? 是
Inode位圖差異:  +1 +(3--10) -(122881--123297) -(647169--655360)
處理<y>? 是
Free inodes count wrong for 簇 #0 (8191, counted=8181).
處理<y>? 是
Directories count wrong for 簇 #0 (1, counted=2).
處理<y>? 是
Free inodes count wrong (1441791, counted=1441781).
處理<y>? 是

/dev/myvg2/mylv2: ***** 文件系統已修改 *****
/dev/myvg2/mylv2: 11/1441792 files (0.0% non-contiguous), 101742/5762048 blocks

[root@localhost dev]# mount /dev/myvg2/mylv2 /mylv2

[root@localhost dev]# df -h | grep mylv2
/dev/mapper/myvg2-mylv2    22G   44M   21G    1% /mylv2
可以看到,邏輯卷分區已經縮小到30GB,但是不建議縮少。


10.刪除物理卷、卷組和邏輯卷

命令 作用
pvremove 刪除物理卷
vgreduce 將物理卷從卷組移除
vgremove 刪除卷組
lvremove 刪除邏輯卷

刪除一個卷組的順序:卸載邏輯卷分區 --> 刪除卷組上所有邏輯卷 --> 刪除卷組。

現在是刪除卷組myvg1

[root@localhost dev]# umount /mylv11  卸載邏輯卷mylv11對應的分區

[root@localhost dev]# lvremove /dev/myvg1/mylv11  刪除邏輯卷mylv11
Do you really want to remove active logical volume mylv11? [y/n]: y
  Logical volume "mylv11" successfully removed

[root@localhost dev]# umount /mylv12   卸載邏輯卷mylv12對應的分區

[root@localhost dev]# lvremove /dev/myvg1/mylv12   刪除邏輯卷mylv12
Do you really want to remove active logical volume mylv12? [y/n]: y
  Logical volume "mylv12" successfully removed
  
[root@localhost dev]# vgreduce myvg1 /dev/sdb5      從卷組myvg1中移除一個物理卷
  Removed "/dev/sdb5" from volume group "myvg1"

[root@localhost dev]# pvremove /dev/sdb5            刪除物理卷/dev/sdb5
  Labels on physical volume "/dev/sdb5" successfully wiped

[root@localhost dev]# vgremove myvg1                刪除卷組myvg1
  Volume group "myvg1" successfully removed


總結:

先分區(fdisk) --> 創建物理卷(pvcreate)--> 創建卷組(vgcreate)--> 激活卷組(vgchange) --> 創建邏輯卷(lvcreate) --> 格式化邏輯卷(mke2fs)  --> 掛載邏輯卷

並且儘量不要使用lvm這類軟件方式的管理器 ,不安全且恢復數據比較難。建議使用btrfs。

PV管理命令

    pvcreate  /dev/sdax 創建pv

    pvs 簡要pv信息

    pvdisplay 詳細pv信息

    pvremove /dev/dev_name 移除pv

VG管理命令

    vgcreate -s #[kKmMgGtTpPeE] VolumeGroupName PhysicalDevicePath... 創建VG

                 -s 指定PE大小

    vgextend VolumeGroupName PhysicalDevicePath...  擴容

    vgreduce VolumeGroupName PhysicalDevicePath...  縮小容量

    vgs、vgdisplay   查看vg

    vgremove  刪除vg

LV管理命令

    lvcreate -L #[mMgGtT] (指明到大小) -n NAME VolumeGroup

    lvextend -L [+]##[mMgGtT]  /dev/VG_NAME/LV_NAME  擴大容量

    lvreduce -L [-]##[mMgGtT]  /dev/VG_NAME/LV_NAME 縮小容量

    lvs、lvdisplay 查看lv

    lvremove 刪除lv

發佈了53 篇原創文章 · 獲贊 19 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章