LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现。
Linux用户安装Linux操作系统时遇到的一个常见的难以决定的问题就是如何正确地评估各分区大小,以分配合适的硬盘空间。普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻辑分区存放不下某个文件时,这个文件因为受上层文件系统的限制,也不能跨越多个分区来存放,所以也不能同时放到别的磁盘上。而遇到出现某个分区空间耗尽时,解决的方法通常是使用符号链接,或者使用调整分区大小的工具,但这只是暂时解决办法,没有从根本上解决问题。随着Linux的逻辑卷管理功能的出现,这些问题都迎刃而解,用户在无需停机的情况下可以方便地调整各个分区大小。
fdisk : 列出帮助信息
fdisk -l : 列出所有分区
fdisk -l /dev/sda1 >>>指定分区列出
fdisk -s :给出分区大小
fdisk -s /dev/sda1 >>> 指定分区给出
fdisk [分区名称] :更改分区
a toggle a bootable flag 切换可引导标志
b edit bsd disklabel 编辑bsd磁盘标签
c toggle the dos compatibility flag 切换dos兼容性标志
d delete a partition 删除分区
g create a new empty GPT partition table 创建一个新的空GPT分区表
G create an IRIX (SGI) partition table 创建IRIX(SGI)分区表
l list known partition types 列出已知分区类型
m print this menu 打印此菜单
n add a new partition 添加新分区
o create a new empty DOS partition table 创建一个新的空DOS分区表
p print the partition table 打印分区表
q quit without saving changes 退出而不保存更改
s create a new empty Sun disklabel 创建新的空Sun disklabel
t change a partitions system id 更改分区的系统id
u change display/entry units 更改显示/输入单位
v verify the partition table 验证分区表
w write table to disk and exit 将表写入磁盘并退出
x extra functionality (experts only) 额外功能(仅限专家)
mkfs:格式化分区
mkfs -t ext3 /dev/sda2 >>>>>>>将磁盘格式化为ext3格式
rpm -qa | grep lvm
yum -y install lvm
▼▼▼
pvcreate /dev/sdb1
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
pvs /dev/sdb1 查看所有pv(pvs后不跟分区默认输出所有)
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.51g 4.00m
/dev/sdb1 lvm2 --- <30.00g <30.00g
查看pv的详细信息:
▼▼▼
pvdispaly /dev/sdb1
[root@localhost ~]# pvdisplay /dev/sdb1
"/dev/sdb1" is a new physical volume of "<30.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <30.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID J5dh1L-SFZf-EqcL-Jyet-E22j-UELn-nscaG7
[root@localhost ~]#
删除pv:(pv不能直接删除需要先pvmove移除所有数据后,pvremove删除pv)
pvmove /dev/sdb1
pvremove /dev/sdb1
▼▼▼
vgcreate [卷组名] [磁盘分区]
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.51g 4.00m
/dev/sdb1 lvm2 --- <30.00g <30.00g
[root@localhost ~]# vgcreate vg0 /dev/sdb1
Volume group "vg0" successfully created
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.51g 4.00m
vg0 1 0 0 wz--n- <30.00g <30.00g
[root@localhost ~]#
查看vg详细信息:
▼▼▼
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <30.00 GiB
PE Size 4.00 MiB
Total PE 7679
Alloc PE / Size 0 / 0
Free PE / Size 7679 / <30.00 GiB
VG UUID 3LYUBp-hY5d-z5gb-XWmC-6mFw-ZyY3-y36Ijm
注:lv是基于vg的,而vg是基于pv的所以此处在创建lv时首先需要查看vg大小能不能容下你要创建的lv,不能则需要扩展。
lvcreate L<指定lv大小 [lv容量] -n<指定逻辑卷名称 [lv名称] [卷组名]
▼▼▼
lvcreate -L 10G -n lv0 vg0
[root@localhost ~]# lvcreate -L 10G -n lv0 vg0
Logical volume "lv0" created.
[root@localhost ~]#
[root@localhost ~]# lvs vg0
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-a----- 10.00g
▼▼▼
mkfs.xfs /dev/sdb1
[root@localhost vg0]# mkfs.xfs /dev/vg0/lv0
meta-data=/dev/vg0/lv0 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost vg0]#
挂载lv:
▼▼▼
[root@localhost vg0]# mount /dev/vg0/lv0 /oracle_pv
[root@localhost vg0]# ls -l
总用量 0
lrwxrwxrwx. 1 root root 7 1月 8 16:32 lv0 -> ../dm-2
[root@localhost vg0]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 10G 33M 10G 1% /oracle_pv
[root@localhost vg0]#
格式化为xfs:
▼▼▼
umount /oracle_log
mkfs.xfs -f /dev/vg0/lv0 -------f为强制执行
mount /dev/vg0/lv0 /oracle_pv
vgextend vg0 /dev/sdb1
vgreduce [卷组名] [物理卷]
pvmove /dev/sdb1
vgreduce /dev/sdb1
pvremove /dev/sdb1
▼▼▼
[root@localhost vg0]# umount /oracle_pv
[root@localhost vg0]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
[root@localhost vg0]# e2fsck -f /dev/vg0/lv0
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第三步: 检查目录连接性
第四步: Checking reference counts
第五步: 检查簇概要信息
▼▼▼
[root@localhost vg0]# resize2fs /dev/vg0/lv0 5G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 1310720 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 1310720 blocks long.
[root@localhost vg0]#
[root@localhost vg0]#
[root@localhost vg0]#
▼▼▼
[root@localhost vg0]# mount /dev/vg0/lv0 /oracle_pv
[root@localhost vg0]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 4.8G 33M 4.5G 1% /oracle_pv
[root@localhost vg0]#
▼▼▼
[root@localhost vg0]# lvreduce -L 5G /dev/vg0/lv0
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/lv0? [y/n]: y
Size of logical volume vg0/lv0 changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents).
Logical volume vg0/lv0 successfully resized.
[root@localhost vg0]#
拉伸文件系统:
ext4格式用:resize2fs
xfs格式用:xfs_growfs
▼▼▼
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 24G 4.5G 20G 19% /
devtmpfs devtmpfs 903M 0 903M 0% /dev
tmpfs tmpfs 920M 0 920M 0% /dev/shm
tmpfs tmpfs 920M 9.3M 911M 2% /run
tmpfs tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 163M 335M 33% /boot
tmpfs tmpfs 184M 12K 184M 1% /run/user/42
tmpfs tmpfs 184M 0 184M 0% /run/user/0
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
▼▼▼
[root@localhost /]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.51g 4.00m
vg0 1 2 0 wz--n- <30.00g <15.00g
[root@localhost /]# lvextend -L 10G /dev/vg0/lv0
Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
Logical volume vg0/lv0 successfully resized.
[root@localhost /]#
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 4.8G 33M 4.5G 1% /oracle_pv
/dev/mapper/vg0-lv1 9.8G 37M 9.2G 1% /oracle_pv1
▼▼▼
[root@localhost /]# resize2fs /dev/vg0/lv0
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv0 is mounted on /oracle_pv; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/vg0/lv0 is now 2621440 blocks long.
[root@localhost /]#
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 9.8G 36M 9.3G 1% /oracle_pv
/dev/mapper/vg0-lv1 9.8G 37M 9.2G 1% /oracle_pv1
▼▼▼
[root@test ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf5002802.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content wont be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
switch off the mode (command c) and change display units to
sectors (command u).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
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): t #修改分区格式
Selected partition 1
Hex code (type L to list codes): L #查看分区格式列表
Hex code (type L to list codes): 8e #类型修改为8e
Changed system type of partition 1 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: 0xf5002802
Device Boot Start End Blocks Id System
/dev/sdb1 1 652 5237158+ 8e Linux LVM
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
mkfs -t ext4 /dev/sdb1
pvcreate /dev/sdb1
lvextend -L 9G /dev/vg_test/lv_root #扩展LV 9G为总大小 如果是增加4G 可写为 +4G
▼▼▼
esize2fs /dev/vg_test/lv_root
df -h
vgdisplay
lvdisplay
resize2fs /dev/vg_test/lv_root #resizes
df -h
▼▼▼
vi /etc/fstab
/dev/phelsysvg/lvphelsys01 /phel/phelsys_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelrdo01 /phel/phelrdo_u01 ext3 defaults 1 2
/dev/phelsysvg/lvpheludo01 /phel/pheludo_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelaud01 /db_audit_file_dest ext3 defaults 1 2
/dev/phelsysvg/lvpheltmp01 /phel/pheltemp_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelarc01 /oraarchivelog ext3 defaults 1 2
更多精彩干货分享
点击下方名片关注
IT那活儿
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129930.html
阅读 1346·2023-01-11 13:20
阅读 1684·2023-01-11 13:20
阅读 1132·2023-01-11 13:20
阅读 1858·2023-01-11 13:20
阅读 4099·2023-01-11 13:20
阅读 2704·2023-01-11 13:20
阅读 1385·2023-01-11 13:20
阅读 3594·2023-01-11 13:20