zoukankan      html  css  js  c++  java
  • LVM-创建与增容

    Author:WeiLei

    一、LVM创建

    1、创建分区

    sda总共有三个分区,sda1,sda2,sda3,其中sda2与sda3为LVM分区,分区类型为8e。

    [root@localhost ~]# fdisk -l
    
    Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000b0ab2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    /dev/sda3        41943040    62914559    10485760   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/lvm_data-lv_data: 9663 MB, 9663676416 bytes, 18874368 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
    

    2、创建LVM分区步骤

    fdisk /dev/sda
    n
    p
    3 (选择分区)
    回车
    t (修改分区格式)
    选择分区
    8e
    w  (保存)
    

    3、重启Linux操作系统,使用reboot命令。

    4、创建物理卷,使用pvcreate /dev/sda3命令。

    pvcreate /dev/sda3
    

    5、查看物理卷PV

    pvdisplay
    

    6、创建卷组VG

    创建名称为lvm_data的VG组,且PE修改4m

    vgcreate -s 4m vg_data /dev/sdb3
    

    注意:LVM 默认使用 4MB 的 PE 区块,即可默认的 LVM VG 会有 4M*65534/(1024M/G)=256G。

    8、将添加新的物理卷,加载到lvm_data卷组

    vgextend vg_data /dev/sda3
    

    9、查看卷组信息,使用vgdisplay命令。

    vgdisplay
    

    10、创建卷LV

    lvcreate -L 10g -n lv_data vg_data
    

    11、查看卷LV

    lvdisplay
    

    12、格式化

    mkfs.xfs /dev/vgdata/lv_data
    或
    mkfs.ext4 /dev/vg_data/lv_data
    

    13、挂载

    mkdir /data
    mount /dev/vg_data/lv_data /data/
    

    14、开机挂载

    echo '/dev/vg_data/lv_data /data/ ext4 defaults 0 0' >> /etc/fstab
    

    二、LVM增容

    [root@localhost ~]# fdisk -l
    
    Disk /dev/sdb: 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: 0x405f1692
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    41943039    20970496   8e  Linux LVM
    
    Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000b0ab2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    /dev/sda3        41943040    62914559    10485760   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/lvm_data-lv_data: 9663 MB, 9663676416 bytes, 18874368 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
    
    

    2.1、创建分区

    [root@localhost ~]# fdisk /dev/sdb
    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 0x405f1692.
    
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): 
    Using default response p
    Partition number (1-4, default 1): 
    First sector (2048-41943039, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
    Using default value 41943039
    Partition 1 of type Linux and of size 20 GiB is set
    
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    

    2.2 创建物理卷PV

    [root@localhost ~]# pvcreate /dev/sdb1
    

    2.3 将物理卷加入卷组

    [root@localhost ~]# vgextend vg_data /dev/sdb1
    

    2.4 查看卷组VG

    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               <19.00 GiB
      PE Size               4.00 MiB
      Total PE              4863
      Alloc PE / Size       4863 / <19.00 GiB
      Free  PE / Size       0 / 0   
      VG UUID               7dTdnP-W5CM-fqz1-1QbR-0uO6-Yv0s-mRllUt
       
      --- Volume group ---
      VG Name               lvm_data
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               0
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               29.99 GiB
      PE Size               4.00 MiB
      Total PE              7678
      Alloc PE / Size       2304 / 9.00 GiB
      Free  PE / Size       5374 / 20.99 GiB
      VG UUID               0zGGI4-cyOE-DBq9-J0hz-AMPg-3UTT-jyK7R9
    
    

    2.5、增加LV

    5374是VG中Free PE的个数

    [root@localhost ~]# lvresize -l +5374  /dev/vg_data/lv_data
      Size of logical volume lvm_data/lv_data changed from 9.00 GiB (2304 extents) to 29.99 GiB (7678 extents).
      Logical volume lvm_data/lv_data successfully resized.
    

    2.6 增加文件系统容量

    ## 先执行
    [root@localhost ~]# e2fsck -f /dev/vg_data/lv_data
    e2fsck 1.42.9 (28-Dec-2013)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/vg_data/lv_data: 1306/589824 files (0.5% non-contiguous), 169349/2359296 blocks
    
    ## 后执行
    [root@localhost ~]# resize2fs /dev/vg_data/lv_data
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/lvm_data/lv_data to 7862272 (4k) blocks.
    The filesystem on /dev/lvm_data/lv_data is now 7862272 blocks long.
    
    
    
    [root@localhost ~]# xfs_growfs /dev/centos/root
    

    2.7 挂载后查询

    [root@localhost ~]# mount /dev/vg_data/lv_data /data/
    
    [root@localhost ~]# df -h
    Filesystem                    Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root        17G  1.9G   16G  12% /
    devtmpfs                      1.9G     0  1.9G   0% /dev
    tmpfs                         1.9G     0  1.9G   0% /dev/shm
    tmpfs                         1.9G   12M  1.9G   1% /run
    tmpfs                         1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1                    1014M  146M  869M  15% /boot
    tmpfs                         378M     0  378M   0% /run/user/0
    /dev/mapper/lvm_data-lv_data   30G  397M   28G   2% /data
    

    2.8 分区类型代码

     0  空              24  NEC DOS         81  Minix / 旧 Linu bf  Solaris        
     1  FAT12           27  隐藏的 NTFS Win 82  Linux 交换 / 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 隐藏的 C:  c6  DRDOS/sec (FAT-
     4  FAT16 <32M      40  Venix 80286     85  Linux 扩展      c7  Syrinx         
     5  扩展            41  PPC PReP Boot   86  NTFS 卷集       da  非文件系统数据 
     6  FAT16           42  SFS             87  NTFS 卷集       db  CP/M / CTOS / .
     7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux 纯文本    de  Dell 工具      
     8  AIX             4e  QNX4.x 第2部分  8e  Linux LVM       df  BootIt         
     9  AIX 可启动      4f  QNX4.x 第3部分  93  Amoeba          e1  DOS 访问       
     a  OS/2 启动管理器 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 休 eb  BeOS fs        
     e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
     f  W95 扩展 (LBA)  54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
    10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC  
    11  隐藏的 FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
    12  Compaq 诊断     5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
    14  隐藏的 FAT16 <3 61  SpeedStor       ab  Darwin 启动     f2  DOS 次要       
    16  隐藏的 FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
    17  隐藏的 HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
    18  AST 智能睡眠    65  Novell Netware  b8  BSDI swap       fd  Linux raid 自动
    1b  隐藏的 W95 FAT3 70  DiskSecure 多启 bb  Boot Wizard 隐  fe  LANstep        
    1c  隐藏的 W95 FAT3 75  PC/IX           be  Solaris 启动    ff  BBT            
    1e  隐藏的 W95 FAT1 80  旧 Minix
    

    2.9 分区类型代码查看磁盘uuid

    blkid /dev/mapper/vg_data-lv_data
    
  • 相关阅读:
    python利用pip安装模块出现报错:ReadTimeoutError: HTTPSConnectionPool的解决方法
    20届一战南理工软件工程(专硕)824
    python—socket编程
    python—异常处理
    python—面向对象设计
    python—装饰器
    python—模块与包
    python—迭代器,生成器与for循环机制
    python—文件处理
    python—函数
  • 原文地址:https://www.cnblogs.com/Mr-Wei/p/15420882.html
Copyright © 2011-2022 走看看