什么是LVM
LVM是 Logical Volume Manager,逻辑的概念,Linux用户安装Linux操作系统时遇到的一个常见的难以决定的问题就是如何正确地评估各分区大小,以分配合适的硬盘空间。普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻辑分区存放不下某个文件时,这个文件因为受上层文件系统的限制,也不能跨越多个分区来存放,所以也不能同时放到别的磁盘上。而遇到出现某个分区空间耗尽时,解决的方法通常是使用符号链接,或者使用调整分区大小的工具,但这只是暂时解决办法,没有从根本上解决问题。随着Linux的逻辑卷管理功能的出现,这些问题都迎刃而解,用户在无需停机的情况下可以方便地调整各个分区大小。
1. 名词解释:
· PV(Phsical Volume,物理卷),PV是VG的组成部分,有分区构成,多块盘的时候,可以把一块盘格式化成一个主分区,然后用这个分区做成一个PV,只有一块盘的时候,可以这块盘的某一个分区做成一个PV,实际上一个PV就一个分区。
· VG(Volume Group,卷组),有若干个PV组成,作用就是将PV组成到以前,然后再重新划分空间。
· LV(Logical Volume,逻辑卷),LV就是从VG中划分出来的卷,LV的使用要比PV灵活的多,可以在空间不够的情况下,增加空间。
2. 主要命令:
· 安装lvm命令报:
$ sudo yum
installlvm2
· pvcreate:创建PV
· pvdisplay:查看已创建的PV
· vgcreate:创建VG
· vgdisplay:查看VG
· lvcreate:创建LV
· lvdisplay:查看LV
扩展/websphere目录
首先查看当前挂载:
[root@slbidev bin]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 50G 16G 35G 31% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 0 16G 0% /dev/shm tmpfs 16G 25M 16G 1% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/mapper/rhel-home 5.0G 33M 5.0G 1% /home /dev/sda1 497M 125M 373M 26% /boot /dev/mapper/rhel-websphere 30G 22G 6.9G 76% /websphere tmpfs 3.2G 0 3.2G 0% /run/user/0 |
找到最新盘符
[root@slbidev bin]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00064030
Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 209715199 104344576 8e Linux LVM
Disk /dev/sdb: 75.2 GB, 75161927680 bytes, 146800640 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 /dev/sdc: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/mapper/rhel-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 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 /dev/mapper/rhel-home: 5368 MB, 5368709120 bytes, 10485760 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 /dev/mapper/rhel-websphere: 32.2 GB, 32212254720 bytes, 62914560 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 /dev/sdb: 75.2 GB 加入/dev/mapper/rhel-websphere
先做PV
[root@slbidev bin]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created |
查看pv
[root@slbidev bin]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size 99.51 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 25474 Free PE 1698 Allocated PE 23776 PV UUID Gh58LH-yjsx-O971-BUCD-dha6-cb2y-zUYrUc
--- Physical volume --- PV Name /dev/sdb VG Name rhel PV Size 70.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 17919 Free PE 17919 Allocated PE 0 PV UUID u44k8n-DhCr-xd9H-WRQJ-Ytxc-9O2F-16kHnT |
查看vg
[root@slbidev bin]# vgdisplay --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 4 Open LV 4 Max PV 0 Cur PV 1 Act PV 1 VG Size 99.51 GiB PE Size 4.00 MiB Total PE 25474 Alloc PE / Size 23776 / 92.88 GiB Free PE / Size 1698 / 6.63 GiB VG UUID kRhvoZ-omBH-1wbq-y0gp-9CBO-xrgt-tcWHiv |
把做好的pv加入vg
[root@slbidev bin]# vgextend rhel /dev/sdb Volume group "rhel" successfully extended |
扩容lv
[root@slbidev bin]# lvextend -L +70G /dev/mapper/rhel-websphere /dev/sdb Insufficient free space: 17920 extents needed, but only 17919 available [root@slbidev bin]# lvextend -L +69G /dev/mapper/rhel-websphere /dev/sdb Size of logical volume rhel/websphere changed from 30.00 GiB (7680 extents) to 99.00 GiB (25344 extents). Logical volume websphere successfully resized. [root@slbidev bin]# |
最后扩容LV对应的FS
[root@slbidev bin]# lvextend -L +70G /dev/mapper/rhel-websphere /dev/sdb Insufficient free space: 17920 extents needed, but only 17919 available [root@slbidev bin]# lvextend -L +69G /dev/mapper/rhel-websphere /dev/sdb Size of logical volume rhel/websphere changed from 30.00 GiB (7680 extents) to 99.00 GiB (25344 extents). Logical volume websphere successfully resized. [root@slbidev bin]# resize2fs /dev/mapper/rhel-websphere resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/rhel-websphere is mounted on /websphere; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 13 The filesystem on /dev/mapper/rhel-websphere is now 25952256 blocks long.
[root@slbidev bin]# |
扩容根目录/
找到最新盘符
[root@slbidev bin]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00064030
Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 209715199 104344576 8e Linux LVM
Disk /dev/sdb: 75.2 GB, 75161927680 bytes, 146800640 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 /dev/sdc: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/mapper/rhel-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 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 /dev/mapper/rhel-home: 5368 MB, 5368709120 bytes, 10485760 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 /dev/mapper/rhel-websphere: 32.2 GB, 32212254720 bytes, 62914560 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 |
如上,先把/dev/sdc: 107.4 GB 加入/dev/mapper/rhel-root
先做PV
[root@slbidev soft]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created |
查看pv
[root@slbidev soft]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size 99.51 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 25474 Free PE 1698 Allocated PE 23776 PV UUID Gh58LH-yjsx-O971-BUCD-dha6-cb2y-zUYrUc
--- Physical volume --- PV Name /dev/sdb VG Name rhel PV Size 70.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 17919 Free PE 255 Allocated PE 17664 PV UUID u44k8n-DhCr-xd9H-WRQJ-Ytxc-9O2F-16kHnT
"/dev/sdc" is a new physical volume of "100.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID hGEL13-1fCJ-eLCj-ecjQ-A2l8-DxK6-jTo2KJ
[root@slbidev soft]# |
把pv加到vg
[root@slbidev soft]# vgextend rhel /dev/sdc Volume group "rhel" successfully extended [root@slbidev soft]# |
扩容lv
[root@slbidev soft]# lvextend -L +99.9G /dev/mapper/rhel-root /dev/sdc Rounding size to boundary between physical extents: 99.90 GiB Size of logical volume rhel/root changed from 50.00 GiB (12800 extents) to 149.90 GiB (38375 extents). Logical volume root successfully resized. [root@slbidev soft]# |
扩容lv对应的fs
[root@slbidev soft]# resize2fs /dev/mapper/rhel-home resize2fs 1.42.9 (28-Dec-2013) resize2fs: Bad magic number in super-block while trying to open /dev/mapper/rhel-home Couldn't find valid filesystem superblock. [root@slbidev soft]# xfs_growfs /dev/mapper/rhel-root meta-data=/dev/mapper/rhel-root isize=256 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13107200 to 39296000 [root@slbidev soft]# [root@slbidev soft]# |
用resize2fs命令报错,经过查找资料,用xfs_growfs命令
参考:
https://www.cnblogs.com/archoncap/p/5442208.html