LVM磁盘创建与扩容
以虚拟机为例
1、在虚拟机上添加新磁盘,点击虚拟机→设置->添加,最后如下图。
2、进入系统fdisk -l,查看当前磁盘信息
[root@master shell]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000af178 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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@master shell]#
发现没有读到我们新添加的磁盘,我们重启下虚拟机。
如果不想重启,或者是生产上的服务器,不允许重启,可以使用partprobe,在线更新分区表。
# partprobe在线更新分区信息表,获取最新的磁盘信息
[root@master ~]# partprobe
重新使用fdisk -l命令查看,发现多了一块21.5GB的/dev/sdb磁盘
# fdisk -l 重新查看一下
[root@master ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.5M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 8.0G 4.8G 3.3G 60% /
/dev/sda1 xfs 1014M 167M 848M 17% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[root@master ~]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000af178 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM Disk /dev/sdb: 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 /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
3、fdisk在新的磁盘上创建分区
[root@master ~]# fdisk /dev/sdb # 注意,这里的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 0xe1f69387. Command (m for help): n # new新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # 选择主分区
Partition number (1-4, default 1): 1 # 分区编号,直接回车,选择默认的1就好
First sector (2048-41943039, default 2048): # 设置起始扇区,直接回车,选择默认的
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): # 设置结束扇区,直接回车,默认选择到磁盘的最后一个扇区。
Using default value 41943039 # 默认分区的容量就是整个磁盘的容量
Partition 1 of type Linux and of size 20 GiB is set Command (m for help): p # print打印当前设置好的磁盘信息(注意,此时还没物理生效) Disk /dev/sdb: 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: 0xe1f69387 Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux Command (m for help): t # 输入t,修改磁盘格式为LVM格式
Selected partition 1
Hex code (type L to list all codes): 8e # 输入8e,8e代表LVM格式
Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p # 再次打印磁盘信息 Disk /dev/sdb: 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: 0xe1f69387 Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 8e Linux LVM Command (m for help): w # w开始保存设置的磁盘分区信息,此时才是真正作用生效了。
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
4、创建pv
创建LVM概念中的物理卷。
注意:这里要选带数字编号的磁盘,这里的/dev/sdb1就是上面我们用fdisk创建好的磁盘分区,1表示我们的分区编号,上面设置的是1,所以这里就是sdb1
[root@master ~]# pvscan # 查看当前系统上的物理卷信息
PV /dev/sda2 VG centos lvm2 [<9.00 GiB / 0 free]
Total: 1 [<9.00 GiB] / in use: 1 [<9.00 GiB] / in no VG: 0 [0 ]
[root@master ~]# pvcreate /dev/sdb1 # 创建物理卷,注意这里的磁盘尾号sdb1必须带数字
Physical volume "/dev/sdb1" successfully created.
[root@master ~]# pvscan
PV /dev/sda2 VG centos lvm2 [<9.00 GiB / 0 free]
PV /dev/sdb1 lvm2 [<20.00 GiB]
Total: 2 [<29.00 GiB] / in use: 1 [<9.00 GiB] / in no VG: 1 [<20.00 GiB]
5、将pv加入vg组,扩容vg
pv是物理卷,vg是卷组,多个pv组成一个vg,然后vg里面去构建逻辑卷组lv
如果系统没有vg,则创建vg组。
[root@master ~]# vgdisplay
[root@master ~]# vgscan
Reading volume groups from cache.
# vgcreate 后面可以接多个磁盘,比如vgcreate vgdata /dev/xvde1 /dev/xvde2,因为这里只有一块,所以就用一个
[root@master ~]# vgcreate vgdata /dev/xvde1 # 创建vg,vg名字设置为vgdata,/dev/xvde1是我们上面创建的pv卷的名字
Volume group "vgdata" successfully created
[root@master ~]# vgscan
Reading volume groups from cache.
Found volume group "vgdata" using metadata type lvm2
[root@master ~]# vgdisplay
--- Volume group ---
VG Name vgdata
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 <300.00 GiB
PE Size 4.00 MiB
Total PE 76799
Alloc PE / Size 0 / 0
Free PE / Size 76799 / <300.00 GiB
VG UUID bY9vpW-ALyF-YDxB-WCjj-Tlvg-04Jp-DWXdkm [root@master ~]#
如果有vg,则扩容
[root@master ~]# 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 <9.00 GiB
PE Size 4.00 MiB
Total PE 2303
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 0 / 0
VG UUID YSauT8-zhj2-05Yc-c4rb-VNqs-OjrX-ZB8eeE [root@master ~]# vgextend centos /dev/sdb1 # centos是原来就已经存在的卷组名字,/dev/sdb1是我们刚刚创建的pv名字
Volume group "centos" successfully extended
[root@master ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID YSauT8-zhj2-05Yc-c4rb-VNqs-OjrX-ZB8eeE
6、扩容LV
如果LV逻辑卷不存在,则创建
[root@yzjgxh2529638940 ~]# lvcreate -n lvdata -L 300G vgdata
Volume group "vgdata" has insufficient free space (76799 extents): 76800 required.
# 一般无法用到300G,所以稍微小一点就好了
[root@yzjgxh2529638940 ~]# lvcreate -n lvdata -L 299G vgdata
Logical volume "lvdata" created.
[root@yzjgxh2529638940 ~]# lvscan
ACTIVE '/dev/vgdata/lvdata' [299.00 GiB] inherit
[root@yzjgxh2529638940 ~]#
# 格式化该逻辑分区
[root@yzjgxh2529638940 ~]# mkfs.xfs /dev/vgdata/lvdata
meta-data=/dev/vgdata/lvdata isize=512 agcount=4, agsize=19595264 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=78381056, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=38272, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@yzjgxh2529638940 ~]#
如果LV逻辑卷存在,则扩容
[root@master ~]# lvscan
ACTIVE '/dev/centos/swap' [1.00 GiB] inherit
ACTIVE '/dev/centos/root' [<8.00 GiB] inherit
[root@master ~]# lvextend -L +19.5G /dev/centos/root
Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to <27.50 GiB (7039 extents).
Logical volume centos/root successfully resized.
7、resize使文件系统生效(重要)
[root@master ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.5M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 8.0G 4.8G 3.3G 60% /
/dev/sda1 xfs 1014M 167M 848M 17% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
# ext3,ext4使用resize2fs
[root@master ~]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.
# 这里需要扩容的是xfs,所以用xfs_growfs命令
[root@master ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2096128, 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 2096128 to 7207936
[root@master ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.5M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 28G 4.8G 23G 18% /
/dev/sda1 xfs 1014M 167M 848M 17% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
8、挂载
# 创建挂载的目录
[root@yzjgxh2529638940 ~]# mkdir /data
# 开始挂载
[root@yzjgxh2529638940 ~]# mount /dev/vgdata/lvdata /data/
[root@yzjgxh2529638940 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda2 xfs 36G 2.1G 34G 6% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 24K 32G 1% /dev/shm
tmpfs tmpfs 32G 18M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/vgdata-lvdata xfs 299G 33M 299G 1% /data
# 加入开机自动挂载
[root@yzjgxh2529638940 ~]# vim /etc/fstab #
# /etc/fstab
# Created by anaconda on Thu May 9 01:56:05 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
#
UUID=a83f4fdc-2ea1-4fec-a1e2-a42016ce0afe / xfs defaults 0 0
UUID=9e33bd6f-c68c-41c7-95c8-703f4fe8c3d4 swap swap defaults 0 0
/dev/vgdata/lvdata /data xfs defaults 0 0
到此,LVM扩容完成。
LVM磁盘创建与扩容的更多相关文章
- lvm之创建/扩容/缩容/快照及关闭的全部流程操作记录
基本介绍Linux用户安装Linux 操作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间.随着 Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解, l ...
- lvm分区创建和扩容
shell> fdisk /dev/xvdb #### 选择磁盘 Command (m for help): m #### 帮助 Command action a toggle a bootab ...
- LVM磁盘管理实战案例
前言:这是关于centos/linux上的LVM磁盘上的扩容,缩减,磁盘类型等收集做的案例 至于ubuntu系统的磁盘扩容参考:https://www.jianshu.com/p/5dcfcec687 ...
- 【转载】CentOS LVM磁盘扩容
转自:http://blog.sina.com.cn/s/blog_8882a6260101cpfs.html EXSI5.1主机有一个linux虚拟机,系统是centos运行httpd服务,因为是多 ...
- Linux:lvm磁盘分区,动态扩容
一.lvm磁盘分区: 1,查看新增的磁盘,需要使用root权限 fdisk -l 看到有一个新增的100G磁盘 2,对磁盘进行分区 fdisk /dev/xvdb 1,输入:n 表示创建一个新的分区( ...
- 03.LinuxCentOS系统root目录LVM磁盘扩容
根目录LVM扩容操作步骤: [root@centos7 ~]# df -lh文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 50G 7.7G 43G 6% / ...
- lvm 磁盘扩容
LVM磁盘管理 一.LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它由Heinz Mauelshagen在Linux 2.4内核上实现.LVM将一个或多个硬盘 ...
- VMware CentOS LVM磁盘扩容
一. 在虚拟机上增加磁盘空间 如下图. 增加完后会有提示 "磁盘已成功扩展.您必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统.是继续完成以下步骤才算成功. 二.调整虚拟机磁盘LVM ...
- LVM磁盘管理
http://www.cnblogs.com/gaojun/archive/2012/08/22/2650229.html Linux LVM硬盘管理及LVM扩容 LVM磁盘管理 一.LVM简介... ...
随机推荐
- word-break-ii leetcode C++
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...
- 力扣 - 剑指 Offer 06. 从尾到头打印链表.md
题目 剑指 Offer 06. 从尾到头打印链表 思路1(递归) 首先先遍历整个脸表,计算出链表的长度(用于初始化数组).然后进行递归,从链表头部递归到尾部,这期间什么都不做,直到递归到最后一个节点的 ...
- 使用Netty和动态代理实现一个简单的RPC
RPC(remote procedure call)远程过程调用 RPC是为了在分布式应用中,两台主机的Java进程进行通信,当A主机调用B主机的方法时,过程简洁,就像是调用自己进程里的方法一样.RP ...
- postman使用(待更新)
参考文档
- springboot使用之请求参数与基本注解
@PathVariable 作用:@PathVariable是spring3.0的一个新功能:接收请求路径中占位符的值,将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariabl ...
- Navicat15最新版本破解 亲测可用!!!(Navicat Premium 注册出现 No All Pattern Found! File Already Patched)
1.下载Navicat Premium官网https://www.navicat.com.cn/下载最新版本下载安装 2.本人网盘链接:https://pan.baidu.com/s/1ncSaxId ...
- Part 15 AngularJS ng init directive
The ng-init directive allows you to evaluate an expression in the current scope. In the following e ...
- 大爽Python入门教程 1-5 答案
大爽Python入门公开课教案 点击查看教程总目录 1 方向变换 >>> 51//4 12 >>> 51%4 3 答: 向左转51次之后, 小明面朝东方, 转过了1 ...
- xpath解析案例
xpath解析百度页面的百度一下 # 1)获取网页的源码 # 2)解析的服务器响应的文件 etree.HTML , 用来解析字符串格式的HTML文档对象,将传进去的字符串转变成 element 对象 ...
- 教你用SQL进行数据分析
摘要:采用 SQL 作为数据查询和分析的入口是一种数据全栈的思路. 本文分享自华为云社区<如何使用 SQL 对数据进行分析?>,作者:zuozewei . 前言 我们通过 OLTP(联机事 ...