LVM

LVM磁盘管理

Lvm创建
1查看是否安装了lvm

rpm -qa |grep lvm 

2 安装关于lvm的全部

yum install -y lvm*

3 pvcreate创建物理卷

[root@demo ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created

4 查看物理卷

   [root@demo ~]# pvdisplay
  "/dev/sdd" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               UrDU4l-cPgT-a1Cn-u3Kg-oaA4-cwNc-WncVjJ

5创建卷组

    [root@demo ~]# vgcreate -s 16M vgEric /dev/sdd  vgEric是名字自己定
      Volume group "vgEric" successfully created

6 逻辑卷创建

[root@demo ~]# lvcreate -L 512M -n lvEric vgEric    -n 名字 vgEric是你创建的卷组
  Logical volume "lvEric" created.

7 格式化

[root@demo ~]# mkfs.ext4 /dev/vgEric/lvEric 

8 挂载

[root@demo ~]# mkdir /newdirr
[root@demo ~]# mount /dev/vgEric/lvEric  /newdirr/

9 扩容

[root@demo ~]# lvextend -L +100M /dev/vgEric/lvEric 
  Rounding size to boundary between physical extents: 112.00 MiB
  Size of logical volume vgEric/lvEric changed from 512.00 MiB (32 extents) to 624.00 MiB (39 extents).
  Logical volume lvEric successfully resized.
[root@demo ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vgEric/lvEric
  LV Name                lvEric
  VG Name                vgEric
  LV UUID                aCSPxR-g9wq-oHM8-wk89-5BOE-ICsH-DXJQBR
  LV Write Access        read/write
  LV Creation host, time demo, 2020-08-04 18:17:21 +0800
  LV Status              available

  LV Size                624.00 MiB
  Current LE             39
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@demo ~]#  resize2fs /dev/vgEric/lvEric 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vgEric/lvEric is mounted on /newdirr; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vgEric/lvEric is now 159744 blocks long.

[root@demo ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda3                   38G  957M   37G   3% /
4% /boot
/dev/mapper/vgEric-lvEric  598M  780K  557M   1% /newdirr

LVM删除
1 卸载

[root@demo ~]# umount /newdirr/

2 先删除lv

[root@demo ~]# lvremove /dev/mapper/vgEric-lvEric 
Do you really want to remove active logical volume lvEric? [y/n]: y
  Logical volume "lvEric" successfully removed

3然后删除vg

[root@demo ~]# vgremove vgEric
  Volume group "vgEric" successfully removed

4 最后删除pv

[root@demo ~]# pvremove /dev/sdd 
  Labels on physical volume "/dev/sdd" successfully wiped

总结

磁盘

Fdisk /dev/sdb
n创建分区
t 改类型8e

物理卷

创建物理卷
pvcreate /dev/sdb1
列出所有物理卷
pvdisplay  / pvs
删除物理卷
pvremove /dev/sdb1

卷组

创建卷组
vgcreate vg1 /dev/sdb1
列出所有卷组
vgdisplay  /  vgs 
删除卷组
Vgremove vg1
扩展卷组
fdisk /dev/sdb 新加一个分区sdb2
在创建一个物理卷
pvcreate /dev/sdb2
然后扩展
Vgextend vg1 /dev/sdb2

逻辑卷

创建逻辑卷
Lvcreate –L –n lv1 vg1
列出所有逻辑卷
Lvdisplay
格式化逻辑卷 
mkfs.xfs  /dev/vg1/lv1
删除逻辑卷
lvremove /dev/vg1/lv1

逻辑卷扩容
Lvresize –L 300M /dev/vg1/lv1
更新信息
resize2fs /dev/vg1/lv1
逻辑卷缩容
先Unmount
然后设置卷大小
Lvresize –L 100M /dev/vg1/lv1
然后更新信息
resize2fs /dev/vg1/lv1
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页