CentOS 7 LVM创建与使用
添加硬盘驱动器
[root@linuxprobe ~]# fdisk /dev/sdb
# enter operation mode for partitionsWelcome 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): p
# show partition tableDisk /dev/vdb: 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: 0xd97d5b18Device Boot Start End Blocks Id System# noneCommand (m for help): n
# create a partitionPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): p
# primaryPartition number (1-4, default 1): 1
# specify partition numberFirst sector (2048-41943039, default 2048): # starting cylinderUsing default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): # end cylinderUsing default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
# show partition tableDisk /dev/vdb: 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: 0xd97d5b18Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux# just createdCommand (m for help): 5
# change type
Selected partition 1
Hex code (type L to list all codes): L # 查看全部格式
# show list0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris1 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 Syrinx5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS accessa OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/Ob W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStorc W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fse W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPTf 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 # 改变硬盘格式
Selected partition 1
Hex code (type L to list all codes): 8e #为LVM标识
# specify Linux LVMChanged type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
# show partition tableDisk /dev/vdb: 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: 0xd97d5b18Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 8e Linux LVM# changedCommand (m for help): w #保存更改
# save and quitThe 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.[root@linuxprobe ~]# sfdisk -l /dev/sdb
# show statusDisk /dev/vdb: 41610 cylinders, 16 heads, 63 sectors/track
sfdisk: Warning: The partition table looks like it was madefor C/H/S=*/3/34 (instead of 41610/16/63).
For this listing I'll assume that geometry.Units: cylinders of 52224 bytes, blocks of 1024 bytes, counting from 0Device Boot Start End #cyls #blocks Id System
/dev/vdb1 20+ 411206- 411187- 20970496 8e Linux LVM
sfdisk: start: (c,h,s) expected (20,0,9) found (2,0,33)sfdisk: end: (c,h,s) expected (1023,2,34) found (650,2,34)/dev/vdb2 0 - 0 0 0 Empty
/dev/vdb3 0 - 0 0 0 Empty
/dev/vdb4 0 - 0 0 0 Empty
管理Phisical卷
- 创建物理卷
[root@linuxprobe ~]# pvcreate /dev/sdb1Physical volume "/dev/sdb1" successfully created# 制定创建的PV大小
[root@linuxprobe ~]# pvcreate --setphysicalvolumesize 50G /dev/sdb1Physical volume "/dev/sdb1" successfully created
- 显示物理卷
[root@linuxprobe ~]# pvdisplay /dev/sdb1"/dev/sdb1" is a new physical volume of "20.00 GiB"--- NEW Physical volume ---PV Name /dev/sdb1VG Name PV Size 20.00 GiBAllocatable NOPE Size 0 Total PE 0Free PE 0Allocated PE 0PV UUID o0nkv0-1XbS-O5Sa-OjKK-kEaL-IVd7-UrSrCP
- 改变物理卷大小
[root@linuxprobe ~]# pvresize --setphysicalvolumesize 10G /dev/sdb1Physical volume "/dev/sdb1" changed1 physical volume(s) resized / 0 physical volume(s) not resized
[root@linuxprobe ~]# pvdisplay /dev/sdb1"/dev/sdb1" is a new physical volume of "10.00 GiB"--- NEW Physical volume ---PV Name /dev/sdb1VG Name PV Size 10.00 GiBAllocatable NOPE Size 0 Total PE 0Free PE 0Allocated PE 0PV UUID o0nkv0-1XbS-O5Sa-OjKK-kEaL-IVd7-UrSrCP
- 扫描pv的信息状态
[root@linuxprobe ~]# pvs /dev/sdb1 PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 20.00g 20.00g
[root@linuxprobe ~]# pvscanPV /dev/sda2 VG centos lvm2 [19.51 GiB / 40.00 MiB free]PV /dev/sdb1 lvm2 [20.00 GiB]Total: 2 [39.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [20.00 GiB]
- 删除pv
[root@linuxprobe ~]# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped
[root@linuxprobe ~]# pvdisplay /dev/sdb1Failed to find physical volume "/dev/sdb1".
- 创建卷组(已创建PV)
[root@linuxprobe ~]# vgcreate vg_linux/dev/sdb1Volume group "vg_linux" successfully created# 制定多个磁盘设备如下:
[root@linuxprobe ~]# vgcreate vg_linux /dev/sdb1 /dev/sdd1Volume group "vg_linux" successfully created
- 显示卷组信息
[root@linuxprobe ~]# vgcreate vg_linux /dev/sdb1 Volume group "vg_linux" successfully created
[root@linuxprobe ~]# vgdisplay vg_linux--- Volume group ---VG Name vg_linuxSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 20.00 GiBPE Size 4.00 MiBTotal PE 5119Alloc PE / Size 0 / 0 Free PE / Size 5119 / 20.00 GiBVG UUID RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
- 改变卷组名称
[root@linuxprobe ~]# vgrename vg_linux vg_probeVolume group "vg_linux" successfully renamed to "vg_probe"
[root@linuxprobe ~]# vgdisplay vg_probe--- Volume group ---VG Name vg_probeSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 2VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 20.00 GiBPE Size 4.00 MiBTotal PE 5119Alloc PE / Size 0 / 0 Free PE / Size 5119 / 20.00 GiBVG UUID RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
- 扩展卷组
# add sdc1 to vg_probe[root@linuxprobe ~]# vgextend vg_probe /dev/sdc1Volume group "vg_probe" successfully extended
[root@linuxprobe ~]# vgdisplay vg_probe--- Volume group ---VG Name vg_probeSystem IDFormat lvm2Metadata Areas 2Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 2Act PV 2VG Size 40.00 GiBPE Size 4.00 MiBTotal PE 20479Alloc PE / Size 0 / 0Free PE / Size 20479 / 160.00 GiBVG UUID RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
- 卷组缩减
# remove sdc1 from vg_probe [root@linuxprobe ~]# vgreduce vg_probe /dev/sdc1Removed "/dev/sdc1" from volume group "vg_probe "
[root@linuxprobe ~]# vgdisplay vg_probe --- Volume group ---VG Name vg_probe System IDFormat lvm2Metadata Areas 1Metadata Sequence No 2VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 20.00 GiBPE Size 4.00 MiBTotal PE 20479Alloc PE / Size 0 / 0Free PE / Size 20479 / 80.00 GiBVG UUID RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
- 删除卷组
# disable target volume group first and delete it
[root@linuxprobe ~]# vgchange -a n vg_probe0 logical volume(s) in volume group "vg_probe" now active
[root@linuxprobe ~]# vgremove vg_probeVolume group "vg_data" successfully removed
创建LV
[root@linuxprobe ~]# lvcreate -L 5G -n lv_data vg_probe # Logical volume "lv_data" created.
[root@linuxprobe ~]# lvcreate -l 100%FREE -n lv_data vg_probeLogical volume "lv_data" already exists in volume group "vg_probe" # lv已存在
[root@linuxprobe ~]# lvcreate -l 100%FREE -n lv_probe vg_probe # 新建LV使用全部的vgLogical volume "lv_probe" created.
[root@linuxprobe ~]# vgsVG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- 19.51g 40.00mvg_probe 1 2 0 wz--n- 20.00g 0
- lv显示
[root@linuxprobe ~]# lvdisplay /dev/vg_probe/lv_probe --- Logical volume ---LV Path /dev/vg_probe/lv_probeLV Name lv_probeVG Name vg_probeLV UUID s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiwLV Write Access read/writeLV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800LV Status available# open 0LV Size 15.00 GiBCurrent LE 3839Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:3
- 改变LV名称
[root@linuxprobe ~]# lvrename vg_probe lv_probe lv_linuxRenamed "lv_probe" to "lv_linux" in volume group "vg_probe"
[root@linuxprobe ~]# lvdisplay /dev/vg_probe/lv_linux --- Logical volume ---LV Path /dev/vg_probe/lv_linuxLV Name lv_linuxVG Name vg_probeLV UUID s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiwLV Write Access read/writeLV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800LV Status available# open 0LV Size 15.00 GiBCurrent LE 3839Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:3[root@linuxprobe ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot centos -wi-ao---- 17.47g swap centos -wi-ao---- 2.00g lv_data vg_probe -wi-a----- 5.00g lv_linux vg_probe -wi-a----- 15.00g
- 拍摄逻辑卷快照
[root@linuxprobe ~]# lvcreate -s -L 5G -n snap-lv_linux /dev/vg_probe/lv_linux Logical volume "snap-lv_linux" created.
[root@linuxprobe ~]# lvdisplay /dev/vg_probe/lv_linux /dev/vg_probe/snap-lv_linux --- Logical volume ---LV Path /dev/vg_probe/lv_linuxLV Name lv_linuxVG Name vg_probeLV UUID s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiwLV Write Access read/writeLV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800LV snapshot status source ofsnap-lv_linux [active]LV Status available# open 0LV Size 5.00 GiBCurrent LE 1280Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:3--- Logical volume ---LV Path /dev/vg_probe/snap-lv_linuxLV Name snap-lv_linuxVG Name vg_probeLV UUID sLLQ2y-IOiv-fgtD-RpPr-y7pw-YWnZ-zqwXhDLV Write Access read/writeLV Creation host, time linuxprobe.org, 2017-01-03 19:30:49 +0800LV snapshot status active destination for lv_linuxLV Status available# open 0LV Size 5.00 GiBCurrent LE 1280COW-table size 5.00 GiBCOW-table LE 1280Allocated to snapshot 0.00%Snapshot chunk size 4.00 KiBSegments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:6
- 扩展逻辑卷
[root@linuxprobe ~]# lvextend -L 6G /dev/vg_probe/lv_dataSize of logical volume vg_probe/lv_data changed from 5.00 GiB (1280 extents) to 6.00 GiB (1536 extents).Logical volume lv_data successfully resized.
[root@linuxprobe ~]# lvdisplay /dev/vg_probe/lv_data --- Logical volume ---LV Path /dev/vg_probe/lv_dataLV Name lv_dataVG Name vg_probeLV UUID 7MVyp5-xw22-dPnu-vQp8-pa5C-ONvs-LQfS09LV Write Access read/writeLV Creation host, time linuxprobe.org, 2017-01-03 19:22:52 +0800LV Status available# open 0LV Size 6.00 GiBCurrent LE 1536Segments 2Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:2[root@linuxprobe ~]# xfs_growfs /mnt/
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1144832 blks= sectsz=512 attr=2, projid32bit=1= crc=0 finobt=0
data = bsize=4096 blocks=4579328, 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
[root@linuxprobe ~]# resize
resize2fs resizecons resizepart
[root@linuxprobe ~]# resize2fs /dev/vg_probe/lv_data #重新格式化
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/vg_probe/lv_data
Couldn't find valid filesystem superblock.
- 减少逻辑卷。
首先卸载目标设备。
[root@linuxprobe ~]# lvreduce -L 5G /dev/vg_probe/lv_data WARNING: Reducing active logical volume to 5.00 GiBTHIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_data? [y/n]: ySize of logical volume vg_probe/lv_data changed from 6.00 GiB (1536 extents) to 5.00 GiB (1280 extents).Logical volume lv_data successfully resized.
[root@linuxprobe ~]# lvchange -an /dev/vg_probe/lv_data
[root@linuxprobe ~]# lvremove /dev/vg_probe/lv_dataLogical volume "lv_data" successfully removed
常见报错
- resize2fs /dev/cl_kvm-centos7/opt
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/cl_kvm-centos7/opt
Couldn't find valid filesystem superblock.
注:由于CentOS7文件系统格式为xfs,因此使用LVM对磁盘进行管理的时候原来的命令有些问题,下面介绍CentOS7下对LVM操作。
# 下载工具包
yum install xfsprogs -y # 重新格式化挂载分区(类似mkfs.ext4)
mkfs.xfs -f /dev/cl_kvm-centos7/data# 重新resize分区
xfs_growfs /dev/mapper/cl_kvm--centos7-var
- 下面两步完成,就能正常的mount和umount啦。。。
CentOS 7 LVM创建与使用相关推荐
- centos的mysql怎么删用户_linux/centos给Mysql创建用户、授权、查看、删除、修改密码、撤...
linux/centos给Mysql创建用户.授权.查看.删除.修改密码.撤 linux/centos给Mysql创建用户.授权.查看.删除.修改密码.撤销权限 linux/centos给Mysql创 ...
- linux增加阵列磁盘空间,Linux Ubuntu系统下通过LVM创建软raid来实现硬盘合并大小
将两块空硬盘合并为"一块",挂载到指定目录下,达到在一个目录使用3块硬盘所有空间的效果. 条件: 硬盘1 /dev/sda 硬盘2 /dev/sdb 硬盘3 /dev/sdc 方法 ...
- 逻辑卷LVM创建及扩容方法
逻辑卷是管理磁盘的一种方式,特点是可以随意扩张大小,缩减大小,下面就来说下创建逻辑卷和扩容的方法. 环境:VMware Workstation 15 Pro: CentOS 7: 一.准备好一块物理磁 ...
- linux 建立lun分区,系统运维|在 iSCSI Target 服务器中使用LVM创建和设置LUN(二)
LUN是逻辑单元号,它与iSCSI存储服务器共享.iSCSI 目标器通过TCP/IP网络共享它的物理驱动器给发起程序(initiator).这些来自一个大型存储(SAN:Storage Area Ne ...
- 银河麒麟高级服务器操作系统V10——LVM创建与使用
银河麒麟高级服务器操作系统V10--LVM创建与使用 fdisk -l 查看当前分区表信息 fdisk 新增一块 2 TB 分区并个性 ID 为 8e fdisk和lsblk 查看最新分区信息 将物理 ...
- lvm创建逻辑卷简单过程
lvm创建逻辑卷简单过程 1 lvm是什么? lvm,基本的逻辑卷管理器,最大的好处是可以动态的调整逻辑卷. 2 lvm是怎么组成的 一个或者几个物理硬盘--创建分区--组成物理卷pv--vg--lv ...
- 在Centos系统下创建与Windows的共享文件夹
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 1分钟实现-->在Centos系统下创建与Windows的共享文件夹 前言 提示:这里可以添加本文要记录的大概内容: 在我的项目 ...
- HP-UX磁盘管理:新磁盘发现、LVM创建与扩展
[转载]HP-UX磁盘管理:新磁盘发现.LVM创建与扩展 原文地址:http://www.toxingwang.com/linux-unix/unix/1488.html 一.HP-UX的文件系统: ...
- 磁盘阵列raid LVM创建
1.磁盘阵列(raid)详解:磁盘阵列,有独立磁盘构成的具有冗余能力的阵列. raid0:(一种简单的.无数据校验的数据条带化技术)它的性能是所有raid中是最好的. 特点:成本低,高读写性能: 10 ...
最新文章
- iOS线程锁中你还不知道的内容
- python urllib2及beautifulsoup学习
- Netty中实现多客户端连接与通信-以实现聊天室群聊功能为例(附代码下载)
- 定义加密函数程序python_一个python自定义的加密解密函数
- 非root用户组启动sftp_如何在 Debian 10 中配置 Chroot 环境的 SFTP 服务 | Linux 中国
- 美图秀秀滤镜之饱和度
- Linux中防火墙端口查看,开启与关闭
- Javascript面向对象特性
- 大数据系列1-规划安排
- 列表、元组、字典、集合的定义与操作
- Lua学习(一):luac、luajit编译与反编译
- 微表情测试软件排行榜,微表情心理测试分析系统:以“微”见智,识情绪辨人心...
- assimp android build,Android assimp编译及引用
- css3ps插件,Photoshop图层转CSS3代码之神器-CSS3Ps插件
- 【开箱即用】HTML5教程
- 华为手机word插件加载失败_c#调用word的组件时失败解决方法
- 今日头条精准引流技巧,今日头条超简单的引流技巧
- 大数据培训课程内容介绍
- 【Linux正则表达式之grepegrep】
- 他竟然只用25万美元换来苹果1/3的股票?
热门文章
- 基于SpringBoot+MybatisPlus+Vue+MySQL的体育用品商城设计
- 拼多多登录一直连接服务器,拼多多有自己的服务器吗
- 电脑网站如何用支付宝收款(php)
- 我的世界服务器怎么制作头颅,我的世界怎么用指令弄自己的头颅 | 手游网游页游攻略大全...
- Excel提取插入的PPT对象
- Google Pay India(UPI) 印度
- 前端面试八股文(详细版)—上
- 程序员写作能赚多少钱,怎么赚
- 如何用计算机算p,App Store 上的“计算器++P”
- C语言程序设计——结构体