Linux LVM磁盘管理
Posted Cyber Security
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux LVM磁盘管理相关的知识,希望对你有一定的参考价值。
几个概念:
PV:物理卷,指LVM的基本逻辑卷,包含LVM的基本参数,如/dev/sdb1等。
VG:卷组,类似于非LVM的硬盘,由多个PV组成。
LV:逻辑卷,类似于非LVM硬盘中的分区。
PE:物理块,每个物理卷PV被划分成一个个PE大基本单元,具有唯一编号的PE是LVM的最小的寻址单元,PE的大小是可以配置的,默认为4M。
LE:逻辑块,逻辑卷LV被划分成可寻址的基本单元LE,在同一个卷组中,PE和LE是大小相同,并且一一对应的。
步骤:
Step1:在机器上插入120G的一块SAS硬盘,并且分区,初始化,配置分区的格式为LVM,使用fdisk分区指定参数为8e,如下图:
[[email protected] networking]# fdisk -l
Disk /dev/sdb: 128.8 GB, 128849018880 bytes, 251658240 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
[[email protected] networking]# fdisk /dev/sdb
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux‘ to ‘Linux LVM‘
Step2:创建PV,如下图:
[[email protected] networking]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[[email protected] networking]#
Step3:创建VG,将创建的PV /dev/sdb1加入卷组,卷组的名称为RHEL
[[email protected] networking]# vgcreate RHEL /dev/sdb1
Volume group "RHEL" successfully created
Step4:创建LV,名称为Data,容量为60G,如下图:
[[email protected] networking]# lvcreate -L 60G -n Data RHEL
Logical volume "Data" created.
Step5:格式化LV,分区格式为xfs,如下图:
[[email protected] networking]# mkfs.xfs /dev/RHEL/Data
meta-data=/dev/RHEL/Data isize=256 agcount=4, agsize=3932160 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=15728640, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=7680, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] networking]#
Step6:创建挂载点/data,将分区挂载上去,如下图:
[[email protected] networking]# mkdir /data
[[email protected] networking]# mount /dev/RHEL/Data /data
[[email protected] networking]# df -hi
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 484K 371 483K 1% /dev
tmpfs 491K 1 491K 1% /dev/shm
tmpfs 491K 462 490K 1% /run
tmpfs 491K 13 491K 1% /sys/fs/cgroup
/dev/mapper/centos-root 45M 69K 44M 1% /
/dev/sda1 500K 334 500K 1% /boot
/dev/mapper/centos-home 22M 8 22M 1% /home
tmpfs 491K 1 491K 1% /run/user/1000
/dev/mapper/RHEL-Data 60M 3 60M 1% /data
[[email protected] networking]#
Step7:修改fstab开机挂载,如下图:
[[email protected] networking]# blkid /dev/RHEL/Data
/dev/RHEL/Data: UUID="9d9e1e69-9ad5-4d08-894c-50e111faf951" TYPE="xfs"
[[email protected] networking]# vi /etc/fstab
# /etc/fstab
# Created by anaconda on Sun Jan 20 05:11:51 2019
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=cd2fc291-2a9c-4479-b2c0-dddfbe129d6c /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=9d9e1e69-9ad5-4d08-894c-50e111faf951 /data xfs defaults 0 0
以上是关于Linux LVM磁盘管理的主要内容,如果未能解决你的问题,请参考以下文章