ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

LVM逻辑卷的创建,扩容和删除

2021-07-13 11:30:05  阅读:133  来源: 互联网

标签:逻辑 删除 bytes dev server LVM datastore 512 root


要求:
1.添加一个新的swap分区,大小为512MB,开机自动挂载,不用修改或移除其他已经存在的swap分区
2.创建一个逻辑卷:先创建一个名为datastore的卷组,大小为4G,逻辑卷名为database,所属卷组为datastore,逻辑卷大小为3G,将新建的逻辑卷格式化为xfs文件系统,开机自动挂载到/database
3.扩大database逻辑卷大小为4G
4.删除所有逻辑卷恢复到系统最初状
前提是确认我们已经安装好了LVM的包

[root@server ~]# rpm -qa | grep lvm
llvm-libs-9.0.1-4.module+el8.2.0+5887+847e8a86.x86_64
udisks2-lvm2-2.8.3-2.el8.x86_64
lvm2-2.03.08-3.el8.x86_64
libblockdev-lvm-2.19-12.el8.x86_64
lvm2-libs-2.03.08-3.el8.x86_64

一.首先我们创建一个新的swap分区,大小为512m

[root@server ~]# fdisk /dev/sda      //我们添加的SATA磁盘

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xdf39d7d7

Device     Boot Start     End Sectors Size Id Type
/dev/sda1        2048 4196351 4194304   2G 8e Linux LVM   //目前只有一个分区

Command (m for help): n                        //创建新的分区
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-20971519, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-20971519, default 20971519): +512M

Created a new partition 2 of type 'Linux' and of size 512 MiB.

Command (m for help): p
Disk /dev/sda: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xdf39d7d7

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1          2048 4196351 4194304    2G 8e Linux LVM
/dev/sda2       4196352 5244927 1048576  512M 83 Linux

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82     //格式改为swap

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): w        //保存退出
The partition table has been altered.
Syncing disks.
[root@server ~]# mkswap /dev/sda2      //格式化
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=8cdf0601-beb6-4caf-8431-4adb7609d0c1
[root@server ~]# vim /etc/fstab       //挂载
[root@server ~]# swapon /dev/sda2     //激活

在这里插入图片描述

二.我们和上题一样,先创建好了sda1和sdb1 2个2G的分区,并将其改为LVM格式(8e),用来整合为一个4G的卷组。

[root@server ~]# fdisk /dev/sda     //创建分区

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xdf39d7d7

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1          2048 4196351 4194304    2G 8e Linux LVM
/dev/sda2       4196352 5244927 1048576  512M 82 Linux swap / Solaris

Command (m for help): w
The partition table has been altered.
Syncing disks.



[root@server ~]# fdisk /dev/sdb      //创建分区

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xe6e5267c

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4196351 4194304   2G 8e Linux LVM



[root@server ~]# pvcreate /dev/sda1 /dev/sdb1    //创建物理卷
  Physical volume "/dev/sda1" successfully created.
  Physical volume "/dev/sdb1" successfully created.
[root@server ~]# vgcreate datastore /dev/sda1 /dev/sdb1   //创建卷组
  Volume group "datastore" successfully created
[root@server ~]# lvcreate -n database -L 3G datastore   //创建逻辑卷
  Logical volume "database" created.
[root@server ~]# mkdir /database     //创建挂载点
[root@server ~]# mkfs.xfs /dev/datastore/database   //格式化
[root@server ~]# mount /dev/datastore/database /database/  //挂载


三.扩展

[root@server ~]# fdisk /dev/sda      //先创建一个新的分区

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xdf39d7d7

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1          2048  4196351  4194304    2G 8e Linux LVM
/dev/sda2       4196352  5244927  1048576  512M 82 Linux swap / Solaris
/dev/sda3       5244928 15730687 10485760    5G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@server ~]# pvcreate /dev/sda3       //再添加新的物理卷分区
  Physical volume "/dev/sda3" successfully created.

[root@server ~]# vgextend datastore /dev/sda3     //增加卷组
  Volume group "datastore" successfully extended
[root@server ~]# lvextend -L +1G /dev/datastore/database   //增加1G逻辑卷
  Size of logical volume datastore/database changed from 3.00 GiB (768 extents) to 4.00 GiB (1024 extents).
  Logical volume datastore/database successfully resized.
[root@server ~]# lvs
  LV       VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  database datastore -wi-a-----  4.00g          //逻辑卷为4G
  root     rhel      -wi-ao---- 10.00g
  swap     rhel      -wi-ao----  2.00g


四.删除
删除的顺序是lv -> vg -> pv ->sda/sdb ->SATA

[root@server ~]# lvremove /dev/datastore/database     //移除逻辑卷
Do you really want to remove active logical volume datastore/database? [y/n]: y
  Logical volume "database" successfully removed
[root@server ~]# vgremove datastore      //移除卷组
  Volume group "datastore" successfully removed
[root@server ~]# pvremove /dev/sda1 /dev/sda3 /dev/sdb1    //移除物理卷
  Labels on physical volume "/dev/sda1" successfully wiped.
  Labels on physical volume "/dev/sda3" successfully wiped.
  Labels on physical volume "/dev/sdb1" successfully wiped.
[root@server ~]# fdisk /dev/sda      //移除分区

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1-3, default 3): 1

Partition 1 has been deleted.

Command (m for help): d
Partition number (2,3, default 3): 3

Partition 3 has been deleted.

Command (m for help): w
The partition table has been altered.
Syncing disks.

[root@server ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Command (m for help): w
The partition table has been altered.
Syncing disks.

最后我们手动移除磁盘就OK了。

标签:逻辑,删除,bytes,dev,server,LVM,datastore,512,root
来源: https://blog.csdn.net/weixin_53202364/article/details/118692024

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有