• LVM操作过程


    (1)添加磁盘后测试:

    [root@centos7-4 ~]# lsblk 

     (2)磁盘分区(只分一个区):

    [root@centos7-4 ~]# fdisk /dev/sdb

     

    (3)创建物理卷(PV)

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

     (4)创建逻辑卷组(VG)

    [root@lvm ~]# vgcreate vg_cloud3 /dev/sdb1

     (5)查看所有逻辑卷组

    [root@lvm ~]# vgscan 

     (6)显示vg_cloud3卷组的详细信息 

    [root@lvm ~]# vgdisplay vg_cloud3 

     (7)创建逻辑卷(LV)

    [root@lvm ~]# lvcreate -L +2G  -n cloud3 vg_cloud3 

     (8)查看所有逻辑卷(LV)

    [root@lvm ~]# lvscan

     (9)格式化逻辑卷(LV)

    [root@lvm ~]# mkfs.ext4 /dev/vg_cloud3/cloud3 

     (10)创建目录backup

    [root@lvm ~]# mkdir backup

     (11)开机挂载逻辑卷cloud3

    [root@lvm ~]# vim /etc/fstab  

    /dev/vg_cloud3/cloud3   /root/backup ext4 defaults 0 0

     

     

     (12)挂载所有

    [root@lvm ~]# mount -a

     (12)查看所有挂载点

    [root@lvm ~]# df -hT

     

    2.扩展逻辑卷/dev/vg_cloud3/cloud3空间
    (1)扩展逻辑卷/dev/vg_cloud3/cloud3空间到4G
    <1>查看卷组的剩余空间
    [root@lvm ~]# vgdisplay vg_cloud3
    --- Volume group ---
    VG Name vg_cloud3
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 2
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 1
    Open LV 1
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size <5.00 GiB
    PE Size 4.00 MiB
    Total PE 1279
    Alloc PE / Size 512 / 2.00 GiB
    Free PE / Size 767 / <3.00 GiB
    VG UUID gFIuXV-UlJH-g2dH-bYin-VWdl-a4Qj-tZEHoP

    <2>扩展逻辑卷/dev/vg_cloud3/cloud3的物理空间
    [root@lvm ~]# lvextend -L +2G /dev/vg_cloud3/cloud3
    Size of logical volume vg_cloud3/cloud3 changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
    Logical volume vg_cloud3/cloud3 successfully resized.

    <3>再次查看挂载点显示该逻辑卷并没有被物理扩容
    [root@lvm ~]# df -hT
    文件系统 类型 容量 已用 可用 已用% 挂载点
    /dev/mapper/centos-root xfs 17G 10G 7.1G 59% /
    devtmpfs devtmpfs 473M 0 473M 0% /dev
    tmpfs tmpfs 489M 0 489M 0% /dev/shm
    tmpfs tmpfs 489M 14M 475M 3% /run
    tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
    /dev/sda1 xfs 1014M 161M 854M 16% /boot
    tmpfs tmpfs 98M 8.0K 98M 1% /run/user/42
    tmpfs tmpfs 98M 24K 98M 1% /run/user/1000
    tmpfs tmpfs 98M 0 98M 0% /run/user/0
    /dev/mapper/vg_cloud3-cloud3 ext4 2.0G 6.0M 1.8G 1% /root/backup

    <4>调整逻辑卷分区的大小(扩展文件系统)
    [root@lvm ~]# resize2fs /dev/vg_cloud3/cloud3
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/vg_cloud3/cloud3 is mounted on /root/backup; on-line resizing re quired
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/vg_cloud3/cloud3 is now 1048576 blocks long.

    [root@lvm ~]# lvscan
    ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
    ACTIVE '/dev/centos/root' [<17.00 GiB] inherit
    ACTIVE '/dev/vg_cloud3/cloud3' [4.00 GiB] inherit

    备注:resize2fs只适用于ext3/ext4文件系统;xfs文件系统用xfs_growfs

    (2)由于卷组空间不足需添加新磁盘让逻辑卷扩大到10G容量.
    <1>查看块设备
    [root@lvm ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 20G 0 disk
    ├─sda1 8:1 0 1G 0 part /boot
    └─sda2 8:2 0 19G 0 part
    ├─centos-root 253:0 0 17G 0 lvm /
    └─centos-swap 253:1 0 2G 0 lvm [SWAP]
    sdb 8:16 0 5G 0 disk
    └─sdb1 8:17 0 5G 0 part
    └─vg_cloud3-cloud3 253:2 0 4G 0 lvm /root/backup
    sdc 8:32 0 10G 0 disk
    sr0 11:0 1 1024M 0 rom
    <2>创建物理卷(PV)
    [root@lvm ~]# pvcreate /dev/sdc
    Physical volume "/dev/sdc" successfully created.

    [root@lvm ~]# pvscan
    PV /dev/sda2 VG centos lvm2 [<19.00 GiB / 0 free]
    PV /dev/sdb1 VG vg_cloud3 lvm2 [<5.00 GiB / 1020.00 MiB free]
    PV /dev/sdc lvm2 [10.00 GiB]
    Total: 3 [33.99 GiB] / in use: 2 [23.99 GiB] / in no VG: 1 [10.00 GiB]

    [root@lvm ~]# vgextend vg_cloud3 /dev/sdc
    Volume group "vg_cloud3" successfully extended

    [root@lvm ~]# pvscan
    PV /dev/sda2 VG centos lvm2 [<19.00 GiB / 0 free]
    PV /dev/sdb1 VG vg_cloud3 lvm2 [<5.00 GiB / 1020.00 MiB free]
    PV /dev/sdc VG vg_cloud3 lvm2 [<10.00 GiB / <10.00 GiB free]
    Total: 3 [<33.99 GiB] / in use: 3 [<33.99 GiB] / in no VG: 0 [0 ]

    [root@lvm ~]# vgdisplay vg_cloud3
    --- Volume group ---
    VG Name vg_cloud3
    System ID
    Format lvm2
    Metadata Areas 2
    Metadata Sequence No 4
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 1
    Open LV 1
    Max PV 0
    Cur PV 2
    Act PV 2
    VG Size 14.99 GiB
    PE Size 4.00 MiB
    Total PE 3838
    Alloc PE / Size 1024 / 4.00 GiB
    Free PE / Size 2814 / 10.99 GiB
    VG UUID gFIuXV-UlJH-g2dH-bYin-VWdl-a4Qj-tZEHoP

    [root@lvm ~]# lvscan
    ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
    ACTIVE '/dev/centos/root' [<17.00 GiB] inherit
    ACTIVE '/dev/vg_cloud3/cloud3' [4.00 GiB] inherit

    [root@lvm ~]# lvextend -L +5G /dev/vg_cloud3/cloud3
    Size of logical volume vg_cloud3/cloud3 changed from 4.00 GiB (1024 extents) to 9.00 G iB (2304 extents).
    Logical volume vg_cloud3/cloud3 successfully resized.

    [root@lvm ~]# lvscan
    ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
    ACTIVE '/dev/centos/root' [<17.00 GiB] inherit
    ACTIVE '/dev/vg_cloud3/cloud3' [9.00 GiB] inherit

    [root@lvm ~]# resize2fs /dev/vg_cloud3/cloud3
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/vg_cloud3/cloud3 is mounted on /root/backup; on-line resizing requi red
    old_desc_blocks = 1, new_desc_blocks = 2
    The filesystem on /dev/vg_cloud3/cloud3 is now 2359296 blocks long.

    [root@lvm ~]# df -hT
    文件系统 类型 容量 已用 可用 已用% 挂载点
    /dev/mapper/centos-root xfs 17G 10G 7.1G 59% /
    devtmpfs devtmpfs 473M 0 473M 0% /dev
    tmpfs tmpfs 489M 0 489M 0% /dev/shm
    tmpfs tmpfs 489M 14M 475M 3% /run
    tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
    /dev/sda1 xfs 1014M 161M 854M 16% /boot
    tmpfs tmpfs 98M 8.0K 98M 1% /run/user/42
    tmpfs tmpfs 98M 24K 98M 1% /run/user/1000
    tmpfs tmpfs 98M 0 98M 0% /run/user/0
    /dev/mapper/vg_cloud3-cloud3 ext4 8.8G 9.0M 8.4G 1% /root/backup

  • 相关阅读:
    shell脚本基础
    rtsp冷门解释
    C++基础之动态内存
    树莓派3安装ros
    Trie树
    [LeetCode]The Skyline Problem
    [LeetCode]Implement Trie (Prefix Tree)
    C++基础之适配器
    配置树莓派3的openwrt中的网络
    [LeetCode]Self Crossing
  • 原文地址:https://www.cnblogs.com/yangyongchao/p/12397888.html
Copyright © 2020-2023  润新知