一、LVM概念
LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。通过LVM系统管理员可以轻松管理磁盘分区,如:将若干个磁盘分区连接为一个整块的卷组(volume group),形成一个存储池。管理员可以在卷组上随意创建逻辑卷组(logical volumes),并进一步在逻辑卷组上创建文件系统。管理员通过LVM可以方便的调整存储卷组的大小,并且可以对磁盘存储按照组的方式进行命名、管理和分配。当系统添加了新的磁盘,通过LVM管理员就不必将磁盘的文件移动到新的磁盘上以充分利用新的存储空间,而是直接扩展文件系统跨越磁盘即可。
二、LVM结构
物理存储介质(The physical media)
这里指系统的存储设备:硬盘,如:/dev/hda、/dev/sda等等,是存储系统最低层的存储单元。
物理卷PV(physical volume)
物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
卷组VG(Volume Group)
LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷PV组成。可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷PV组成。
物理块PE(physical extent)
每一个物理卷PV被划分为被称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。
逻辑块LE(logical extent)
逻辑卷也被划分为被称为逻辑块LE的可被寻址的基本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
逻辑卷LV(logical volume)
LVM的逻辑卷类似于非LVM系统中的硬盘分区,在VG上面割取PE就组成了LV,是一个标准的块设备,可以在其上建立文件系统(比如/home或者/usr等)。
Tips:从一块硬盘到能使用LV文件系统的步骤:硬盘→分区→(PV→VG→LV)→格式化(LV为ext文件系统)→挂载
三、创建LV
创建LV前需要创建VG,而创建VG前需要创建PV,所以我们要先创建PV再创建VG最后再创建LV,这里利用/dev/sdb盘来创建
创建PV:pvcreate /dev/sdbx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
[root@justin ~]
# fdisk -l
Disk
/dev/sda
: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors
/track
, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x000661de
Device Boot Start End Blocks Id System
/dev/sda1
* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2
26 1332 10485760 83 Linux
/dev/sda3
1332 1593 2097152 82 Linux swap / Solaris
/dev/sda4
1593 2611 8182784 5 Extended
/dev/sda5
1593 2611 8181760 83 Linux
Disk
/dev/sdb
: 5368 MB, 5368709120 bytes
255 heads, 63 sectors
/track
, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@justin ~]
# fdisk /dev/sdb
Command (m
for
help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
Using default value 652
Command (m
for
help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +3G
Command (m
for
help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (394-652, default 394):
Using default value 394
Last cylinder, +cylinders or +size{K,M,G} (394-652, default 652):
Using default value 652
Command (m
for
help): p
Disk
/dev/sdb
: 5368 MB, 5368709120 bytes
255 heads, 63 sectors
/track
, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0xd58eff7b
Device Boot Start End Blocks Id System
/dev/sdb4
1 652 5237158+ 5 Extended
/dev/sdb5
1 393 3156709+ 83 Linux
/dev/sdb6
394 652 2080386 83 Linux
Command (m
for
help): t
Partition number (1-6): 5
Hex code (
type
L to list codes): 8e
Changed system
type
of partition 5 to 8e (Linux LVM)
Command (m
for
help): t
Partition number (1-6): 6
Hex code (
type
L to list codes): 8e
Changed system
type
of partition 6 to 8e (Linux LVM)
Command (m
for
help): p
Disk
/dev/sdb
: 5368 MB, 5368709120 bytes
255 heads, 63 sectors
/track
, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0xd58eff7b
Device Boot Start End Blocks Id System
/dev/sdb4
1 652 5237158+ 5 Extended
/dev/sdb5
1 393 3156709+ 8e Linux LVM
/dev/sdb6
394 652 2080386 8e Linux LVM
Command (m
for
help): w
The partition table has been altered!
Calling ioctl() to re-
read
partition table.
Syncing disks.
[root@justin ~]
# pvcreate /dev/sdb5 /dev/sdb6
Writing physical volume data to disk
"/dev/sdb5"
Physical volume
"/dev/sdb5"
successfully created
Writing physical volume data to disk
"/dev/sdb6"
Physical volume
"/dev/sdb6"
successfully created
[root@justin ~]
# partprobe /dev/sdb ;使用工具partprobe让kernel读取分区信息
[root@justin ~]
# fdisk -l
Disk
/dev/sda
: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors
/track
, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x000661de
Device Boot Start End Blocks Id System
/dev/sda1
* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2
26 1332 10485760 83 Linux
/dev/sda3
1332 1593 2097152 82 Linux swap / Solaris
/dev/sda4
1593 2611 8182784 5 Extended
/dev/sda5
1593 2611 8181760 83 Linux
Disk
/dev/sdb
: 5368 MB, 5368709120 bytes
255 heads, 63 sectors
/track
, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0xd58eff7b
Device Boot Start End Blocks Id System
/dev/sdb4
1 652 5237158+ 5 Extended
/dev/sdb5
1 393 3156709+ 8e Linux LVM
/dev/sdb6
394 652 2080386 8e Linux LVM
[root@justin ~]
# pvdisplay ;查看PV信息
"/dev/sdb5"
is a new physical volume of
"3.01 GiB"
--- NEW Physical volume ---
PV Name
/dev/sdb5
VG Name
PV Size 3.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Pz14Rv-2Ngu-lbdD-5dgF-CLU1-cQ9p-bDAf52
"/dev/sdb6"
is a new physical volume of
"1.98 GiB"
--- NEW Physical volume ---
PV Name
/dev/sdb6
VG Name
PV Size 1.98 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 9sIqz9-iXNv-kloo-p55V-ZzMT-eGD0-Tf2iEn
[root@justin ~]
#
|
VG创建:vgcreate 卷组名 物理卷
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@justin ~]
# vgcreate VGtest /dev/sdb5 /dev/sdb6
Volume group
"VGtest"
successfully created
[root@justin ~]
# vgdisplay
--- Volume group ---
VG Name VGtest
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 4.99 GiB
PE Size 4.00 MiB
Total PE 1277
Alloc PE / Size 0 / 0
Free PE / Size 1277 / 4.99 GiB
VG UUID TmBe8X-wSlx-uJDy-1f0W-m4yj-31E7-zPtyqS
[root@justin ~]
#
|
创建LV:lvcreate -L 大小 卷组名 -n 逻辑卷名称
-L:指定逻辑卷大小 -n:指定逻辑卷名称
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
[root@justin ~]
# lvcreate -L 4G VGtest -n LVtest
Logical volume
"LVtest"
created
[root@justin ~]
# lvdisplay
--- Logical volume ---
LV Path
/dev/VGtest/LVtest
LV Name LVtest
VG Name VGtest
LV UUID nBIB0X-1ZON-hFhv-oDF3-8Dfb-61Vt-AeiGUM
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:22:00 +0800
LV Status available
# open 0
LV Size 4.00 GiB
Current LE 1024
Segments 2
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:0
[root@justin ~]
# lvcreate -L 1G VGtest -n LVtest1
Volume group
"VGtest"
has insufficient
free
space (253 extents): 256 required.
[root@justin ~]
# lvcreate -L VGtest -n LVtest1
Invalid argument
for
--size: VGtest
Error during parsing of
command
line.
[root@justin ~]
# lvcreate -L 256M VGtest -n LVtest1
Logical volume
"LVtest1"
created
[root@justin ~]
# lvdisplay
--- Logical volume ---
LV Path
/dev/VGtest/LVtest
LV Name LVtest
VG Name VGtest
LV UUID nBIB0X-1ZON-hFhv-oDF3-8Dfb-61Vt-AeiGUM
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:22:00 +0800
LV Status available
# open 0
LV Size 4.00 GiB
Current LE 1024
Segments 2
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:0
--- Logical volume ---
LV Path
/dev/VGtest/LVtest1
LV Name LVtest1
VG Name VGtest
LV UUID 6AggK6-XjPH-Jgt0-A4pI-2Fnw-cHKf-hM5mba
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:23:00 +0800
LV Status available
# open 0
LV Size 256.00 MiB
Current LE 64
Segments 1
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:1
[root@justin ~]
#
|
格式化和挂载:mkfs [-t 系统类型] 分区 、mkfs.extn 分区 mount [-t 系统类型] 要挂载的分区 挂载到的分区
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
[root@justin ~]
# mkfs.ext4 /dev/VGtest/LVtest ;对应LV Path名称
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048576 blocks
52428 blocks (5.00%) reserved
for
the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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
Writing inode tables:
done
Creating journal (32768 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@justin ~]
# mkfs -t ext4 /dev/VGtest/LVtest1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved
for
the super user
First data block=1
Maximum filesystem blocks=67371008
32 block
groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables:
done
Creating journal (8192 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@justin ~]
# mkdi
mkdict
mkdir
[root@justin ~]
# mkdir /mnt/{sdb5,sdb6}
[root@justin ~]
# mount -t ext4 /dev/VGtest/LVtest /mnt/sdb5
[root@justin ~]
# mount -t ext4 /dev/VGtest/LVtest1 /mnt/sdb6
[root@justin ~]
# [root@justin ~]# vim /etc/fstab
proc
/proc
proc defaults 0 0
/dev/VGtest/LVtest
/mnt/sdb5
ext4 defaults 0 0
/dev/VGtest/LVtest1
/mnt/sdb6
ext4 defaults 0 0
|
Tips:查看到lv的信息,可以通过fdisk -、lvdisply、/etc/fsta、df -Th或者mount查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
[root@justin ~]
# fdisk -l
Disk
/dev/sda
: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors
/track
, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x000661de
Device Boot Start End Blocks Id System
/dev/sda1
* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2
26 1332 10485760 83 Linux
/dev/sda3
1332 1593 2097152 82 Linux swap / Solaris
/dev/sda4
1593 2611 8182784 5 Extended
/dev/sda5
1593 2611 8181760 83 Linux
Disk
/dev/sdb
: 5368 MB, 5368709120 bytes
255 heads, 63 sectors
/track
, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0xd58eff7b
Device Boot Start End Blocks Id System
/dev/sdb4
1 652 5237158+ 5 Extended
/dev/sdb5
1 393 3156709+ 8e Linux LVM
/dev/sdb6
394 652 2080386 8e Linux LVM
Disk
/dev/mapper/VGtest-LVtest
: 4294 MB, 4294967296 bytes
255 heads, 63 sectors
/track
, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk
/dev/mapper/VGtest-LVtest1
: 268 MB, 268435456 bytes
255 heads, 63 sectors
/track
, 32 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@justin ~]
# lvdisplay
--- Logical volume ---
LV Path
/dev/VGtest/LVtest
LV Name LVtest
VG Name VGtest
LV UUID nBIB0X-1ZON-hFhv-oDF3-8Dfb-61Vt-AeiGUM
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:22:00 +0800
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 2
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:0
--- Logical volume ---
LV Path
/dev/VGtest/LVtest1
LV Name LVtest1
VG Name VGtest
LV UUID 6AggK6-XjPH-Jgt0-A4pI-2Fnw-cHKf-hM5mba
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:23:00 +0800
LV Status available
# open 1
LV Size 256.00 MiB
Current LE 64
Segments 1
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:1
[root@justin ~]
# mount|grep LVtest
/dev/mapper/VGtest-LVtest
on
/mnt/sdb5
type
ext4 (rw)
/dev/mapper/VGtest-LVtest1
on
/mnt/sdb6
type
ext4 (rw)
[root@justin ~]
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2
ext4 9.9G 2.5G 7.0G 26% /
tmpfs tmpfs 504M 0 504M 0%
/dev/shm
/dev/sda1
ext4 194M 27M 158M 15%
/boot
/dev/sda5
ext4 7.7G 146M 7.2G 2%
/home
/dev/mapper/VGtest-LVtest
ext4 4.0G 136M 3.7G 4%
/mnt/sdb5
/dev/mapper/VGtest-LVtest1
ext4 248M 11M 226M 5%
/mnt/sdb6
[root@justin ~]
#
|
至此,LV创建完毕
四、扩展
将/dev/VGtest/LVtest1从256M扩展到3G,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@justin ~]
# vgdisplay
--- Volume group ---
VG Name VGtest
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access
read
/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 4.99 GiB ;VG总大小
PE Size 4.00 MiB
Total PE 1277
Alloc PE / Size 1088 / 4.25 GiB ;已分配的VG大小
Free PE / Size 189 / 756.00 MiB
VG UUID TmBe8X-wSlx-uJDy-1f0W-m4yj-31E7-zPtyqS
|
VG大小不足以将/dev/VGtest/LVtest1扩展到3G,所以扩展LV前先要扩展VG大小
VG扩展
格式:vgextend 卷组名 物理卷
扩展VG要先创建PV,之前的硬盘空间已用完需要重新添加一块硬盘/dev/sdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
[root@justin ~]
# pvcreate /dev/sdc1
Writing physical volume data to disk
"/dev/sdc1"
Physical volume
"/dev/sdc1"
successfully created
[root@justin ~]
# vgextend VGtest /dev/sdc1 ;将pv/dev/sdc1加入VG组VGtest里
Volume group
"VGtest"
successfully extended
[root@justin ~]
# vgdisplay
--- Volume group ---
VG Name VGtest
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access
read
/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 8.98 GiB
PE Size 4.00 MiB
Total PE 2300
Alloc PE / Size 1088 / 4.25 GiB
Free PE / Size 1212 / 4.73 GiB
VG UUID TmBe8X-wSlx-uJDy-1f0W-m4yj-31E7-zPtyqS
[root@justin ~]
# vgs
VG
#PV #LV #SN Attr VSize VFree
VGtest 3 2 0 wz--n- 8.98g 4.73g
[root@justin ~]
# vgs VGtest ;查看指定VG信息
VG
#PV #LV #SN Attr VSize VFree
VGtest 3 2 0 wz--n- 8.98g 4.73g
[root@justin ~]
#
|
将某一PV移除VG
1
2
|
[root@localhost ~]
# vgreduce VGtest /dev/sdb5 #从vg组里移出sdb5
Removed
"/dev/sdb5"
from volume group
"VGtest"
|
LV扩展
格式:lvresize -L 容量大小 对象
/dev/VGtest/LVtest1从256M扩展到3G需要增加2.75G
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
[root@justin ~]
# lvresize -L +2.75G /dev/VGtest/LVtest1
Extending logical volume LVtest1 to 3.00 GiB
Logical volume LVtest1 successfully resized
[root@justin ~]
# resize2fs /dev/VGtest/LVtest1 ;重设文件系统
resize2fs 1.41.12 (17-May-2010)
Filesystem at
/dev/VGtest/LVtest1
is mounted on
/mnt/sdb6
; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 12
Performing an on-line resize of
/dev/VGtest/LVtest1
to 3145728 (1k) blocks.
The filesystem on
/dev/VGtest/LVtest1
is now 3145728 blocks long.
[root@justin ~]
# lvs /dev/VGtest/LVtest1
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LVtest1 VGtest -wi-ao-- 3.00g
[root@justin ~]
# lvdisplay /dev/VGtest/LVtest1
--- Logical volume ---
LV Path
/dev/VGtest/LVtest1
LV Name LVtest1
VG Name VGtest
LV UUID 6AggK6-XjPH-Jgt0-A4pI-2Fnw-cHKf-hM5mba
LV Write Access
read
/write
LV Creation host,
time
justin, 2013-11-15 14:23:00 +0800
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 768
Segments 2
Allocation inherit
Read ahead sectors auto
- currently
set
to 256
Block device 253:1
[root@justin ~]
# lvresize -L 3G /dev/VGtest/LVtest1 --或者
[root@justin ~]
# lvextend -L +2.75G /dev/VGtest/LVtest1 --或者
[root@justin ~]
# lvreduce /dev/VGtest/LVtest1 --移除
|
扩展Lv前先卸载,扩展完在挂载
五、PV数据移动
格式:pvmove 源数据 目标数据
1
2
3
4
|
[root@justin ~]
# pvmove /dev/sdb6 /dev/sdc1 ;sdb6数据移动sdc1里
/dev/sdb6
: Moved: 1.6%
/dev/sdb6
: Moved: 100.0%
[root@justin ~]
#
|
六、移除
移除LV
格式:lvremove lv_name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@justin ~]
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LVtest VGtest -wi-ao-- 4.00g
LVtest1 VGtest -wi-ao-- 3.00g
[root@justin ~]
# lvremove /dev/VGtest/LVtest1
Logical volume VGtest
/LVtest1
contains a filesystem
in
use.
[root@justin ~]
# umount !$
umount
/dev/VGtest/LVtest1
[root@justin ~]
# lvremove /dev/VGtest/LVtest1
Do you really want to remove active logical volume LVtest1? [y
/n
]: y
Logical volume
"LVtest1"
successfully removed
[root@justin ~]
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LVtest VGtest -wi-ao-- 4.00g
[root@justin ~]
#
|
移除VG
格式:vgremove 移除vg名
移除VG前需要先把LV全部移除
1
2
3
4
5
6
7
8
9
10
11
|
[root@justin ~]
# vgremove VGtest
Do you really want to remove volume group
"VGtest"
containing 1 logical volumes? [y
/n
]: y
Logical volume VGtest
/LVtest
contains a filesystem
in
use.
[root@justin ~]
# lvremove /dev/VGtest/LVtest
Do you really want to remove active logical volume LVtest? [y
/n
]: y
Logical volume
"LVtest"
successfully removed
[root@justin ~]
# vgremove VGtest
Volume group
"VGtest"
successfully removed
[root@justin ~]
# vgs
No volume
groups
found
[root@justin ~]
#
|
PV移除
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@justin ~]
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb5
lvm2 a-- 3.01g 3.01g
/dev/sdb6
lvm2 a-- 1.98g 1.98g
/dev/sdc1
lvm2 a-- 4.00g 4.00g
[root@justin ~]
# pvremove /dev/sdb5
Labels on physical volume
"/dev/sdb5"
successfully wiped
[root@justin ~]
# pvremove /dev/sdb6
Labels on physical volume
"/dev/sdb6"
successfully wiped
[root@justin ~]
# pvremove /dev/sdc1
Labels on physical volume
"/dev/sdc1"
successfully wiped
[root@justin ~]
# pvs
[root@justin ~]
#
|
补充:
由于vg是多个PE(块)组成的,而且每个vg块的PE最大数量是65534。默认每个PE的大小是4m
也就是说默认的每个vg最大也就是4m乘65534=256G,因此PE块的大小决定了最终vg的大小。
改变PE大小:vgcreate -s PE大小 卷组名 物理卷
1
|
[root@justin ~]
# vgcreate -s 16M vg /dev/sdb{1..5}
|
e2fsck---检查ext2文件系统的正确性
说 明:
e2fsck执行后的传回值及代表意义如下:
0没有任何错误发生。
1文件系统发生错误,并且已经修正。
2文件系统发生错误,并且已经修正。
4文件系统发生错误,但没有修正。
8运作时发生错误。
16使用的语法发生错误。
128共享的函数库发生错误。
参 数:
-a:对partition做检查,若有问题便自动修复,等同-p的功能
-b:设定存放superblock的位置
-B:设定单位block的大小
-c:检查该partition是否有坏轨
-Cfile:将检查的结果存到file中以便查看
-d:列印e2fsck的debug结果
-f:强制检查
-F:在开始检查前,将device的buffercache清空,避免有错误发生
-lbad_blocks_file:将有坏轨的block资料加到bad_blocks_file里面
-Lbad_blocks_file:设定坏轨的block资料存到bad_blocks_file里面,若无该档则自动产生
-n:将档案系统以[唯读]方式开启
-p:对partition做检查,若有问题便自动修复
-v:详细显示模式
-V:显示出目前e2fsck的版本
-y:预先设定所有检查时的问题均回答[是]
1
2
3
4
5
6
7
8
9
|
[root@localhost ~]
# e2fsck -f /dev/testvg/testlv #强制检查testlv分区是否正常
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv
: 11
/1048576
files (9.1% non-contiguous), 68593
/2097152
blocks
[root@localhost ~]
#
|
注 意:
大部份使用e2fsck来检查硬盘partition的情况时,通常都是情形特殊,因此最好先将该partitionumount,然后再执行e2fsck来做检查,若是要非要检查/时,则请进入singalusermode再执行。
resize2fs---ext2/ext3/ext4文件系统重定义大小工具
说 明
resize2fs程序会重新定义ext2,ext3或者是ext4文件系统。能够用于扩大或者缩小一个在设备上未挂载的文件系统。如果这个文件系统是挂在的,它能够用于扩大挂载了的文件系统,假定内核支持在线重新定义大小。(从这个算起,linux的2.6内核支持使用ext3挂载文件系统的在线重定义大小。)
大小参数指定要求的文件系统的新大小。如果单位没有指定,大小参数的单位会成为文件系统的文件系统的文件块尺寸。可选择的,大小参数也会分别带有后缀为's','K','M'或者'G'的单位标识符为512字节(bytesectors),千字节(kilobytes),百万字节(megabytes)或者是十亿字节(gigabytes)。文件系统的大小也不能够大于分区的大小。如果大小参数没有被指定,会使用默认的分区大小。
resize2fs程序不会改变分区的大小。如果你希望扩大是一个文件系统,你必须首先确认扩大的潜在的分区的大小。这个能够用于使用fdisk通过过删除分区并重新创建一个各大的分区或者使用lvextend,如果你在使用本地卷管理(logicalvolumemanager)(lvm)。当重新创建分区,确定你用相同的初始磁盘柱面;另外,重定义操作也会不会工作,并且你可能会失去你的的整个的文件系统。运行过fdisk之后,运行resize2fs来重新改变ext2分区的大小来使用所有的所有的空间在新的扩大后的分区。
如果你希望缩小一个ext2格式的分区,首先使用resize2fs来缩小文件系统的大小。之后你可以使用fdisk来缩小分区的大小。当缩小分区的大小时,确定你没有是它小于ext2文件系统的新大小
选项
-ddebug-flags(调试-标志)
打开多样的resize2fs调试特性,如果他们已经被编译进入了库当中。调试-标志应该通过相加下列列表设计的特性的数字来计算:
2-Debugblockrelocations(调试block再安置)
4-Debuginoderelocations(调试inode再安置)
8-Debugmovingtheinodetable(调试移动inodetable)
-f强制开始文件系统重定义大小操作,推翻一些resize2fs平常的强制安全检查。
-F开始之前排除文件系统设备的缓冲区的缓存。真正只对resize2fs的时间检验有用。
-M减小文件系统到最小的大小。
-p为了每一个resize2fs操作打印一个百分比完成条,因此用户可以保持注意程序正在运作的动态。
-P打印最小的文件大小并退出。
本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1325203,如需转载请自行联系原作者