文档章节

CentOS7的LVM动态扩容

亚林瓜子
 亚林瓜子
发布于 08/20 13:55
字数 2090
阅读 70
收藏 4

# 问题

CentOS7上面的磁盘空间有点紧张,需要扩容。

解决

查询当前磁盘状态

[root@xxx ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 15.5G  0 part 
  ├─centos-swap 253:0    0  1.6G  0 lvm  [SWAP]
  └─centos-root 253:1    0 13.9G  0 lvm  /
sr0              11:0    1 1024M  0 rom  
loop0             7:0    0  4.3G  0 loop /mnt/iso

查询当前文件系统状态

[root@xxx ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   14G   14G   20K  100% /
devtmpfs                 3.8G     0  3.8G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G  442M  3.4G   12% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/sda1                497M  295M  202M   60% /boot
tmpfs                    782M   12K  782M    1% /run/user/42
/dev/loop0               4.3G  4.3G     0  100% /mnt/iso
tmpfs                    782M     0  782M    0% /run/user/0

查看当前磁盘分区情况

[root@xxx ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): p
Disk /dev/sda: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): FE64D670-2841-445E-974F-12A258105C57
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 385877949 sectors (184.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048        33554431   15.5 GiB    8E00  Linux LVM

lvm扩容

创建8e

[root@xxx ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): n
Partition number (3-128, default 3): 
First sector (34-419430366, default = 33554432) or {+-}size{KMGTP}: 
Last sector (33554432-419430366, default = 419430366) or {+-}size{KMGTP}: +84G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot   
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM           
a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap        
a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID  
a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap   
a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum  
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+      
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
Press the <Enter> key to see more codes: 8e00
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition 
fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
fd00 Linux RAID            
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/sda: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 209717181 sectors (100.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048        33554431   15.5 GiB    8E00  Linux LVM
   3        33554432       209715199   84.0 GiB    8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

这里需要注意的地方就是,扩容了84G,并且使用8e00。

更新8e

[root@xxx ~]# partprobe -s
/dev/sda: gpt partitions 1 2 3
[root@xxx ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
├─sda2            8:2    0 15.5G  0 part 
│ ├─centos-swap 253:0    0  1.6G  0 lvm  [SWAP]
│ └─centos-root 253:1    0 13.9G  0 lvm  /
└─sda3            8:3    0   84G  0 part 
sr0              11:0    1 1024M  0 rom  
loop0             7:0    0  4.3G  0 loop /mnt/iso

验证8e

[root@xxx ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 419430400 sectors, 200.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 419430366
Partitions will be aligned on 2048-sector boundaries
Total free space is 209717181 sectors (100.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048        33554431   15.5 GiB    8E00  Linux LVM
   3        33554432       209715199   84.0 GiB    8E00  Linux LVM

PV阶段

现有PV

[root@xxx ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               15.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3970
  Free PE               0
  Allocated PE          3970
  PV UUID               S13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C

现在PV的大小是15G。

创建PV

[root@xxx ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.

验证PV

[root@xxx ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               15.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3970
  Free PE               0
  Allocated PE          3970
  PV UUID               S13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C
   
  "/dev/sda3" is a new physical volume of "84.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               84.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Ssb5Y6-gD5q-heAE-sil9-oIU3-kdX8-B0pqLS

VG阶段

现有VG

[root@xxx ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <15.51 GiB
  PE Size               4.00 MiB
  Total PE              3970
  Alloc PE / Size       3970 / <15.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               F3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC

VG也是15G。

扩容VG

[root@xxx ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended

在这个阶段遇到Couldn't create temporary archive name.问题,只需要清理一部分无用文件腾出一点点磁盘空间即可。

验证VG

[root@xxx ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               99.50 GiB
  PE Size               4.00 MiB
  Total PE              25473
  Alloc PE / Size       3970 / <15.51 GiB
  Free  PE / Size       21503 / <84.00 GiB
  VG UUID               F3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC

Free部分已经不是0了。

LV阶段

现有LV

[root@xxx ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                c2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laM
  LV Write Access        read/write
  LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:56 +0800
  LV Status              available
  # open                 2
  LV Size                1.60 GiB
  Current LE             410
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                r2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8
  LV Write Access        read/write
  LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:57 +0800
  LV Status              available
  # open                 1
  LV Size                <13.91 GiB
  Current LE             3560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

这里主要扩容这个LV:/dev/centos/root。

扩容LV

[root@xxx ~]# lvresize -L +83.99GB /dev/centos/root
  Rounding size to boundary between physical extents: 83.99 GiB.
  Size of logical volume centos/root changed from <13.91 GiB (3560 extents) to <97.90 GiB (25062 extents).
  Logical volume centos/root successfully resized

验证LV

[root@xxx ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                c2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laM
  LV Write Access        read/write
  LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:56 +0800
  LV Status              available
  # open                 2
  LV Size                1.60 GiB
  Current LE             410
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                r2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8
  LV Write Access        read/write
  LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:57 +0800
  LV Status              available
  # open                 1
  LV Size                <97.90 GiB
  Current LE             25062
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

更新扩容

[root@xxx ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=911360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3645440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 3645440 to 25663488

验证扩容

[root@xxx ~]# df -lh
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   98G   14G   84G   15% /
devtmpfs                 3.8G     0  3.8G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G  442M  3.4G   12% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/sda1                497M  295M  202M   60% /boot
tmpfs                    782M   12K  782M    1% /run/user/42
/dev/loop0               4.3G  4.3G     0  100% /mnt/iso
tmpfs                    782M     0  782M    0% /run/user/0

总结

主要就是创建8e分区,然后用pvcreate命令创建PV,再使用vgextend命令来扩容VG,再使用lvresize命令扩容LV,最后使用xfs_growfs命令更新扩容。

参考

本文转载自:http://linux.vbird.org/linux_basic/0420quota.php#lvm_whatis

亚林瓜子

亚林瓜子

粉丝 23
博文 254
码字总数 87653
作品 0
长沙
高级程序员
私信 提问
VMware虚拟机中CentOS 7的硬盘空间扩容

查看centos7系统挂载点信息 扩展VMWare-centos7硬盘空间 对新增加的硬盘进行分区、格式化 添加新LVM到已有的LVM组,实现扩容 1.查看centos7系统挂载点信息 df -h查看挂载点信息 2.扩展VMWar...

kim_o
2018/08/16
554
0
LVM2逻辑卷之1——创建及扩容

一、背景介绍 LVM2逻辑卷由于支持空间的动态扩展或收缩,在中小企业中有一定的使用场景,在CentOS5、6系统中经常会见到,从CentOS7以后默认的文件系统由ext4改为btrfs,而btrfs也支持空间的动...

科技小能手
2017/11/12
0
0
CentOS7 LVM添加硬盘及扩容

一、LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制。LVM将一个或多个磁盘分区(PV)虚拟为一个卷组(VG),相当于一个大的硬盘,...

张斌_青岛
2015/03/13
0
0
XenServer 虚拟机(centos7.2)扩容LVM磁盘分区的方法

XenServer 虚拟机(centos7.2)扩容LVM磁盘分区的方法 说明:XenServer(6.2)里面安装的虚拟机(centos7),分区的时候采用的是LVM磁盘分区,文件系统格式为xfs 需求:现在需要扩容虚拟机根分区/...

yikayi
2017/02/14
0
0
服务器磁盘lvm管理轻松在线扩容

centos 7.4 x86_64 场景:安装服务器系统时就需要规划好磁盘空间,并用lvm建立分区,以便随后磁盘空间耗尽,随时添加。 lvm原理: PV(physical volume):物理卷 即整个物理硬盘或物理硬盘上的...

hiwill
2018/08/24
27
0

没有更多内容

加载失败,请刷新页面

加载更多

二叉查找树的第 K 个结点

private TreeNode ret;private int cnt = 0;public TreeNode KthNode(TreeNode pRoot, int k) { inOrder(pRoot, k); return ret;}private void inOrder(TreeNode root......

Garphy
53分钟前
4
0
windo8 weblogic

需要的软件包 现在安装jdk 则先进入你电脑自带jdk \bin目录下 然后java -jar 执行你的jar包就可以了 欢迎界面直接点击下一步,跳到更新界面,直接选择跳过 然后选择安装目录(注意:目录不要有...

恩多
今天
8
0
Activiti 批注

Activiti添加批注(comment)信息 在每次提交任务的时候需要描述一些批注信息,例如:请假流程提交的时候要描述信息为什么请假,如果领导驳回可以批注驳回原因等  1、添加批注 // 由于流程...

奔跑的android
今天
4
0
centos7命令行和图形界面的相互切换

最近安装了centos7,发现在命令行和图形界面的相互切换命令上,与centos以往版本有很大不同。 1,centos7默认安装后,跟其他版本一样,启动默认进入图形界面; 2,在图形化桌面,右击鼠标,选...

无名氏的程序员
今天
6
0
快速失败 (fail-fast) 和安全失败 (fail-safe) 的区别是什么

一:快速失败(fail—fast) 在用迭代器遍历一个集合对象时,如果遍历过程中对集合对象的内容进行了修改(增加、删除、修改),则会抛出Concurrent Modification Exception。 原理:迭代器在...

Bb进阶
今天
7
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部