CentOS 7 LVM创建与使用

原创 2017年01月03日 10:45:11

添加硬盘驱动器

 [root@linuxprobe ~]# fdisk /dev/sdb
# enter operation mode for partitions

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.

Command (m for help): p
# show partition table

Disk /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: 0xd97d5b18

   Device Boot      Start         End      Blocks   Id  System

 # none

Command (m for help): n  
# create a partition

Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended

Select (default p): p
# primary

Partition number (1-4, default 1): 1
# specify partition number

First sector (2048-41943039, default 2048):   # starting cylinder

Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):   # end cylinder

Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
# show partition table

Disk /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: 0xd97d5b18

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   83  Linux

 # just created

Command (m for help): 5
# change type
Selected partition 1
Hex code (type L to list all codes): L  # 查看全部格式
# show list

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  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  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  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 LVM

Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
# show partition table

Disk /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: 0xd97d5b18

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   8e  Linux LVM

 # changed

Command (m for help): w  #保存更改
# save and quit

The 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 status


Disk /dev/vdb: 41610 cylinders, 16 heads, 63 sectors/track
sfdisk: Warning: The partition table looks like it was made
  for 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 0

   Device 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/sdb1
  Physical volume "/dev/sdb1" successfully created

# 制定创建的PV大小
[root@linuxprobe ~]# pvcreate --setphysicalvolumesize 50G /dev/sdb1
  Physical 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/sdb1
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               o0nkv0-1XbS-O5Sa-OjKK-kEaL-IVd7-UrSrCP
  • 改变物理卷大小
[root@linuxprobe ~]#  pvresize --setphysicalvolumesize 10G /dev/sdb1
  Physical volume "/dev/sdb1" changed
  1 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/sdb1
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV 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 ~]# pvscan
  PV /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/sdb1
  Failed to find physical volume "/dev/sdb1".
  • 创建卷组(已创建PV)
 [root@linuxprobe ~]# vgcreate vg_linux/dev/sdb1
  Volume group "vg_linux" successfully created

# 制定多个磁盘设备如下:
[root@linuxprobe ~]# vgcreate vg_linux /dev/sdb1 /dev/sdd1
  Volume 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_linux
  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               20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5119 / 20.00 GiB
  VG UUID               RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
  • 改变卷组名称
[root@linuxprobe ~]# vgrename vg_linux vg_probe
  Volume group "vg_linux" successfully renamed to "vg_probe"
[root@linuxprobe ~]# vgdisplay vg_probe
  --- Volume group ---
  VG Name               vg_probe
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  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               20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5119 / 20.00 GiB
  VG UUID               RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
  • 扩展卷组
# add sdc1 to vg_probe

[root@linuxprobe ~]# vgextend vg_probe /dev/sdc1

  Volume group "vg_probe" successfully extended
[root@linuxprobe ~]# vgdisplay vg_probe

  --- Volume group ---
  VG Name               vg_probe
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               40.00 GiB
  PE Size               4.00 MiB
  Total PE              20479
  Alloc PE / Size       0 / 0
  Free  PE / Size       20479 / 160.00 GiB
  VG UUID               RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
  • 卷组缩减
# remove sdc1 from vg_probe 

[root@linuxprobe ~]# vgreduce vg_probe /dev/sdc1

  Removed "/dev/sdc1" from volume group "vg_probe "
[root@linuxprobe ~]# vgdisplay vg_probe 

  --- Volume group ---
  VG Name               vg_probe 
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  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               20.00 GiB
  PE Size               4.00 MiB
  Total PE              20479
  Alloc PE / Size       0 / 0
  Free  PE / Size       20479 / 80.00 GiB
  VG UUID               RnRfbj-DUC4-BdUB-kmov-L6Lh-uiCP-SVDsKq
  • 删除卷组
# disable target volume group first and delete it
[root@linuxprobe ~]# vgchange -a n vg_probe

  0 logical volume(s) in volume group "vg_probe" now active
[root@linuxprobe ~]# vgremove vg_probe
  Volume 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_probe
  Logical volume "lv_data" already exists in volume group "vg_probe"   #  lv已存在
[root@linuxprobe ~]# lvcreate -l 100%FREE -n lv_probe vg_probe  # 新建LV使用全部的vg
  Logical volume "lv_probe" created.
