LVM逻辑卷管理和挂盘操作
一、简介
逻辑卷管理器是linux系统对硬盘区分进行管理的一种机制,为解决硬盘设备在创建后不易修改分区大小的缺陷。并且通过LVM,可以对逻辑卷进行扩展和缩小分区。
1.1 PV & VG & LV含义
- PV:Physical Volume,物理卷。物理卷在逻辑卷最顶层,提供容量,可视为对硬盘的分区。
- VG:Volume Group,卷组。卷组在物理卷之上,由一个或多个物理卷组成。一个系统可以由一个或多个卷组。
- LV:Logical Volume,逻辑卷。逻辑卷建立在卷组之上,它是对卷组的切割。卷组有10G,可切割一个5G的LV。
- PE:Physical Extents, 物理扩展块。LVM寻址的最小单元,默认为4M,一个VG最多仅能含有65534个,但可以修改PE大小。
1.2 PV & VG & LV关系图
二、挂盘操作
2.1 添加
添加一块硬盘
查看磁盘
[root@disk1 ~]# fdisk -lDisk /dev/sda: 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: 0x000dfaf7Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 36079615 17833984 83 Linux#已经添加进来了
Disk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos_test-root: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos_test-swap: 2147 MB, 2147483648 bytes, 4194304 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
分区
[root@disk1 ~]# fdisk /dev/sdb
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 0xe78a1bcc.Command (m for help): m #查看帮助
Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help): n #添加一个分区
Partition type:p primary (0 primary, 0 extended, 4 free)e extended
Select (default p): p #添加一个主分区,最多能添加四个主分区或3个主分区、多个逻辑分区
Partition number (1-4, default 1):
First sector (2048-12582911, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-12582911, default 12582911): +1G #设置分区为1G
Partition 1 of type Linux and of size 1 GiB is setCommand (m for help): p #查看分区信息Disk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 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: 0xe78a1bccDevice Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 LinuxCommand (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 (2099200-12582911, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-12582911, default 12582911): +1G
Partition 2 of type Linux and of size 1 GiB is setCommand (m for help): pDisk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 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: 0xe78a1bccDevice Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4196351 1048576 83 Linux
Command (m for help): w #保存修改信息,退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
查看分区信息
[root@disk1 ~]# fdisk -lDisk /dev/sda: 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: 0x000dfaf7Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 36079615 17833984 83 LinuxDisk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 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: 0x4a5a2424
#已经分区Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4196351 1048576 83 LinuxDisk /dev/mapper/centos_test-root: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos_test-swap: 2147 MB, 2147483648 bytes, 4194304 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
通知系统分区变化
[root@disk1 ~]# partprobe
2.2 格式化
对分区进行格式化为xfs文件系统
[root@disk1 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65536 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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@disk1 ~]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=65536 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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
2.3 挂载
创建目录进行挂载
[root@disk1 ~]# mkdir /data{1,2}
[root@disk1 ~]# mount /dev/sdb1 /data1
[root@disk1 ~]# mount /dev/sdb2 /data2[root@disk1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_test-root 15G 1.9G 14G 13% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 111M 87M 57% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 1014M 33M 982M 4% /data1 #挂载成功
/dev/sdb2 1014M 33M 982M 4% /data2
想要使挂载永久生效,需要修改/etc/fstab
[root@disk1 ~]# vim /etc/fstab
/dev/sdb1 /data1 xfs defaults 0 0
/dev/sdb2 /data2 xfs defaults 0 0重载/etc/fstab文件信息,使用修改生效,无误,则修改正确
[root@disk1 ~]# mount -a
2.4 删除
删除操作的话,
[root@disk1 ~]# fdisk /dev/sdb
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.Command (m for help): d #删除
Partition number (1,2, default 2): 2
Partition 2 is deletedCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
三、逻辑卷操作
创建逻辑卷时,分区不能挂载,需要umount /data1 /data2
3.1 添加逻辑卷
修改分区类型的ID为8e
[root@disk1 ~]# fdisk /dev/sdb
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.Command (m for help): l 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux LVM' to 'Linux LVM'Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): pDisk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 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: 0x5e00bc37Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
创建物理卷
[root@disk1 ~]# pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: yWiping xfs signature on /dev/sdb1.Physical volume "/dev/sdb1" successfully created.
[root@disk1 ~]# pvcreate /dev/sdb2
WARNING: xfs signature detected on /dev/sdb2 at offset 0. Wipe it? [y/n]: yWiping xfs signature on /dev/sdb2.Physical volume "/dev/sdb2" successfully created.
查看物理卷
[root@disk1 ~]# pvscan PV /dev/sda2 VG centos_test lvm2 [17.00 GiB / 4.00 MiB free]PV /dev/sdb1 lvm2 [1.00 GiB]PV /dev/sdb2 lvm2 [1.00 GiB]Total: 3 [19.00 GiB] / in use: 1 [17.00 GiB] / in no VG: 2 [2.00 GiB]
创建卷组
[root@disk1 ~]# vgcreate vg_test /dev/sdb1 创建卷组,格式:vgcreate vg_name pv_nameVolume group "vg_test" successfully created
[root@disk1 ~]# vgextend vg_test /dev/sdb2 扩展卷组,格式:vgextend vg_name pv_nameVolume group "vg_test" successfully extended
查看卷组
[root@disk1 ~]# vgsVG #PV #LV #SN Attr VSize VFreecentos_test 1 2 0 wz--n- 17.00g 4.00mvg_test 2 0 0 wz--n- 1.99g 1.99g
创建逻辑卷
#lvcreate -L +创建lv大小(M/G) -n 逻辑卷名字 卷组名字
[root@disk1 ~]# lvcreate -L +1G -n lv_test vg_test Logical volume "lv_test" created.
#分配所有空间
lvcreate -l 100%VG -n lvname vgname
[root@disk1 ~]# mkfs.xfs /dev/vg_test/lv_test
meta-data=/dev/vg_test/lv_test isize=512 agcount=4, agsize=65536 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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
3.2 扩展逻辑卷
可以在线扩展
[root@disk1 ~]# lvextend -L +500M /dev/vg_test/lv_test Size of logical volume vg_test/lv_test changed from 1.00 GiB (256 extents) to <1.49 GiB (381 extents).Logical volume vg_test/lv_test successfully resized.
查看发现大小不变,还需要让文件系统知道,使扩容生效
[root@disk1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_test-root 15G 1.9G 14G 13% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 111M 87M 57% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_test-lv_test 1014M 33M 982M 4% /data1
使扩容生效
[root@disk1 ~]# xfs_growfs /dev/vg_test/lv_test
meta-data=/dev/mapper/vg_test-lv_test isize=512 agcount=4, agsize=65536 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=262144, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 262144 to 390144
查看分区信息
[root@disk1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_test-root 15G 1.9G 14G 13% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 111M 87M 57% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_test-lv_test 1.5G 33M 1.5G 3% /data1
ps:
xfs文件系统:需要用xfs_growfs
ext2 ext3 ext4文件系统:需要用resize2fs /dev/sdb3 2G ,2G是扩展到2G
3.3 缩减逻辑卷
不能在线缩减
下边是由1G缩减为500M
xfs系统
缩减,需要重新创建lv,无法直接缩减
#umount /dev/vg_test/lv_test
#lvresize -L 500M /dev/vg_test/lv_test
#lvs 发现lv变为500M
#mkfs.xfs /dev/vg_test/lv_test
#mount /dev/vg_test/lv_test /data1/
ext系统
#umount /dev/vg_test/lv_test
#e2fsck -f /dev/vg_test/lv_test 磁盘检查
#resize2fs /dev/vg_test/lv_test 500M 调整文件系统大小为500M
#mount /dev/vg_test/lv_test /data1/
#df -h 查看文件系统大小已变成500M
#lvs 查看逻辑卷大小依然是1G,没有改变,需要调整LV大小
#lvresize -L 500M /dev/vg_test/lv_test 调增lv大小为500M
3.4 删除逻辑卷
[root@disk1 ~]# umount /dev/vg_test/lv_test
[root@disk1 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot centos_test -wi-ao---- 15.00g swap centos_test -wi-ao---- 2.00g lv_test vg_test -wi-a----- <1.49g
[root@disk1 ~]# lvremove lv_testVolume group "lv_test" not foundCannot process volume group lv_test
LVM逻辑卷管理和挂盘操作相关推荐
- linux 软raid和lvm,lvm逻辑卷管理和软Raid设置
一.LVM逻辑卷管理 1. 定义 将多个物理分区/磁盘从逻辑上组合成一个更大的整体,从其中划分出不同的逻辑分区,逻辑分区的大小可以根据需求扩大和缩减 2. LVM概念 PV:物理卷 VG:卷组(可以包 ...
- Linux -- lvm逻辑卷管理和RAID
一.LVM概述 LVM(Logical Volume Manager):逻辑卷管理,是在硬盘分区和文件系统之间添加的一个逻辑层可用来提高磁盘分区管理的灵活性,动态扩展我们的磁盘空间. LVM 屏蔽了底 ...
- linux逻辑卷下空间丢了,Linux-lvm逻辑卷管理和提示丢失pv物理卷
问题描述: 有次在使用lvm扩容的时候,整错了,导致显示如下情况 提示缺少一个pv导致无法继续,pvdisplay的时候查看到unknown 使用pvs查看找到pvname的unknown对应群组ce ...
- LVM逻辑卷管理与磁盘配额
文章目录 1.前言 2.LVM管理 2.1LVM概述 (1)LVM基本原理 (2)LVM实现过程 (3)LVM基本术语 2.2LVM命令管理 (1)PV管理工具 (2)VG管理工具 (3)LV管理工具 ...
- LVM逻辑卷,LVM管理工具集,LVM创建逻辑卷,调整现有磁盘的分区,使用逻辑分区做逻辑卷,扩展卷组大小,扩展逻辑卷的大小
一.什么是LVM逻辑卷 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux ...
- linux设置逻辑卷进不了图形界面,LVM逻辑卷管理器图形界面操作
LVM逻辑卷管理器图形界面操作 LVM有关概念 LVM(Logical Volume Manager)即逻辑卷管理器,它最先是在Linux 2.4内核中被集成到内核中去的,它的出现改变了传统的磁盘空间 ...
- Linux下逻辑卷LVM的管理和RAID磁盘阵列
Linux系统安全 | Linux下逻辑卷LVM的管理和RAID磁盘阵列 原创 谢公子 [谢公子学安全](javascript:void(0);) 昨天 转载自公众号:谢公子学安全 图片 图片 LVM ...
- 【Liunx常用操作】LVM逻辑卷的介绍和相关操作(创建、删除、扩缩容)
[Liunx常用操作]LVM逻辑卷的介绍和相关操作 提示:为保证文章的正确性和实用性,文章内容作者会不断优化改进,若您有建议或者文章存在错误请留言或评论指正. 前言 LVM(Logical Volum ...
- linux系统创建lvm卷,LVM逻辑卷创建管理
一.简介 LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵 ...
最新文章
- 刚出道的黑客搞瘫美国!他们一边搞钱一边捐款给慈善组织,还说俄国人不打俄国人...
- Win64 驱动内核编程-20.UnHook SSDT
- 协议关键技术_北京理工大学与华为签署战略合作协议
- 堡垒机 请确认是否安装oracle客户端_OracleOracle数据库的安装(超详细)
- python 弹窗不阻断线程_Javascript 如何阻断程序的运行
- clientdataset1.filter like怎么用_除了like, 英语还能这样说“喜欢”!
- 【jQuery笔记Part1】08-jQuery操作css-获取设置样式
- yii2 复制一个应用需配置
- php如何实现运算符重载,JS怎样实现运算符重载
- 2022-04-08美团笔试练题
- 第3章:混仿高级特性
- 使用 JavaScript 将 JSON 数据动态转换为 HTML 表
- 微型计算机内存与外存的区别,计算机的内存 和外存一样吗?
- hadoop更换硬盘
- python 字节流分段_如何在Python中编写简单代码,并且速度超越Spark?
- 百度云图片识别(ImageRecognition) 针对 各种图片识别的例子
- google搜索---搜索指定网页的内容
- ImageGear for .NET扫描打印等图形图像处理控件介绍使用手册
- 1999年法国版的《基督山伯爵》国语
- 数据万象内容审核 — 共建安全互联网,专项开展“清朗”直播整治行动