CentOS 7.2 添加磁盘并创建新区

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 添加磁盘并创建新区前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
添加一个3T的磁盘,并对其进行分区

   LVM创建
   LVM基本概念
   1、 物理卷-----PV(Physical Volume)
   物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个 物理硬盘。
   2、 卷组--------VG(Volumne Group)
   卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可 动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以 拥有多个卷组。
   3、 逻辑卷-----LV(Logical Volume)
   逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立 后可以动态地扩展和缩小空间。系统中的多个逻辑卷要以属于同一个卷组,也可以 属于不同的多个卷组。
   4、 物理区域--PE(Physical Extent)
   物理区域是物理卷中可用于分配的最小存储单元,物理区域的大小可根据实际情况在 建立物理卷时指定。物理区域大小一旦确定将不能更改,同一卷组中的所有物理卷 的物理区域大小需要一致。
   5、 逻辑区域—LE(Logical Extent)
   逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在 卷组中的物理区域的大小。
   6、 卷组描述区域-----(Volume Group Descriptor Area)
   卷组描述区域存在于每个物理卷中,用于描述物理卷本身、物理卷所属卷组、卷组中的 逻辑卷及逻辑卷中物理区域的分配等所有信息,卷组描述区域是在使用pvcreate 建立物理卷时建立的。
   parted创建LVM
   把一块3T硬盘全部设为LVM

结构图如下:

