• Linux LVM动态扩容


    引用自:

     https://blog.csdn.net/u012439646/article/details/73380197 
     xfs_growfs /dev/centos/root 
    一、首先安装系统时系统分区选择lvm卷组分区,详见本人博客链接https://www.cnblogs.com/Presley-lpc/p/9242871.html
      1、查看盘结构 lsblk
    [root@localhost ~]# lsblk 
    NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    fd0                      2:0    1    4K  0 disk 
    sda                      8:0    0   20G  0 disk 
    ├─sda1                   8:1    0    2M  0 part 
    ├─sda2                   8:2    0    2M  0 part 
    ├─sda3                   8:3    0    1G  0 part /boot
    ├─sda4                   8:4    0    1K  0 part 
    └─sda5                   8:5    0   19G  0 part 
      ├─centos-root        253:0    0    5G  0 lvm  /
      ├─centos-swap        253:1    0    1G  0 lvm  [SWAP]
      ├─centos-swap00      253:2    0    1G  0 lvm  [SWAP]
      ├─centos-home        253:3    0    2G  0 lvm  /home
      ├─centos-var         253:4    0    1G  0 lvm  /var
      └─centos-application 253:5    0    9G  0 lvm  /application
    sdb                      8:16   0   20G  0 disk 
    sr0                     11:0    1 1024M  0 rom  

      2、查看卷组名称及卷组使用情况  vgdisplay

      3、查看当前逻辑卷的空间状态 lvdisplay

    [root@localhost ~]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/centos/home
      LV Name                home
      VG Name                centos
      LV UUID                vJAKGc-Nd7w-IbPZ-FSI5-CTSS-XoXt-WcFu2z
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:24 +0800
      LV Status              available
      # open                 1
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:3
       
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                Sgyddc-qr0l-Xry3-xR5f-rYUe-lNkq-3Ia928
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:25 +0800
      LV Status              available
      # open                 2
      LV Size                1.00 GiB
      Current LE             256
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/centos/var
      LV Name                var
      VG Name                centos
      LV UUID                A0RDo9-Xuz1-7ElO-mwWQ-IHkS-fwDt-YPP1t2
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:25 +0800
      LV Status              available
      # open                 1
      LV Size                1.00 GiB
      Current LE             256
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:4
       
      --- Logical volume ---
      LV Path                /dev/centos/swap00
      LV Name                swap00
      VG Name                centos
      LV UUID                9HyfSy-etlb-74M9-NKiz-AtaC-YPij-i9Tb78
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:26 +0800
      LV Status              available
      # open                 2
      LV Size                1.00 GiB
      Current LE             256
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:2
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                fez5HR-4F4j-PRBy-cdfE-syBU-4NIU-DHnNIK
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:26 +0800
      LV Status              available
      # open                 1
      LV Size                5.00 GiB
      Current LE             1280
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/centos/application
      LV Name                application
      VG Name                centos
      LV UUID                UT39NC-88Ru-hcX2-iceA-P84w-yHac-xKf3o0
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-17 19:41:27 +0800
      LV Status              available
      # open                 1
      LV Size                8.99 GiB
      Current LE             2301
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:5
       

    二、扩容

      1、在一中我们通过lvdisplay可以看到最后这个卷组 /dev/centos/application 的大小为8.99G,现在要动态扩容到28.99G。

        a、首先添加一块硬盘,然后查看 fdisk -l,可以看到/dev/sdb即为所添加的硬盘.

    [root@localhost application]# 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 /dev/sda: 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: 0x0003a9f3
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048        6143        2048   83  Linux
    /dev/sda2            6144       10239        2048   83  Linux
    /dev/sda3   *       10240     2107391     1048576   83  Linux
    /dev/sda4         2107392    41943039    19917824    5  Extended
    /dev/sda5         2109440    41943039    19916800   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 5368 MB, 5368709120 bytes, 10485760 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: 1073 MB, 1073741824 bytes, 2097152 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-swap00: 1073 MB, 1073741824 bytes, 2097152 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-home: 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/centos-var: 1073 MB, 1073741824 bytes, 2097152 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-application: 9651 MB, 9651093504 bytes, 18849792 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

        b、给磁盘分区,此处全部都分出来

    [root@localhost application]# 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 0x6f1c09c9.
    
    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-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): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

        c、将分区类型改为lvm

    [root@localhost application]# 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.
    
    
    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'
    
    Command (m for help): p
    
    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: 0x6f1c09c9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    41943039    20970496   8e  Linux LVM

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.

      2、开始扩容

        a、将新加的分区 /dev/sdb1 创建为物理卷

    [root@localhost application]# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created

        b、给卷组‘centos’扩容(此处的centos即为一中vgdisplay 中的centos),将物理卷 /dev/sdb1 扩展至‘centos’卷组

    [root@localhost application]# vgextend centos /dev/sdb1
      Volume group "centos" successfully extended

        c、此时卷组‘centos’有20G空余空间,将其全部扩展至 /application

    [root@localhost application]# lvextend -l +100%FREE /dev/mapper/centos-application
      Size of logical volume centos/application changed from 8.99 GiB (2301 extents) to 28.99 GiB (7421 extents).
      Logical volume application successfully resized.

        d、虽然此时磁盘已经扩展至/application,但是还没有写入文件系统,我们先通过df -hT 查看/application文件格式为xfs,因此,使用xfs_growfs /dev/mapper/centos-application 命令写入。若文件格式为ext4则使用命令resize2fs /dev/mapper/centos-application写入

    [root@localhost application]# df -hT
    Filesystem                     Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root        xfs       5.0G 1020M  4.0G  20% /
    devtmpfs                       devtmpfs  483M     0  483M   0% /dev
    tmpfs                          tmpfs     493M     0  493M   0% /dev/shm
    tmpfs                          tmpfs     493M  6.8M  487M   2% /run
    tmpfs                          tmpfs     493M     0  493M   0% /sys/fs/cgroup
    /dev/mapper/centos-home        xfs       2.0G   33M  2.0G   2% /home
    /dev/mapper/centos-application xfs       9.0G   33M  9.0G   1% /application
    /dev/mapper/centos-var         xfs      1014M   79M  936M   8% /var
    /dev/sda3                      xfs      1014M  133M  881M  14% /boot
    tmpfs                          tmpfs      99M     0   99M   0% /run/user/0
    [root@localhost application]# xfs_growfs /dev/mapper/centos-application
    meta-data=/dev/mapper/centos-application isize=256    agcount=4, agsize=589056 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=0        finobt=0
    data     =                       bsize=4096   blocks=2356224, 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
    data blocks changed from 2356224 to 7599104
    [root@localhost application]# df -hT
    Filesystem                     Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root        xfs       5.0G 1020M  4.0G  20% /
    devtmpfs                       devtmpfs  483M     0  483M   0% /dev
    tmpfs                          tmpfs     493M     0  493M   0% /dev/shm
    tmpfs                          tmpfs     493M  6.8M  487M   2% /run
    tmpfs                          tmpfs     493M     0  493M   0% /sys/fs/cgroup
    /dev/mapper/centos-home        xfs       2.0G   33M  2.0G   2% /home
    /dev/mapper/centos-application xfs        29G   33M   29G   1% /application
    /dev/mapper/centos-var         xfs      1014M   79M  936M   8% /var
    /dev/sda3                      xfs      1014M  133M  881M  14% /boot
    tmpfs                          tmpfs      99M     0   99M   0% /run/user/0

        e、可以看到/application大小已经从9G动态扩容到了29G。

    三、lvm创建和使用

      1、创建和使用流程
        建立分区-PV--VG--LV--格式化--挂载

      2、fdisk建立分区

        #fdisk /dev/sdb //同样分区sdc

        n 1 回车 回车

        t 8e 回车

        p 查看 w退出

        # fdisk -l /dev/sdb /dev/sdc | grep "LVM"

      3、 转换为物理卷PV

        # pvcreate /dev/sdb1 /dev/sdc1

      4、创建卷组VG 

        # vgcreate juanzu /dev/sdb1 /dev/sdc1

      5、在卷组中 创建逻辑卷LV

        # lvcreate -L 120G -n luoji juanzu
      6、mkfs 格式化

        #mkfs -t ext4 /dev/juanzu/luoji

      7、mount 挂载

        #mount /dev/juanzu/luoji /yinpan

        df -hT 查看

        #df -hT

      8、注意:设置文件系统自动挂载

        #vi /etc/fstab

        设备名称 挂载点目录 文件类型 defaults默认参数(读写) 0(dump备份) 0(启动检查)
        /dev/juanzu/luoji /yinpan ext4 defaults 0 0

    四、lvm动态扩容总结

      1、创建分区      

    #fdisk /dev/sdb

      2、创建物理卷                                             

    #pvcreat /dev/sdb1

      3、查看卷组名称及使用情况                         

    #vgdisplay

      4、将物理卷扩展到卷组                              

     #vgextend centos /dev/sdb1   (此处‘centos’是卷组名称)

      5、将卷组中空闲空间扩展到 /home           

    #lvextend -l +100%FREE /dev/mapper/centos-application

      6、刷新文件系统使扩容生效                     

    #resize2fs /dev/mapper/centos-application

      7、使用reiserfs 文件系统代替ext2/ext3 ,若为xfs则用xfs_growfs  

    #resize_reiserfs /dev/mapper/cl-home
    #xfs_growfs /dev/mapper/cl-home
  • 相关阅读:
    IIS7.5 部署WCF项目问题集锦
    C#制作“安装和部署”时,实现软件开机启动
    Strsafe.h:更安全的C语言字符串处理函数
    FMOD音频引擎简单使用
    您也使用托管C++吗?
    《Programming in Lua中文版》 8.Compilation, Execution, and Errors
    恶心的C语言strtok函数
    Lua一些基本函数
    Lua tables 分析1
    如何让EditPlus支持LUA(转)
  • 原文地址:https://www.cnblogs.com/Presley-lpc/p/9668083.html
Copyright © 2020-2023  润新知