LVM逻辑卷
逻辑卷管理LVM是一个多才多艺的硬盘系统工具。无论在Linux或者其他类似的系统,都是非常的好用。传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。
优点
a. 使用方便
缺点
a. 误删除数据恢复更加困难
b. LVM缩减分区大小风险较大
命令
LVM逻辑卷的使用
查看系统磁盘
使用lsblk命令,查看系统磁盘,命令如下:
[root@lvm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vda1 253:1 0 20G 0 disk /mnt
创建物理卷
在创建物理卷之前,需要对磁盘进行分区。首先使用fdisk命令对vdb进行分区操作,分出两个大小为5 GB的分区,命令如下:
[root@lvm ~]# umount /dev/vdb
[root@lvm ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x23122c56.
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x23122c56
Device Boot Start End Blocks Id System
Command (m for help): n //输入n进行创建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //输入p创建主分区
Partition number (1-4, default 1): //默认按回车
First sector (2048-41943039, default 2048): //默认按回车
Using default value 2048
Last sector, +sectors or +size{
K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808