#parted /dev/sdb
>mklabel gpt  //由于MBR分区表只支持2T硬盘,所以如果大于2T必须用GPT分区表
(parted) mkpart primary xfs 0%  20%
(parted) p                                                              
Model: ATA ST3000NM0033-9ZM (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
1      1049kB  600GB  600GB               primary
(parted) mkpart primary xfs 20%  40%
(parted) mkpart primary xfs 40%  60%                                    
(parted) mkpart primary xfs 60%  100% 
(parted) p                                                                
Model: ATA ST3000NM0033-9ZM (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  600GB   600GB                primary
 2      600GB   1200GB  600GB                primary
 3      1200GB  1800GB  600GB                primary
 4      1800GB  3001GB  1200GB               primary

(parted) set 1 lvm on  //设定编号1为LVM分区,on开启 off是关闭                                                
(parted) set 2 lvm on                                                     
(parted) set 3 lvm on                                                     
(parted) set 4 lvm on                                                     
(parted) p
Model: ATA ST3000NM0033-9ZM (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  600GB   600GB                primary  lvm
 2      600GB   1200GB  600GB                primary  lvm
 3      1200GB  1800GB  600GB                primary  lvm
 4      1800GB  3001GB  1200GB               primary  lvm

(parted) quit                                                             
Information: You may need to update /etc/fstab.
#partprobe 立即生效
 退出后进行建立pv,vg,lv等
 创建LVM
[root@localhost /]# pvcreate /dev/sdb1 //创建pv
  Physical volume "/dev/sdb1" successfully created
[root@localhost /]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created
[root@localhost /]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created
[root@localhost /]# pvcreate /dev/sdb4
  Physical volume "/dev/sdb4" successfully created
[root@localhost /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               centos
  PV Size               344.99 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              88316
  Free PE               1
  Allocated PE          88315
  PV UUID               RuGu3e-MrqN-nXgM-x43B-nHcy-fELh-At2EG7

  "/dev/sdb2" is a new physical volume of "558.90 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               558.90 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               36oEPq-fGuY-1DgE-eRwN-Kn2U-CBfv-Y1Jdl7

  "/dev/sdb3" is a new physical volume of "558.90 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name               
  PV Size               558.90 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Yzewvc-yv0t-dObI-POQf-J1vr-zIbp-uIuDim

  "/dev/sdb4" is a new physical volume of "1.09 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb4
  VG Name               
  PV Size               1.09 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               68TePP-fusv-sasY-KLIe-ZKmf-mUzU-vgn9oc

  "/dev/sdb1" is a new physical volume of "558.90 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               558.90 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               nbcrMl-ukJb-Qpj3-Lc05-mkaf-yHUj-9EjhK2
[root@localhost /]# vgdisplay  //显示PV分区情况
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               344.98 GiB
  PE Size               4.00 MiB
  Total PE              88316
  Alloc PE / Size       88315 / 344.98 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               PUyFI6-z0gL-r014-xhk1-btLX-aDhY-7tghOP

创建VG

[root@localhost /]# vgcreate vg /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4
  Volume group "vg" successfully created
[root@localhost /]# vgdisplay
  --- Volume group ---
  VG Name               vg
  System ID             
  Format                lvm2
  Metadata Areas        4
  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                4
  Act PV                4
  VG Size               2.73 TiB
  PE Size               4.00 MiB
  Total PE              715395
  Alloc PE / Size       0 / 0   
  Free  PE / Size       715395 / 2.73 TiB
  VG UUID               2bbsrh-o7OU-18d2-2rgG-kZFb-FmIZ-hdvncj

  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               344.98 GiB
  PE Size               4.00 MiB
  Total PE              88316
  Alloc PE / Size       88315 / 344.98 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               PUyFI6-z0gL-r014-xhk1-btLX-aDhY-7tghOP

创建LV

[root@localhost Desktop]# lvcreate --help
  lvcreate: Create a logical volume

lvcreate
    [-A|--autobackup {y|n}]
    [-a|--activate [a|e|l]{y|n}]
    [--addtag Tag]
    [--alloc AllocationPolicy]
    [-H|--cache
      [--cachemode {writeback|writethrough}]
      [--cachepolicy policy]
      [--cachesettings key=value]
    [--cachepool CachePoolLogicalVolume{Name|Path}]
    [-c|--chunksize ChunkSize]
    [-C|--contiguous {y|n}]
    [--commandprofile ProfileName]
    [-d|--debug]
    [-h|-?|--help]
    [--errorwhenfull {y|n}]
    [--ignoremonitoring]
    [--monitor {y|n}]
    [-i|--stripes Stripes [-I|--stripesize StripeSize]]
    [-k|--setactivationskip {y|n}]
    [-K|--ignoreactivationskip]
    {-l|--extents LogicalExtentsNumber[%{VG|PVS|FREE}] |
     -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
    [-M|--persistent {y|n}] [-j|--major major] [--minor minor]
    [--Metadataprofile ProfileName]
    [-m|--mirrors Mirrors [--nosync]
      [{--mirrorlog {disk|core|mirrored}|--corelog}]]
    [-n|--name LogicalVolumeName]
    [--noudevsync]
    [-p|--permission {r|rw}]
    [--poolMetadatasize MetadataSize[bBsSkKmMgG]]
    [--poolMetadataspare {y|n}]]
    [--[raid]minrecoveryrate Rate]
    [--[raid]maxrecoveryrate Rate]
    [-r|--readahead {ReadAheadSectors|auto|none}]
    [-R|--regionsize MirrorLogRegionSize]
    [-T|--thin
      [--discards {ignore|nopassdown|passdown}]
    [--thinpool ThinPoolLogicalVolume{Name|Path}]
    [-t|--test]
    [--type VolumeType]
    [-v|--verbose]
    [-W|--wipesignatures {y|n}]
    [-Z|--zero {y|n}]
    [--version]
    VolumeGroupName [PhysicalVolumePath...]

lvcreate
    { {-s|--snapshot} OriginalLogicalVolume[Path] |
      [-s|--snapshot] VolumeGroupName[Path] -V|--virtualsize VirtualSize}
      {-H|--cache} VolumeGroupName[Path][/OriginalLogicalVolume]
      {-T|--thin} VolumeGroupName[Path][/PoolLogicalVolume]
                  -V|--virtualsize VirtualSize}
    [-A|--autobackup {y|n}]
    [--addtag Tag]
    [--alloc AllocationPolicy]
    [--cachepolicy Policy] [--cachesettings Key=Value]
    [-c|--chunksize]
    [-C|--contiguous {y|n}]
    [--commandprofile ProfileName]
    [-d|--debug]
    [--discards {ignore|nopassdown|passdown}]
    [-h|-?|--help]
    [--ignoremonitoring]
    [--monitor {y|n}]
    [-i|--stripes Stripes [-I|--stripesize StripeSize]]
    [-k|--setactivationskip {y|n}]
    [-K|--ignoreactivationskip]
    {-l|--extents LogicalExtentsNumber[%{VG|FREE|ORIGIN}] |
     -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
    [--poolMetadatasize MetadataVolumeSize[bBsSkKmMgG]]
    [-M|--persistent {y|n}] [-j|--major major] [--minor minor]
    [--Metadataprofile ProfileName]
    [-n|--name LogicalVolumeName]
    [--noudevsync]
    [-p|--permission {r|rw}]
    [-r|--readahead ReadAheadSectors|auto|none]
    [-t|--test]
    [{--thinpool ThinPoolLogicalVolume[Path] |
      --cachepool CachePoolLogicalVolume[Path]}]
    [-v|--verbose]
    [--version]
    [PhysicalVolumePath...]
[root@localhost /]# lvcreate -L 300G -n soft vg //创建大小300G名称soft的lv
  Logical volume "soft" created.
[root@localhost /]# lvcreate -L 800G -n datainfo vg
  Logical volume "datainfo" created.
[root@localhost /]# lvcreate -L 1600G -n systeminfo vg
  Logical volume "systeminfo" created.

对磁盘进行格式化

[root@localhost Desktop]# mkfs.xfs  /dev/vg/soft
Meta-data=/dev/vg/soft           isize=256    agcount=4,agsize=19660800 blks
         = sectsz=512 attr=2,projid32bit=1          = crc=0 finobt=0 data     =                       bsize=4096   blocks=78643200,imaxpct=25
         = sunit=0 swidth=0 blks naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=38400,version=2
         = sectsz=512 sunit=0 blks,lazy-count=1 realtime =none                   extsz=4096   blocks=0,rtextents=0

在根目录下创建一个soft目录,便于将该磁盘挂在这个目录上。

mount -t xfs /dev/vg/soft /soft
[root@localhost Desktop]# mkfs.xfs  /dev/vg/datainfo
Meta-data=/dev/vg/datainfo       isize=256    agcount=4,agsize=52428800 blks
         = sectsz=512 attr=2,projid32bit=1          = crc=0 finobt=0 data     =                       bsize=4096   blocks=209715200,imaxpct=25
         = sunit=0 swidth=0 blks naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=102400,rtextents=0
[root@localhost Desktop]# mkfs.xfs  /dev/vg/systeminfo
Meta-data=/dev/vg/systeminfo     isize=256    agcount=4,agsize=104857600 blks
         = sectsz=512 attr=2,projid32bit=1          = crc=0 finobt=0 data     =                       bsize=4096   blocks=419430400,imaxpct=5
         = sunit=0 swidth=0 blks naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=204800,rtextents=0
[root@localhost Desktop]# mount -t xfs /dev/vg/datainfo /datainfo
[root@localhost Desktop]# mount -t xfs /dev/vg/systeminfo /systeminfo
[root@localhost Desktop]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   xfs        40G  4.6G   36G  12% /
devtmpfs                  devtmpfs   32G     0   32G   0% /dev
tmpfs                     tmpfs      32G  160K   32G   1% /dev/shm
tmpfs                     tmpfs      32G  9.6M   32G   1% /run
tmpfs                     tmpfs      32G     0   32G   0% /sys/fs/cgroup
/dev/sda1                 vfat       96M   28M   69M  29% /boot/efi
/dev/mapper/centos-ssd    xfs       289G   33M  289G   1% /ssd
tmpfs                     tmpfs     6.3G   12K  6.3G   1% /run/user/0
/dev/mapper/vg-soft       xfs       300G   33M  300G   1% /soft
/dev/mapper/vg-datainfo   xfs       800G   33M  800G   1% /datainfo
/dev/mapper/vg-systeminfo xfs       1.6T   33M  1.6T   1% /systeminfo

让系统开机自动挂载,需要在/etc/fstab添加相应的内容,最后的内容如下:

[root@localhost /]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 19 19:16:20 2016
#
# 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=345E-97C8          /boot/efi               vfat    umask=0077,shortname=winnt 0 0
/dev/mapper/centos-ssd  /ssd                    xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/mapper/vg-soft     /soft                   xfs     defaults        0 0
/dev/mapper/vg-datainfo /datainfo               xfs     defaults        0 0
/dev/mapper/vg-systeminfo /systeminfo           xfs     defaults        0 0

/etc/fstab中的参数请自己在网络上查找。
参考:
http://www.centoscn.com/CentOS/config/2015/0315/4891.html
http://www.opsers.org/base/create-lvm-parted.html
http://blog.sina.com.cn/s/blog_967817f20102v2a6.html
http://my.oschina.net/guol/blog/61424

原文链接:https://www.f2er.com/centos/381514.html

猜你在找的CentOS相关文章