[root@linuxprobe ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree 
  centos     1   2   0 wz--n- 19.51g 40.00m
  vg_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_probe
  LV Name                lv_probe
  VG Name                vg_probe
  LV UUID                s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiw
  LV Write Access        read/write
  LV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             3839
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
  • 改变LV名称
[root@linuxprobe ~]# lvrename vg_probe lv_probe lv_linux
  Renamed "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_linux
  LV Name                lv_linux
  VG Name                vg_probe
  LV UUID                s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiw
  LV Write Access        read/write
  LV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             3839
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

[root@linuxprobe ~]# lvs
  LV       VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root     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_linux
  LV Name                lv_linux
  VG Name                vg_probe
  LV UUID                s11m21-qn5J-2gLx-IrFm-GZ1B-ZEZx-teHFiw
  LV Write Access        read/write
  LV Creation host, time linuxprobe.org, 2017-01-03 19:23:29 +0800
  LV snapshot status     source of
                         snap-lv_linux [active]
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/vg_probe/snap-lv_linux
  LV Name                snap-lv_linux
  VG Name                vg_probe
  LV UUID                sLLQ2y-IOiv-fgtD-RpPr-y7pw-YWnZ-zqwXhD
  LV Write Access        read/write
  LV Creation host, time linuxprobe.org, 2017-01-03 19:30:49 +0800
  LV snapshot status     active destination for lv_linux
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  COW-table size         5.00 GiB
  COW-table LE           1280
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:6
  • 扩展逻辑卷
[root@linuxprobe ~]# lvextend -L 6G /dev/vg_probe/lv_data
  Size 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_data
  LV Name                lv_data
  VG Name                vg_probe
  LV UUID                7MVyp5-xw22-dPnu-vQp8-pa5C-ONvs-LQfS09
  LV Write Access        read/write
  LV Creation host, time linuxprobe.org, 2017-01-03 19:22:52 +0800
  LV Status              available
  # open                 0
  LV Size                6.00 GiB
  Current LE             1536
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block 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 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_data? [y/n]: y
  Size 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_data
  Logical 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啦。。。
版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。

相关文章推荐

CentOS7下LVM的简单创建

一、环境:CentOS7虚拟机,挂载了一块2G硬盘 二、配置过程: 1、给硬盘分区:       创建三个分区,前两个512M,最后一个默认大小,1G多一些,最后一个默认指定大小,具体操作根据自己环境...

CentOS 7.2 安装MariaDB

MariaDB简介 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL...

DNS BIND之recursion递归

一般客户机和服务器之间属递归查询,当客户机向DNS服务器发出请求后,若DNS服务器本身不能解析,则会向另外的DNS服务器发出查询请求,得到结果后转交给客户机。主机向本地域名服务器的查询一般都是采用递归...

DNS BIND 搭建域名智能解析DNS服务器之配置

智能DNS的原理很简单:在用户解析一个域名的时候,判断一下用户的IP,然后跟DNS服务器内部的IP表匹配一下,看看用户是电信还是网通用户,然后给用户返回对应的IP地址。目前的域名服务运营商不提供智能D...

DNS BIND之运维管理脚本

为了方便管理bind,编写shell脚本,实现bind的start、stop、restart、status操作,并可以将脚本复制到/etc/rc.d/init.d/,添加以服务启动,并设置bind服务...

CentOS 7.2 部署邮件服务器(Postfix)

一、Postfix简介 Postfix 是一种电子邮件服务器,它是由任职于IBM华生研究中心(T.J. Watson Research Center)的荷兰籍研究员Wietse Venema为了改良s...

DNS BIND 搭建企业内部高可用DNS服务器

对于一个互联网企业来说,搭建一个公司内部的DNS服务器是很必要的,一来可以通过公司内网的DNS缓存提高公司内部的DNS解析效率,二来域名服务商提供的解析服务并不可靠,为了安全起见,自己搭建(当然也有不...

DNS BIND之DNS轮询负载

DNS负载均衡的优点是简单易行,而且实现代价小。它在DNS服务器中为同一个域名配置多个IP地址(即为一个主机名设置多条A资源记录),在应答DNS查询时,DNS服务器对每个查询将以DNS文件中主机记录的...

centos yum的配置文件 repo文件详解

什么是repo文件?repo文件是Fedora中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,repo文件中的...

DNS BIND之ACL、View、ZONE介绍

BIND主配置文件由named进程运行时首先读取,文件名为named.conf,默认在/etc目录下。该文件只包括Bind的基本配置,并不包含任何DNS的区域数据。named.conf配置文件由语句与...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)