部署逻辑卷
1.添加两块硬盘,建立物理卷1
2
3[root@localhost ~]# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
2.创建卷组 storage ,并将sdb,sdc加入到卷组stroage1
2[root@localhost ~]# vgcreate storage /dev/sdb /dev/sdc
Volume group "storage" successfully created
3.查看卷组状态1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name storage
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 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID Z9dr3u-7oni-yBLE-rfS9-xJ9g-p2aQ-s1VCUk
4.切割一个约为150MB的逻辑卷设备
#对逻辑卷切割有两种计量单位。
使用-L参数 -L 150M 生成150 MB
使用-l参数 -l 37 生成37*4=148MB(每个单元大小默认为4MB,按单元为计量单位)1
[root@localhost ~]# lvcreate -n vo -L 150M storage
5.格式化逻辑卷,并挂载1
2
3[root@localhost ~]# mkfs.ext4 /dev/storage/vo
[root@localhost ~]# mkdir /LVM
[root@localhost ~]# mount /dev/storage/vo /LVM/
6.查看挂载状态,并写入配置文件,使其永久生效1
2
3
4
5
6
7
8
9
10
11[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.3G 17G 7% /
devtmpfs 904M 0 904M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.7M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 297M 113M 185M 38% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/storage-vo 144M 1.6M 132M 2% /LVM
[root@localhost ~]# echo "/dev/storage/vo /LVM/ ext4 defaults 0 0" >> /etc/fstab
扩容逻辑卷
1.取消挂载1
[root@localhost ~]# umount /LVM/
2.扩展逻辑卷vo至290MB1
2
3
4[root@localhost ~]# lvextend -L 290M /dev/storage/vo
Rounding size to boundary between physical extents: 292.00 MiB
Size of logical volume storage/vo changed from 152.00 MiB (38 extents) to 292.00 MiB (73 extents).
Logical volume vo successfully resized.
3.检查硬盘完整性,并重置硬盘容量1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@localhost ~]# e2fsck -f /dev/storage/vo
e2fsck 1.42.9 (28-Dec-2013)
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/storage/vo: 11/38912 files (0.0% non-contiguous), 10567/155648 blocks
[root@localhost ~]# resize2fs /dev/storage/vo
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/storage/vo to 299008 (1k) blocks.
The filesystem on /dev/storage/vo is now 299008 blocks long.
4.重新挂载,并查看挂载状态1
2
3
4
5
6
7
8[root@localhost ~]# mount /dev/storage/vo /LVM/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.3G 17G 7% /
devtmpfs 904M 0 904M 0% /dev
tmpfs 913M 8.7M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/mapper/storage-vo 279M 2.1M 259M 1% /LVM
缩小逻辑卷
1.取消挂载1
[root@localhost ~]# umount /LVM/
2.检查文件系统完整性1
2
3
4
5
6
7
8[root@localhost ~]# e2fsck -f /dev/storage/vo
e2fsck 1.42.9 (28-Dec-2013)
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/storage/vo: 11/75776 files (0.0% non-contiguous), 15729/299008 blocks
3.把逻辑卷vo容量减小 到 120MB1
2
3
4
5
6
7
8
9
10
11[root@localhost ~]# resize2fs /dev/storage/vo 120M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/storage/vo to 122880 (1k) blocks.
The filesystem on /dev/storage/vo is now 122880 blocks long.
[root@localhost ~]# lvreduce -L 120M /dev/storage/vo
WARNING: Reducing active logical volume to 120.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vo? [y/n]: y
Size of logical volume storage/vo changed from 292.00 MiB (73 extents) to 120.00 MiB (30 extents).
Logical volume vo successfully resized.
4.重新挂载文件系统并查看系统状态1
2
3
4
5
6
7
8[root@localhost ~]# mount /dev/storage/vo /LVM/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.3G 17G 7% /
devtmpfs 904M 0 904M 0% /dev
tmpfs 913M 8.7M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/mapper/storage-vo 113M 1.6M 103M 2% /LVM
逻辑卷快照
#快照卷容量必须等于逻辑卷的已使用容量
#快照卷仅一次有效,一旦执行还原操作后会被立即删除
1.查看卷组信息,查看Alloc PE / Size 已使用容量1
vgdisplay
后面再写吧