Linux—LVM命令

  • Post author:
  • Post category:linux



目录


一、查看卷组信息


二、新建一个分区partition


三、创建物理卷pv


四、创建卷组vg


五、查看vg可用空间


六、建立逻辑卷lv


七、建立文件系统


八、建立挂载点


九、挂载存储


十、修改fstab配置文件实现自动挂载


十一、卸载卷组的逻辑卷lv


十二、删除逻辑卷lv


十三、删除卷组vg


十四、删除物理卷pv


十五、编辑/etc/fstab,删除对应挂载信息


一、查看卷组信息

查看服务器

卷组(VG)



物理卷(PV)



逻辑卷(LV)

相关信息。


vgscan

:查找系统中存在的LVM卷组。显示卷组名和LVM元数据类型。


vgdisplay

:查看卷组详细信息。


pvscan

:查看系统中所有连接硬盘,显示出物理卷。


lvscan

:查看所有LVM的逻辑卷(LV)。

新增硬盘后,用

fdisk -l

命令,查看新增硬盘。

二、新建一个分区partition

新建一个主分区(primary partition)或逻辑分区(logical partition)

[root@getlnx20 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xaa12f277.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): 
Using default value 10443
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

三、创建物理卷pv

[root@getlnx20 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@getlnx20 ~]# pvscan
  PV /dev/sda2   VG VolGroup00   lvm2 [39.51 GiB / 0    free]
  PV /dev/sdb1                   lvm2 [80.00 GiB]
  Total: 2 [119.51 GiB] / in use: 1 [39.51 GiB] / in no VG: 1 [80.00 GiB]

四、创建卷组vg

[root@getlnx20 ~]# vgcreate -s 32M VolGroup01 /dev/sdb1
  Volume group "VolGroup01" successfully created
