52AV手機A片王|52AV.ONE
標題:
LVM 教學
[打印本頁]
作者:
IT_man
時間:
2016-1-20 16:52
標題:
LVM 教學
參考 :
http://linux.vbird.org/linux_basic/0420quota.php#lvm
/ m% w# _7 Q; s& ?. y& X
http://linux.vbird.org/linux_basic/0230filesystem.php#gdisk
* m- P- e% J: G. b. G, r& l
7 J3 k3 W8 K. \
[彈性放大LV容量]
! M1 t3 S! d4 v, |
; m2 @7 C; o3 p1 h
4 M, @) q8 t- g5 n% h3 ^
1) lvextend -l 178813 /dev/11HD_vg/11HD_lv
, [+ J% P9 }8 ]0 G7 b( I
: r$ f8 j1 G; N- l3 ?- G2 L
8 X0 h' U; D9 ?+ f. ?. D
178813是欲加大的size,如2.7T=178813 PE, 1 PE=16MB
; P2 ^3 _' x& n, D
; Z; a3 Z" t# n! L+ K
; b! [5 C# N- u6 p+ e9 a
2)lvresize -l 1966943 /dev/11HD_vg/11HD_lv
* ^( w9 q7 D( O. H
' F* ~) F: }9 y& i, s) t% L
' ^0 L) b% T% K7 z
1966943是加大後的總size,如30T=1966943 PE , 可以用 vgdisplay 11HD_vg 查目前的 vg 詳細資料,包含total size and free size ,單位都是 PE
8 n( ~, x% |8 n
" w! h6 L4 ^1 f) n7 R% f# E( x5 W
5 H' ?, U Q3 a- K O; ~2 O+ Q
3)resize2fs /dev/11HD_vg/11HD_lv
( C( ?" r! [& t* k) L
* r- W6 _0 F8 H: x4 H) U8 T+ k
7 {1 q. U5 Y0 |$ P
P.S
假如找不到gdisk指令,使用 yum install gdisk 安裝
, U5 A3 U8 k) g0 s5 b% R7 }$ c' C
使用 gdisk 分割磁區時,
/ j ?0 i2 n6 S2 O1 ]- N9 W o
Hex code or GUID (L to show codes, Enter = 8300): 輸入8e00 ===> LVM (logical volumn manager)
& f, f4 H" |+ X! |% g' q9 Q
0 R" n- e7 z2 f7 t% j% Y
; g/ o+ y$ B' }& l
[移除pv]
- _8 V! i; Q( {& p( l$ L$ ~
pvscan or pvdisplay 毀損的硬碟會顯示:
( n$ g3 G9 F3 a4 k. r: G
Couldn't find device with uuid WWeM0m-MLX2-o0da-tf7q-fJJu-eiGl-e7UmM3
0 w& D% w9 R) \% n8 t: H
PV Name unknown device
4 B/ p7 m/ h Q6 W) \
+ n; a+ y' q8 D
由於硬碟毀損,紀錄還留在VG內,因此需移除 PV:
. t* e2 f7 _9 y) v" o2 ~& \
vgreduce --removemissing --force 11HD_vg #但也會把所有 LV刪除,故須重建 LV
% M$ Q7 L" R5 U3 }1 E9 M6 V& [; o
pvscan or pvdisplay 就不會顯示 "
unknown device
"
* B! j/ D9 o( G, ^! O+ f
5 j5 t: t4 h* u; I4 u1 `5 x2 R
* r6 I U, M7 k# L8 x
[如何mount 已存在於一顆硬碟內之LVM的partition]
3 w# R+ t V7 N9 ?1 u
#pvscan
+ w2 t0 n% Z# P# @4 X6 P/ Z
PV /dev/sdc2 VG vg_centos6 lvm2 [27.46 GiB / 0 free] <===== 吾人想要mount 的LVM (已存在於別顆硬碟)
+ }# `+ \" j( u7 i; }$ _
PV /dev/sdb2 VG vg_test lvm2 [18.92 GiB / 0 free]
0 @- m1 u4 z& ^
Total: 2 [46.39 GiB] / in use: 2 [46.39 GiB] / in no VG: 0 [0 ]
8 {4 C& B" @3 }, }0 _, f5 X
4 o: D: U% |, _1 q' K
#vgscan
2 T2 |3 M6 \ [1 N
Reading all physical volumes. This may take a while...
+ ^1 a7 J" e" ^- ]0 b& r0 r
Found volume group "vg_centos6" using metadata type lvm2
) W i. V: u* |( {, u
Found volume group "vg_test" using metadata type lvm2
$ s/ i1 F2 _- x6 e2 e
1 E- z0 Z& F0 b
; k! o6 E3 G4 a! S- [1 B, x
#lvscan
% ~3 l3 Y/ p0 A" ~2 g! z
inactive '/dev/vg_centos6/lv_root' [21.84 GiB] inherit <====未啟用
; e7 a% r, a; {( H
inactive '/dev/vg_centos6/lv_swap' [5.62 GiB] inherit <====未啟用
5 @ k. T- x. ?; _2 v% T
ACTIVE '/dev/vg_test/lv_root' [16.98 GiB] inherit
9 ]4 `9 G/ A7 v8 F
ACTIVE '/dev/vg_test/lv_swap' [1.94 GiB] inherit
! @* ~+ O0 l9 U/ r
. f3 g. a& J7 n. s1 H$ h
- o+ Y5 V/ d$ w6 c6 m8 e5 W$ p( `
#lvdisplay /dev/vg_centos6/lv_root
% j2 Q9 h; h2 U8 O) U
--- Logical volume ---
) [& {, Z, |* a" w
LV Path /dev/vg_centos6/lv_root
; M0 ^" x" g- M, L. A6 U: {
LV Name lv_root
/ j2 G* v) |; `( l2 j, {
VG Name vg_centos6
/ u4 F* K9 z( ?2 j0 d8 O( i
LV UUID 0nFiiu-yDQG-1JUB-JI2r-uoTe-Hupi-WGisCe
4 i6 F7 O, E4 q" j% \
LV Write Access read/write
) H. |: u2 T: K. X$ T* a- e
LV Creation host, time ,
% b: ~7 U0 J8 U# r- H" q
LV Status unavailable <==== 不可用
- \0 z1 M$ g. @" ~
# open 1
9 J. j. E% _: @/ B
LV Size 21.84 GiB
1 K) S7 Y5 H; A3 D
Current LE 5591
9 x0 g+ D% S. R+ Y6 ~
Segments 1
3 j8 D$ m) _% [8 b
Allocation inherit
( P: W3 o0 F/ V+ O
Read ahead sectors auto
! \! [& Y0 K( R- A
- currently set to 256
5 c0 u9 W! ]$ @8 g/ ^7 }
Block device 253:2
) ^5 K) `0 |9 K3 t
7 [5 f% n2 {$ n5 \) @$ T
+ J/ l+ z' K' I: P
重點在這裡:
$ u( i3 o8 m# ]5 Q' u2 n8 j& q A
vgchange -ay
vg_centos6 <====== 啟動 VG (假如 關閉VG ==> vgchange -an vg_centos6)
5 q) C" _: e9 \
再查一次 LV:
( G# S9 W. H3 y. T2 h% ]
#lvscan
) T0 ?6 K. r3 e$ h( V1 f9 \7 s
ACTIVE '/dev/vg_centos6/lv_root' [21.84 GiB] inherit <====已啟動了
4 s; ^4 y9 o) I
ACTIVE '/dev/vg_centos6/lv_swap' [5.62 GiB] inherit <====已啟動了
1 R' [! U% }0 E; e# s
ACTIVE '/dev/vg_test/lv_root' [16.98 GiB] inherit
2 n5 T! _# }2 j
ACTIVE '/dev/vg_test/lv_swap' [1.94 GiB] inherit
& J" y6 D, Z! j; |" u+ F! [) A
3 ~. \ i, E0 n" d
6 t, d- t# r p8 v' k$ m2 _+ Y2 P
mount LVM:
; \9 z, ?: T/ i& e
mkdir /mnt/lvmdisk
+ |& P) q! L6 m4 n* o9 I
mount /dev/vg_centos6/lv_root /mnt/lvmdisk
" t# h& k, R- l; m2 `) F' q
大功告成!
, |4 `2 e6 \; R! y& V, [
3 I: m) ~% S' N b8 t
4 E+ @0 N3 `2 K, B# v
歡迎光臨 52AV手機A片王|52AV.ONE (https://www.52av.one/)
Powered by Discuz! X3.2