lvm入门
实例:
使用lvm存储结构的主机需要扩容,现在我们已经将一个新的硬盘安装上去,将该新的硬盘的空间全部增加到主机上
20 ls /dev/sd* #查看新增加的硬盘名,我的为xvdb
21 ls /dev
22 fdisk -l
23 fdisk /dev/xvdb #对其进行操作(写下来大概是m,n,p,1,t,8e,w)
24 pvcreate /dev/xvdb1 #增加物理卷
25 vgdisplay #查看组,组名为cl
26 vgextend cl /dev/xvdb1 #扩展/dev/xvdb1到cl组
27 vgdisplay
28 lvdisplay #获取lv路径
29 lvresize -l +127999 /dev/cl/root #-l指定大小,因为前面已经vgextend,127999这个值可以从vgdisplay这里获取(Free PE)
30 df -h
31 df -Th #需要注意文件系统格式,如果是xfs格式,使用下一条命令,如果不是则是另一条resize2fs /dev/cl/root
32 xfs_growfs /dev/cl/root #xfs_growfs会自动扩展至最大可用值,这条命令只能用于文件系统是xfs的,文件系统可以通过df -Th查看,其他的文件系统就不是用这个命令了
33 df -h
可能会遇到一个问题,那就是在vgextend时报错,可能是因为磁盘太满了,建议清空部分文件,再次执行扩容
以下为详细过程及讲解
二次整理lvm:
首先,往系统中添加物理磁盘或虚拟磁盘,如果热插没有直接识别,可以尝试以下三条命令(或者是partprobe,不过这条命令我没试过,好像是fdisk之后才用的)
[root@localhost ~]# echo ‘- - -‘> /sys/class/scsi_host/host0/scan
[root@localhost ~]# echo ‘- - -‘> /sys/class/scsi_host/host1/scan
[root@localhost ~]# echo ‘- - -‘> /sys/class/scsi_host/host3/scan
首先是确认是否添加磁盘成功
ls /dev/xvd* (需要根据具体情况,我这个是xen虚拟平台的,如果是vm之类的虚拟软件,新设备名称可能是sd开头的),有显示则表示成功,或者有ll /dev下面的文件,修改时间为最新的即为新增磁盘设备
接下来就可以开始进行lvm操作了,直接上图看一下吧
先看一下,在原lvm基础上怎么扩展原空间吧
[root@localhost ~]# fdisk /dev/xvdb #进行fdisk操作,后面是我新增的磁盘
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xde5438c0.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): n #n是指新增分区
Command action
e extended
p primary partition (-)
p #这里还需要按p
Partition number (-): 1 #新增分区号
First cylinder (-, default ): #分区开始位置,回车默认就可以了
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): #选择分区大小,可以使用例如+50G然后回车确认,+50G的意思是该分区大小分50G
Using default value Command (m for help): t #设置分区类型
Selected partition 1 #如果有多个分区,这里也有分别选中想操作的分区号
Hex code (type L to list codes): 8e #我选择的是LVM类型,可以使用L查看全部类型
Changed system type of partition to 8e (Linux LVM) Command (m for help): w #保存这次修改并退出
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# vgextend VolGroup /dev/xvdb1 #将新增的分区加到vg,扩大vg容量,加入vg的好处是在vg中的lv可以动态扩展大小(注意xvdb1,也就是我们刚才选择的分区号,如果是选的2的话,则应是xvdb2)
Physical volume "/dev/xvdb1" successfully created
Volume group "VolGroup" successfully extended
[root@localhost ~]# lvextend -L +52G /dev/VolGroup/lv_root #这里比较烦,我增加的是52G的磁盘,提示空间不够,那就相当于有损耗呗,空间稍微减少个1G就成功了,后面的lv_root可以从lvdisplay中查看
Insufficient free space: extents needed, but only available
[root@localhost ~]# lvextend -L +51G /dev/VolGroup/lv_root
Size of logical volume VolGroup/lv_root changed from 28.31 GiB ( extents) to
79.31 GiB ( extents). Logical volume lv_root successfully resized
[root@localhost ~]# resize2fs /dev/VolGroup/lv_root #扩展之后,还需重置lv大小,resize2fs是针对etx4的,xfs是xfs_growfs,不知道为什么,这里不用格式化lv卷。执行之后df -Th应该就能显示增加成功了
resize2fs 1.41. (-May-)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = , new_desc_blocks =
Performing an on-line resize of /dev/VolGroup/lv_root to (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now blocks long.
接下来是新增独立的vg,重新划分,而不是在原来已经划分好的基础上
[root@localhost ~]# fdisk /dev/xvdc #fdisk 新增磁盘名(这里我将一块磁盘划分了4个分区,所以这里内容有点多重复的也多)
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9f0be0ba.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's 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 (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +24G Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +125G Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +64G Command (m for help): n
Command action
e extended
p primary partition (-)
p
Selected partition
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): t
Partition number (-):
Hex code (type L to list codes): 8e
Changed system type of partition to 8e (Linux LVM) Command (m for help): t
Partition number (-): 2 #每一个分区都需要分别选择类型
Hex code (type L to list codes): 8e
Changed system type of partition to 8e (Linux LVM) Command (m for help): t
Partition number (-):
Hex code (type L to list codes): 8e
Changed system type of partition to 8e (Linux LVM) Command (m for help): t
Partition number (-):
Hex code (type L to list codes): 8e
Changed system type of partition to 8e (Linux LVM) Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkdir /tmp #创建相应的挂载分区,嗯嗯,我这里是错误示范,这几个文件夹是系统自带的,我删掉之后就出现问题,所以自己另起个名字吧
[root@localhost ~]# mkdir /var
[root@localhost ~]# mkdir /srv/Bigdata
[root@localhost ~]# mkdir /opt
[root@localhost ~]# vgcreate datavg /dev/xvdc
xvdc xvdc1 xvdc2 xvdc3 xvdc4
[root@localhost ~]# vgcreate datavg /dev/xvdc1 /dev/xvdc2 /dev/xvdc3 /dev/xvdc4 #这里好像是在执行vgcreate时同时执行pvcreate了
#新增vg,只有在vg里面的lv才能动态扩展
Physical volume "/dev/xvdc1" successfully created
Physical volume "/dev/xvdc2" successfully created
Physical volume "/dev/xvdc3" successfully created
Physical volume "/dev/xvdc4" successfully created
Volume group "datavg" successfully created
[root@localhost ~]# lvcreate -n tmplv +24G datavg
Please specify either size or extents
Run `lvcreate --help' for more information.
[root@localhost ~]# lvcreate -n tmplv -L +23G datavg #增加一个lv,这个lv是用来挂载分区的
Logical volume "tmplv" created
[root@localhost ~]# mkfs.ext4 /dev/datavg/tmplv #挂载独立分区时就需要进行mkfs格式化,后面跟的是lv路径,可以使用lvdisplay查看
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1507328 inodes, 6029312 blocks
301465 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
184 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/datavg/tmplv /tmp #挂载时使用的是mount lv路径(也是lvdisplay查看) 挂载路径,注意,这条命令最好加入/etc/fstab里面,加入之后就可以开机自动挂载了
[root@localhost ~]# lvcreate -n varlv -L +124G datavg #接下来这些就是新增第二第三第四个分区了
Logical volume "varlv" created
[root@localhost ~]# mkfs.ext4 /dev/datavg/varlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
8126464 inodes, 32505856 blocks
1625292 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
992 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/datavg/varlv /var
[root@localhost ~]# lvcreate -n datalv -L +63G datavg
Logical volume "datalv" created
[root@localhost ~]# mkfs.ext4 /dev/datavg/datalv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
4128768 inodes, 16515072 blocks
825753 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
504 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/datavg/datalv /srv/Bigdata
[root@localhost ~]# lvcreate -n optlv -L +310G datavg
Volume group "datavg" has insufficient free space (79356 extents): 79360 required
.[root@localhost ~]# lvcreate -n optlv -L +309G datavg
Logical volume "optlv" created
[root@localhost ~]# mkfs.ext4 /dev/datavg/optlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
20250624 inodes, 81002496 blocks
4050124 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2472 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/datavg//opt
datalv optlv tmplv varlv
[root@localhost ~]# mount /dev/datavg/optlv /opt
e2fsck -f /dev/storage/vo 检查磁盘完整性
resize2fs /dev/storage/vo 重置硬盘容量(应该是相当于更新磁盘的意思吧),扩容的话是先扩容再检查最后重置并挂载,减容的话就是先检查磁盘完整性再重置大小并挂载
mount -a
df -h 查看磁盘容量
umount /bplvm 为后面缩小逻辑卷做准备
e2fsck -f /dev/storage/vo
resize2fs /dev/storage/vo 120M 将磁盘容量减少至120M
lvreduce -L 120M /dev/storage/vo 减少120M(如果执行完上面那条命令再执行这条,应该会减为0M了吧,没试过)
删除逻辑卷:
umount /bplvm
vim /etc/fstab 删除自己添加的那条挂载vo的命令的那行
lvremove /dev/storage/vo 删除LV逻辑卷设备
vgremove storage 删除VG卷组
pvremove /dev/sdb /dev/sdc 删除PV物理卷设备
注意删除的顺序是按照上面的删除顺序的,跟增加时正好相反,不能乱来
lvm入门的更多相关文章
- linux入门系列13--磁盘管理之RAID、LVM技术
前一篇文章学习了磁盘分区.格式化.挂载等相关知识,本文将讲解RAID和LVM技术. 磁盘管理操作主要是运维人员用的较多,如果只是单纯的开发人员,可以先略过本文.但是在很多小公司里往往都是一人多用,运维 ...
- MySQL入门02-MySQL二进制版本快速部署
在上篇文章 MySQL入门01-MySQL源码安装 中,我们介绍了MySQL源码安装的方法. 源码安装虽然有着更加灵活和更加优化等诸多优势.但源码编译安装部署的过程相对复杂,而且整个过程所花费的时间很 ...
- OpenStack云计算快速入门之二:OpenStack安装与配置
原文:http://blog.chinaunix.net/uid-22414998-id-3265685.html OpenStack云计算----快速入门(2) 该教程基于Ubuntu12.04版, ...
- OpenStack云计算快速入门之一:OpenStack及其构成简介
原文:http://blog.chinaunix.net/uid-22414998-id-3263551.html OpenStack云计算快速入门(1) 该教程基于Ubuntu12.04版,它将帮助 ...
- Linux快速入门01-基础概念
4年多前,刚到上海时报过一个关于Oracle的培训班,在那里接触到了Linux,不过一直都没真正去试着使用它.现在经过慢慢的成长,越来越觉得,Linux是每一个服务端工程师必须掌握的系统,即使是现在最 ...
- Linux快速入门03-系统管理
这部分将涉及常用的各类linux命令和一些系统高级管理特性,尤其是shell script的创建,这部分在系统自动化运维时会很有作用. Linux系列文章 快速入门系列--Linux--01基础概念 ...
- Docker与容器快速入门
Docker之风席卷全球,但很多人觉得docker入门确实不太容易,其原因在于很多知识点上没准备好,在docker解决了什么问题.怎么解决的.用什么技术解决的都还没想清楚的时候就去探索docker组件 ...
- Kvm虚拟化的一种打包及部署方案(采用tar包,lvm方式)
Kvm虚拟化的一种打包部署方案(采用tar包,lvm方式) –-–-–-2016年终总结 一 毕业之后跟师兄学到的第一块主要内容,理解花了不少时间.期间经历了shell的入门.linux基础知识入门. ...
- Linux 系统从入门到精通的学习大纲;
以前没有接触过Linux,生产环境需要,有时候遇到问题,百度一下,问题解决了,在遇到问题,在百度,有时候问题是如何解决的,为什么会解决有点丈二的和尚摸不着头脑, 为此,想用一段时间,系统的学习下Lin ...
随机推荐
- js如何生成一个对象,并转化为json字符串
js如何生成一个对象,并转化为json字符串,很多人都会误写为: var ary = []; var obj = {}; for (var i = 0; i < 3; i++) { obj.na ...
- tp配置
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE ...
- jquery元素插入、删除、清空、找父子级元素
1)jquery元素插入 <!--位置1--> <div id='test'> <!--位置2--> <div>测试</div> <! ...
- 接触到的加密算法MD5、SHA1(转)
参考链接: https://blog.csdn.net/u012611878/article/details/54000607 https://blog.csdn.net/worm0527/artic ...
- python的编码与转码
编码问题一直是初学者的难题,搞不明白.甚至一些程序员做了多年的程序,但是编码一直整不清,下面就来认识认识编码吧. ASCII(American Standard Code for Informatio ...
- AOP 实现请求参数打印
1.编写打印方法 import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; import org.aspe ...
- centos6.6安装hadoop-2.5.0(一、本地模式安装)
操作系统:centos6.6(一台服务器) 环境:selinux disabled:iptables off:java 1.8.0_131 安装包:hadoop-2.5.0.tar.gz hadoop ...
- Python 栈和队列,双向队列
# 栈 # 特点: 先进后出 class StackFullException(Exception): pass class StackEmptyException(Exception): pass ...
- Golang福利爬虫
没事的时候跑两把,穷人专用. package main import ( "bytes" "fmt" "github.com/PuerkitoBio/ ...
- 使用Redis做为MySQL的缓存
OS: Ubuntu 16.04.4 x64 更新并安装必要的工具 apt update && apt upgrade -y && apt dist-upgrade - ...