[root@getlnx20 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup01" using metadata type lvm2
  Found volume group "VolGroup00" using metadata type lvm2

五、查看vg可用空间

[root@getlnx20 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup01
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               79.97 GiB
  PE Size               32.00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / 79.97 GiB
  VG UUID               FD5kEp-a9Cv-K181-Xb7e-i8k4-zV52-Dbuxc3
   
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               39.51 GiB
  PE Size               4.00 MiB
  Total PE              10114
  Alloc PE / Size       10114 / 39.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               sWwXef-0AHf-66ZI-dZHh-JuJt-KMj7-YqIisW

六、建立逻辑卷lv

[root@getlnx20 ~]# lvcreate -L79.97G -n LogVol00 VolGroup01
  Rounding up size to full physical extent 80.00 GiB
  Volume group "VolGroup01" has insufficient free space (2559 extents): 2560 required.
[root@getlnx20 ~]# lvcreate -L79.96G -n LogVol00 VolGroup01
  Rounding up size to full physical extent 79.97 GiB
  Logical volume "LogVol00" created
[root@getlnx20 ~]# lvscan
  ACTIVE            '/dev/VolGroup01/LogVol00' [79.97 GiB] inherit
  ACTIVE            '/dev/VolGroup00/lv_root' [31.51 GiB] inherit
  ACTIVE            '/dev/VolGroup00/lv_swap' [8.00 GiB] inherit

七、建立文件系统

[root@getlnx20 ~]# mkfs -t ext3 /dev/VolGroup01/LogVol00
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20963328 blocks
1048166 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
640 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000
 
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

八、建立挂载点

[root@getlnx20 ~]# mkdir /mysqldata

九、挂载存储

[root@getlnx20 ~]# mount /dev/VolGroup01/LogVol00 /mysqldata
[root@getlnx20 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-lv_root
                       31G  2.5G   27G   9% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             477M   33M  419M   8% /boot
/dev/mapper/VolGroup01-LogVol00
                       79G  184M   75G   1% /mysqldata

十、修改fstab配置文件实现自动挂载

[root@getlnx20 ~]# more /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Jun 13 10:29:07 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup00-lv_root /                       ext4    defaults        1 1
UUID=5486634e-ec6a-42d5-bbb9-dcd92537c294 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup00-lv_swap swap                    swap    defaults        0 0
/dev/VolGroup01/LogVol00                                /mysqldata  ext3 defaults 1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

十一、卸载卷组的逻辑卷lv

先 df -h 查看卷组信息,

/dev/mapper/VolGroup05-LogVol00      178G   48G  121G  29% /u05

然后再  vgdisplay 查看pv、lv信息

[root@getlnx01uat ~]# vgdisplay -v VolGroup05
    Using volume group(s) on command line
    Finding volume group "VolGroup05"
  --- Volume group ---
  VG Name               VolGroup05
  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               179.97 GB
  PE Size               32.00 MB
  Total PE              5759
  Alloc PE / Size       5759 / 179.97 GB
  Free  PE / Size       0 / 0   
  VG UUID               UNFxZH-lAGM-vqF3-jtNK-yuKT-enUX-WwL7FQ
   
  --- Logical volume ---
  LV Name                /dev/VolGroup05/LogVol00
  VG Name                VolGroup05
  LV UUID                kCTJnc-D3zQ-QiJp-TfPh-ivWs-WKyW-VvGTod
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                179.97 GB
  Current LE             5759
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Physical volumes ---
  PV Name               /dev/sdg5     
  PV UUID               VbSwjS-9ckQ-ZfWf-bl8g-oPWQ-TMBi-H6oMWv
  PV Status             allocatable
  Total PE / Free PE    5759 / 0

接下来卸载卷组逻辑卷

[root@getlnx01uat ~]# umount /dev/VolGroup05/LogVol00
或
[root@getlnx01uat ~]# umount /u05

十二、删除逻辑卷lv

[root@getlnx01uat ~]# lvremove /dev/VolGroup05/LogVol00
Do you really want to remove active logical volume LogVol00? [y/n]: y
  Logical volume "LogVol00" successfully removed

验证lv是否删除

[root@getlnx01uat ~]# lvdisplay | grep "dev/VolGroup05/LogVol00

十三、删除卷组vg

[root@getlnx01uat ~]# vgremove VolGroup05 
  Volume group "VolGroup05" successfully removed

采用安全方法删除卷组vg,用  vgchange -a n VolGroup05 关闭了vg_name,然后才可以删除它。

[root@getlnx01uat ~]# vgchange -a n VolGroup05
  0 logical volume(s) in volume group "VolGroup05" now active
[root@getlnx01uat ~]# vgremove VolGroup05 
  Volume group "VolGroup05" successfully removed

验证卷组vg是否删除

[root@getlnx01uat ~]# vgscan
 
Reading all physical volumes. This may take a while...
 
Found volume group "VolGroup04" using metadata type lvm2
 
Found volume group "VolGroup03" using metadata type lvm2
 
Found volume group "VolGroup02" using metadata type lvm2
 
Found volume group "VolGroup01" using metadata type lvm2
 
Found volume group "VolGroup00" using metadata type lvm2

十四、删除物理卷pv

[root@getlnx01uat ~]# pvremove /dev/sdg5  
  Labels on physical volume "/dev/sdg5" successfully wiped
[root@getlnx01uat ~]# pvscan
  PV /dev/sde5   VG VolGroup04   lvm2 [139.97 GB / 0    free]
  PV /dev/sdd5   VG VolGroup03   lvm2 [199.97 GB / 0    free]
  PV /dev/sdc5   VG VolGroup02   lvm2 [199.97 GB / 0    free]
  PV /dev/sdb5   VG VolGroup01   lvm2 [79.97 GB / 0    free]
  PV /dev/sda2   VG VolGroup00   lvm2 [51.88 GB / 0    free]
  PV /dev/sdf5   VG VolGroup00   lvm2 [59.97 GB / 0    free]
  Total: 6 [731.72 GB] / in use: 6 [731.72 GB] / in no VG: 0 [0   ]

十五、编辑/etc/fstab,删除对应挂载信息

这一步是为了避免重启时会报错。先用下面的命令,把系统文件权限改为rw读写。然后编辑/etc/fstab,删除挂载信息,重启即可。

mount -o remount, rw / 


本文参考:



Linux LVM学习总结——创建卷组VG



by 潇湘隐者



https://www.cnblogs.com/kerrycode/p/4612925.html







Linux LVM学习总结——删除卷组VG



by 潇湘隐者



https://www.cnblogs.com/kerrycode/p/4569515.html



版权声明:本文为Sven119原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。