美文网首页
CentOS 7.x 创建 LVM 系统分区

CentOS 7.x 创建 LVM 系统分区

作者: 又语 | 来源:发表于2019-11-21 19:26 被阅读0次

    本文介绍 CentOS 7.x 系统创建 LVM 系统分区的命令与方法。


    目录

    • 版本说明
    • 方法步骤
    • 总结

    版本说明

    • CentOS Linux release 7.6

    方法步骤

    1. 执行命令 lsblk 查询磁盘分区情况。
    [root@... opt]# lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0      11:0    1 1024M  0 rom  
    xvda    202:0    0   40G  0 disk 
    ├─xvda1 202:1    0   36G  0 part /
    └─xvda2 202:2    0    4G  0 part [SWAP]
    xvde    202:64   0  380G  0 disk
    

    看见一块未分区的新磁盘 xvde

    1. 执行磁盘分区命令 fdisk /dev/xvde,输入 p 打印分区表。
    [root@... opt]# fdisk /dev/xvde
    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 0x55a42d8e.
    
    Command (m for help): p
    
    Disk /dev/xvde: 408.0 GB, 408021893120 bytes, 796917760 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: 0x55a42d8e
    
        Device Boot      Start         End      Blocks   Id  System
    
    1. 执行命令 n 创建一个 200G 大小的主分区。
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (2048-796917759, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-796917759, default 796917759): +200G
    Partition 1 of type Linux and of size 200 GiB is set
    
    1. 执行命令 t 修改分区类型为 Linux LVM(Logical Volume Manager,逻辑卷管理),注意:L 可以查看所有可用的十六进制代码,Linux LVM 的十六进制代码是 8e
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list all codes): L
    
     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      
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    1. 再次执行命令 p 打印分区表,可见 Linux LVM 已经创建成功。
    Command (m for help): p
    
    Disk /dev/xvde: 408.0 GB, 408021893120 bytes, 796917760 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: 0x55a42d8e
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvde1            2048   419432447   209715200   8e  Linux LVM
    
    1. 执行命令 wq 写入并退出。
    Command (m for help): wq
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    1. 执行命令 pvcreate /dev/xvde1 创建物理卷,执行 pvscanpvdisplay 命令可以查看 pv 标志的物理分区。
    [root@... opt]# pvcreate /dev/xvde1
      Physical volume "/dev/xvde1" successfully created.
    [root@... opt]# pvscan
      PV /dev/xvde1                      lvm2 [200.00 GiB]
      Total: 1 [200.00 GiB] / in use: 0 [0   ] / in no VG: 1 [200.00 GiB]
    [root@... opt]# pvdisplay
      "/dev/xvde1" is a new physical volume of "200.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/xvde1
      VG Name               
      PV Size               200.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               GrC5or-Jyr5-BEou-Zpzd-Sott-PSfx-5Hn9rt
    
    1. 执行命令 vgcreate opt /dev/xvde1 创建卷组,其中 opt 是卷组名称,执行 vgscanvgdisplay 命令可以查看卷组信息。
    [root@... opt]# vgcreate opt /dev/xvde1
      Volume group "opt" successfully created
    [root@... opt]# vgscan
      Reading volume groups from cache.
      Found volume group "opt" using metadata type lvm2
    [root@... opt]# vgdisplay
      --- Volume group ---
      VG Name               opt
      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               <200.00 GiB
      PE Size               4.00 MiB
      Total PE              51199
      Alloc PE / Size       0 / 0   
      Free  PE / Size       51199 / <200.00 GiB
      VG UUID               4ixgcF-nJ6u-XLcZ-esai-heup-l687-HnjZUG
    
    1. 执行命令 lvcreate -L 199G -n opt opt 创建逻辑卷,-L 表示从卷组中划分 199G 空间,-n 表示后面第一个参数 opt 为逻辑卷名称,执行命令 lvdisplay 查询逻辑卷信息。
    [root@... opt]# lvcreate -L 199G -n opt opt
      Logical volume "opt" created.
    [root@... opt]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/opt/opt
      LV Name                opt
      VG Name                opt
      LV UUID                tpsOd4-iDeL-82oO-HsYo-e3Kb-bGNN-XavB2X
      LV Write Access        read/write
      LV Creation host, time ctuphicprc00342, 2019-11-21 20:41:39 +0800
      LV Status              available
      # open                 0
      LV Size                199.00 GiB
      Current LE             50944
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    
    1. 执行命令 mkfs.ext4 对逻辑卷进行格式化。
    [root@... opt]# mkfs.ext4 /dev/opt/opt
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    13041664 inodes, 52166656 blocks
    2608332 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2199912448
    1592 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
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    1. 执行命令 mount 进行挂载,注意:要使挂载信息永久生效需要修改 /etc/fstab 文件,参考:CentOS 7.x 磁盘分区挂载
    [root@... opt]# mount /dev/opt/opt /opt
    [root@... opt]# lsblk
    NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0          11:0    1 1024M  0 rom  
    xvda        202:0    0   40G  0 disk 
    ├─xvda1     202:1    0   36G  0 part /
    └─xvda2     202:2    0    4G  0 part [SWAP]
    xvde        202:64   0  380G  0 disk 
    └─xvde1     202:65   0  200G  0 part 
      └─opt-opt 253:0    0  199G  0 lvm  /opt
    

    总结

    创建 LVM 系统分区的主要步骤:

    1. 添加物理磁盘
    2. 创建新分区
    3. 创建 Physical Volume 物理卷
    4. 创建 Volume Group 卷组
    5. 创建 Logincal Volume 逻辑卷
    6. 格式化逻辑卷
    7. 挂载逻辑卷到指定目录
    8. 挂载信息写入 /etc/fstab

    相关文章

      网友评论

          本文标题:CentOS 7.x 创建 LVM 系统分区

          本文链接:https://www.haomeiwen.com/subject/uptxwctx.html