美文网首页
LVM逻辑卷基本操作

LVM逻辑卷基本操作

作者: ArthurIsUsed | 来源:发表于2019-03-14 08:51 被阅读0次

    相关命令

    • pvcreate /dev/sdb //创建物理卷(VGDA:卷组描述区域)
      • pvscan, pvdisplay //扫瞄,显示物理卷
      • pvremove /dev/sdb //删除物理卷
    [root@KMVS-CENTOS shm]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               vg_kmvscentos
      PV Size               79.51 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              20354
      Free PE               0
      Allocated PE          20354
      PV UUID               Ggncx1-y0eb-XVyQ-6jxi-SX35-tzbp-rSeJHP
    
    • vgdisplay 查看卷组,vgcreate 创建卷组
      • vgcreate <volume-group1卷组名> /dev/sdb1 /dev/sdb2 /dev/sdb3
      • vgremove <volume-group1> //删除卷组
      • vgchange -a y // 激活所有卷组
      • vgextend <volume-group1> <pv-path> //增大卷组,把新的物理卷加入现在卷组
      • vgreduce <volume-group1> <pv-path>//减小卷组,把物理卷从卷组中移出
    [root@KMVS-CENTOS shm]# vgdisplay 
      --- Volume group ---
      VG Name               vg_kmvscentos
      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               79.51 GiB
      PE Size               4.00 MiB
      Total PE              20354
      Alloc PE / Size       20354 / 79.51 GiB
      Free  PE / Size       0 / 0   
      VG UUID               HbeVkk-bnpi-O4NZ-aGzQ-N8jy-D8rZ-QNcqgD
    
    • lvcreate -L 100M -n <lv1逻辑卷名> <volume-group1卷组名> //创建逻辑卷
      • lvdisplay
      • lvremove /dev/volume-group1/lv1 //删除逻辑卷
      • lvresize -L 200M /dev/volume-group1/lv1 // 增大,或 缩小逻辑卷大小
      • lvextend -L|--size +逻辑卷大小增量 逻辑卷全路径名 //增大
      • lvreduce q -L|--size +逻辑卷减小量 逻辑卷全路径名 //缩小
      • lvchange -an <logical volume path> //inactive 逻辑卷
      • lvchange -ay <logical volume path>//active 激活逻辑卷
    [root@KMVS-CENTOS shm]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/vg_kmvscentos/lv_home
      LV Name                lv_home
      VG Name                vg_kmvscentos
      LV UUID                UoK2Gc-Y1Ec-lJXr-Vv57-xAkc-iZsz-HaAtNV
      LV Write Access        read/write
      LV Creation host, time KMVS-CENTOS, 2013-08-08 12:25:46 +0800
      LV Status              available
      # open                 1
      LV Size                25.63 GiB
      Current LE             6562
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:2
    
    • 格式化逻辑卷
      • sudo mkfs.ext4 /dev/mapper/dataVG-data
    • 每次开机自动挂载
      • echo "/dev/mapper/dataVG-data /data ext4 defaults,noatime,barrier=0,data=writeback 0 0" | sudo tee -a /etc/fstab
    • 建立/data目录,不然挂载不上
      • sudo mkdir /data

    不重启,显示新硬盘

    • 确定主机总线号:
    [root@KMVS-CENTOS shm]# ls /sys/class/scsi_host/
    host0  host1  host2
    
    • 重新扫描SCSI总线来添加设备:
     [root@iNeedle~]# echo "- - -" > /sys/class/scsi_host/host0/scan
     [root@iNeedle~]# echo "- - -" > /sys/class/scsi_host/host1/scan
     [root@iNeedle~]# echo "- - -" > /sys/class/scsi_host/host2/scan
    
    • fdisk -l
    Disk /dev/sdb: 32.2 GB, 32212254720 bytes
    255 heads, 63 sectors/track, 3916 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    

    添加新硬盘,纳入逻辑卷

    • create物理卷
    [root@KMVS-CENTOS shm]# pvcreate  /dev/sdb 
      Physical volume "/dev/sdb" successfully created
    
    • 扩充逻辑卷
    [root@KMVS-CENTOS shm]# vgextend vg_kmvscentos /dev/sdb
      Volume group "vg_kmvscentos" successfully extended
    [root@KMVS-CENTOS shm]# vgdisplay 
      --- Volume group ---
      VG Name               vg_kmvscentos
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  5
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                3
      Open LV               3
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               109.50 GiB
      PE Size               4.00 MiB
      Total PE              28033
      Alloc PE / Size       20354 / 79.51 GiB
      Free  PE / Size       7679 / 30.00 GiB
      VG UUID               HbeVkk-bnpi-O4NZ-aGzQ-N8jy-D8rZ-QNcqgD
    
    • 给特定逻辑卷增加容量
    [root@KMVS-CENTOS shm]# lvresize -L 30G /dev/mapper/vg_kmvscentos-lv_home 
      Extending logical volume lv_home to 30.00 GiB
      Logical volume lv_home successfully resized
        
    [root@KMVS-CENTOS shm]# lvextend -L   +25.6G  /dev/mapper/vg_kmvscentos-lv_home 
      Rounding size to boundary between physical extents: 25.60 GiB
      Extending logical volume lv_home to 55.60 GiB
      Logical volume lv_home successfully resized
    
    • resize2fs /dev/mapper/vg_kmvscentos-lv_home
    [root@KMVS-CENTOS shm]# resize2fs /dev/mapper/vg_kmvscentos-lv_home 
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/mapper/vg_kmvscentos-lv_home is mounted on /home; on-line resizing required
    old desc_blocks = 2, new_desc_blocks = 4
    Performing an on-line resize of /dev/mapper/vg_kmvscentos-lv_home to 14582784 (4k) blocks.
    The filesystem on /dev/mapper/vg_kmvscentos-lv_home is now 14582784 blocks long.
    
    [root@KMVS-CENTOS shm]# df -h
    文件系统          容量  已用  可用 已用%% 挂载点
    /dev/mapper/vg_kmvscentos-lv_root
                           50G   14G   33G  30% /
    tmpfs                 7.9G  292K  7.9G   1% /dev/shm
    /dev/sda1             485M   38M  423M   9% /boot
    /dev/mapper/vg_kmvscentos-lv_home
                           55G   20G   33G  39% /home
    /dev/sda3             119G   13G  101G  11% /disk
    

    相关文章

      网友评论

          本文标题:LVM逻辑卷基本操作

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