zoukankan      html  css  js  c++  java
  • [RHEL] 配置 LVM 卷

    [RHEL] 配置 LVM 卷

    一、Introduction

    基础预览 :LVM 认知与扩容操作

    高端实战:Linux系统如何迁移至LVM磁盘


    之前转过一篇文章 LVM分区在线扩容 ,其原因是我需要给公司的 LVM 卷进行一个扩展卷的扩大。

    那其实,不仅只有扩大。还有:缩小以及修复

    二、Environment

    [root@server0 ~]# lsblk 
    NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda               253:0    0   10G  0 disk 
    └─vda1            253:1    0   10G  0 part /
    vdb               253:16   0   10G  0 disk 
    └─vdb1            253:17   0  512M  0 part 
      └─finance-loans 252:0    0  256M  0 lvm  /finance/loans
    

    注释:可以看到系统内已经有了一个 LVM 卷了,但系统还有剩余空间(9.5G)还未被使用。

    Firest:Format File System

    ...
    Command (m for help): p
    
    Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0009f6d4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048     1050623      524288   8e  Linux LVM
    

    **提示: **上述具体 Command 解释,位于文章底部有附录—— Command_action

    **注意: **the next reboot or after you run partprobe(8) or kpartx(8)

    Second:Create Physical Volume

    [root@server0 ~]# pvcreate /dev/vdb2
    

    Third: Create Volume Group

    [root@server0 ~]# vgcreate vg /dev/vdb2
      Volume group "vg" successfully created
    

    BTW: " -s" 可定义 PEnum 块大小;

    Finished:Make Volume Group join LVM

    [root@server0 ~]# lvcreate -n lvm vg -L 100M
      Logical volume "lvm" created
    

    BTW: "-l" 可定义 PEnum 数量

    **注意: ** " -L " 可使用 +size|-size|size(means equal)

    三、Expand Space

    1、单盘扩大

    [root@server0 ~]# lvextend -L +100M /dev/vg/lvm --resizefs 
    fsck from util-linux 2.23.2
    /dev/mapper/vg-lvm: clean, 11/25688 files, 8896/102400 blocks
      Extending logical volume lvm to 200.00 MiB
      Logical volume lvm successfully resized
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/mapper/vg-lvm to 204800 (1k) blocks.
    The filesystem on /dev/mapper/vg-lvm is now 204800 blocks long.
    

    注意:我这里偷了一个懒把俩条命令结合在一起了,否则 lvs /path/to/lvm 空间大小是不会立即生效的。

    Q1:fsadm: Cannot get FSTYPE of "/dev/vg/lvm" Filesystem check failed.

    A1:please format Filesystem promptly.

    Q2:Forgot to add option "--resizefs"

    A2:redo or ext2/ext3/ext4 filesystem to execute resizefs /path/to/lvm , but xfs filesystem must to be execute xfs_growfs mountpoint . The difference is looking what's command admin execute mkfs.ext4 or mkfs.xfs. Attention:XFS must to use mountpoint or not to use /path/to/lvm

    2、加磁盘扩大

    fdisk /dev/disk
        new
            default
            size
        type
            choose
            82
        print
        write
    
    pvcreate /path/to/new/create/lvm_disk
    
    vgcreate <vg_name> /path/to/new/crate/lvm_disk
    

    提示:其他一样。

    四、Reduce Space

    [root@server0 ~]# lsblk 
    NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda               253:0    0   10G  0 disk 
    └─vda1            253:1    0   10G  0 part /
    vdb               253:16   0   10G  0 disk 
    ├─vdb1            253:17   0  512M  0 part 
    │ └─finance-loans 252:0    0  256M  0 lvm  /finance/loans
    └─vdb2            253:18   0    1G  0 part 
      └─vg-lvm        252:1    0  200M  0 lvm  
    

    Firest:unmount device

    [root@server0 ~]# umount /dev/vg/lvm 
    

    Second:check a Linux ext2/ext3/ext4 file system

    [root@server0 ~]# e2fsck -f /dev/vg/lvm 
    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/lvm: 11/49400 files (9.1% non-contiguous), 11884/204800 blocks
    

    Third:resize umount and e2fsck device

    [root@server0 ~]# resize2fs /dev/vg/lvm 66M
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/vg/lvm to 67584 (1k) blocks.
    The filesystem on /dev/vg/lvm is now 67584 blocks long.
    

    提示:当需要进行 LVM 缩小操作时,所有操作必须相反。所以该步异常重要,下一步需要使 RHEL 重新识别被缩小的 LVM 卷。

    Finished:reduce device

    [root@server0 ~]# lvreduce -L 60M /dev/vg/lvm
      WARNING: Reducing active logical volume to 60.00 MiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce lvm? [y/n]: y
      Reducing logical volume lvm to 60.00 MiB
      Logical volume lvm successfully resized
    [root@server0 ~]# vgs vg
      VG   #PV #LV #SN Attr   VSize    VFree  
      vg     1   1   0 wz--n- 1020.00m 960.00m
    [root@server0 ~]# lvs vg
      LV   VG   Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
      lvm  vg   -wi-a----- 60.00m
    

    Q:why the output tell me that "Rounding size to boundary between physical extents"

    A:the lvm have the boundary and the defaults PE size was 4MB. You can change them with lvchange -s {1..4} <vgname> and check it with vgdisplay <vgname>.

    五、Restore Destroyed LVM

    Firest:Check LVM devices

    [root@server0 ~]# vgcfgrestore -l vg 
    
      File:		/etc/lvm/archive/vg_00033-587950815.vg
      VG name:    	vg
      Description:	Created *before* executing 'vgscan'
      Backup Time:	Sun Nov  5 23:28:28 2017
    
       
      File:		/etc/lvm/archive/vg_00034-1362264111.vg
      VG name:    	vg
      Description:	Created *before* executing 'vgscan'
      Backup Time:	Sun Nov  5 23:28:28 2017
    
       
      File:		/etc/lvm/backup/vg
      VG name:    	vg
      Description:	Created *after* executing 'vgscan'
      Backup Time:	Sun Nov  5 23:28:28 2017
    

    Second:Restore

    vgcfgrestore -f <file_list_print> <vg>
    Exameple: vgcfgrestore -f /etc/lvm/archive/vg_00034-1362264111.vg vg
    

    Finished:unActive and Active

    lvchange -an /dev/<vg>/<lvm>
    
    lvchange -ay /dev/<vg>/<lvm> 
    

    Others

    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
  • 相关阅读:
    SHT20 IIC 寄存器概述
    代理技术简介
    Spring基于注解配置AOP
    Spring基于XML配置AOP
    如何在国内下载Eclipse及其插件
    Spring AOP理解
    idea个人配置记录
    使用Gradle自动创建Java项目结构
    Spring使用外部属性文件
    Web程序员开发App系列
  • 原文地址:https://www.cnblogs.com/itxdm/p/RHEL_Configure_the_LVM_volume.html
Copyright © 2011-2022 走看看