二.创建逻辑卷(逻辑卷的大小不能超过卷组)
lvcreate -L 逻辑卷大小 - n 逻辑卷的名称 卷组名
[root@server0 ~]#
lvcreate -L 16
G -n mylv myvg
Logical volume "
mylv"
created
[root@server0 ~]#
vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 1 0
wz--n- 19
.99g 3
.99g
[root@server0 ~]#
lvs
LV VG Attr
LSize Pool Origin Data%
Move Log Cpy%
Sync Convert
mylv myvg -wi-a----- 16
.00g
三.使用逻辑卷
[root@server0 ~]
# mkfs.ext4 /dev/myvg/mylv
[root@server0 ~]
# mkdir /lvm
[root@server0 ~]
# vim /etc/fstab
...
/dev/myvg/mylv /lvm ext4 defaults
0 0
...
[root@server0 ~]
# mount -a
[root@server0 ~]
# df -h
逻辑卷扩展(支持线上操作)
lvextend -L 新大小 /dev/卷组名/逻辑卷名
一.卷组有足够的剩余空间
1.直接扩展逻辑卷的空间
[root@server0 ~]
# lvs
LV VG Attr
LSize Pool Origin Data% Move Log Cpy%Sync Convert
mylv myvg -wi-a-----
16.00g
[root@server0 ~]
# lvextend -L 18G /dev/myvg/mylv
Extending logical volume mylv to
18.00 GiB
Logical volume mylv successfully resized
[root@server0 ~]
# lvs
LV VG Attr
LSize Pool Origin Data% Move Log Cpy%Sync Convert
mylv myvg -wi-ao----
18.00g
[root@server0 ~]
# df -h
文件系统
容量 已用 可用 已用% 挂载点
/dev/vda1
10G 3.1G 7.0G 31% /
devtmpfs
906M
0 906M
0% /dev
tmpfs
921M
80K
921M
1% /dev/shm
tmpfs
921M
17M
904M
2% /run
tmpfs
921M
0 921M
0% /sys/fs/cgroup
/dev/vdb3
3.0G
33M
3.0G
2% /part3
/dev/vdb2
2.0G
6.0M
1.8G
1% /part2
/dev/mapper/myvg-mylv
16G
45M
15G
1% /lvm
2.扩展文件系统的大小
扩展ext4文件系统:resize2fs /dev/myvg/mylv
[root@server0 ~]
# resize2fs /dev/myvg/mylv
resize2fs
1.42.9 (
28-Dec
-2013)
Filesystem at /dev/myvg/mylv
is mounted
on /lvm;
on-line resizing required
old_desc_blocks =
2, new_desc_blocks =
3
The filesystem
on /dev/myvg/mylv
is now
4718592 blocks long.
[root@server0 ~]
# df -h
文件系统
容量 已用 可用 已用% 挂载点
/dev/vda1
10G 3.1G 7.0G 31% /
devtmpfs
906M
0 906M
0% /dev
tmpfs
921M
80K
921M
1% /dev/shm
tmpfs
921M
17M
904M
2% /run
tmpfs
921M
0 921M
0% /sys/fs/cgroup
/dev/vdb3
3.0G
33M
3.0G
2% /part3
/dev/vdb2
2.0G
6.0M
1.8G
1% /part2
/dev/mapper/myvg-mylv
18G
44M
17G
1% /lvm
扩展xfs文件系统:xfs_growfs /dev/myvg/mylv
二.卷组没有剩余空间
vgextend 卷组名 空闲分区
[root@server0 ~]#
vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 1 0
wz--n- 19
.99g 1
.99g
1.先扩展卷组
[root@server0 ~]
# vgextend myvg /dev/vdc3
Physical volume
"/dev/vdc3" successfully created
Volume group
"myvg" successfully extended
2.扩展逻辑卷的空间
3.扩展文件系统大小
逻辑卷缩减 (运维几乎不用)
先缩减文件系统 在缩减空间
[root@server0 ~]
# resize2fs /dev/myvg/mylv 10G
resize2fs
1.42.9 (
28-Dec
-2013)
Filesystem at /dev/myvg/mylv
is mounted
on /lvm;
on-line resizing required
resize2fs: On-line shrinking
not supported
[root@server0 ~]
# umount /lvm
[root@server0 ~]
# resize2fs /dev/myvg/mylv 10G
resize2fs
1.42.9 (
28-Dec
-2013)
请先运行
'e2fsck -f /dev/myvg/mylv'.
[root@server0 ~]
# e2fsck -f /dev/myvg/mylv
e2fsck
1.42.9 (
28-Dec
-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第
3步: 检查目录连接性
Pass
4: Checking reference counts
第
5步: 检查簇概要信息
/dev/myvg/mylv:
11/
1638400 files (
0.0% non-contiguous),
146871/
6553600 blocks
[root@server0 ~]
# resize2fs /dev/myvg/mylv 10G
resize2fs
1.42.9 (
28-Dec
-2013)
Resizing the filesystem
on /dev/myvg/mylv to
2621440 (
4k) blocks.
The filesystem
on /dev/myvg/mylv
is now
2621440 blocks long.
[root@server0 ~]
# mount -a
[root@server0 ~]
# df -h
文件系统
容量 已用 可用 已用% 挂载点
/dev/vda1
10G 3.1G 7.0G 31% /
devtmpfs
906M
0 906M
0% /dev
tmpfs
921M
80K
921M
1% /dev/shm
tmpfs
921M
17M
904M
2% /run
tmpfs
921M
0 921M
0% /sys/fs/cgroup
/dev/vdb3
3.0G
33M
3.0G
2% /part3
/dev/vdb2
2.0G
6.0M
1.8G
1% /part2
/dev/mapper/myvg-mylv
9.8G
37M
9.3G
1% /lvm