博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CentOS 7笔记23】, Logical Volume Manager逻辑卷管理#
阅读量:5895 次
发布时间:2019-06-19

本文共 31990 字,大约阅读时间需要 106 分钟。

hot3.png

shallow丿ove


  • 物理分区(Phycical Partions)

  • 物理存储介质(PhysicalStorageMedia)

    指系统的物理存储设备:磁盘,如:/dev/hda、/dev/sda等,是存储系统最底层的存储单元

  • 物理卷(Physical Volume,PV)

    物理卷是指磁盘分区或者从逻辑上看起来和磁盘分区类似得设备(比如RAID设备)

  • 逻辑卷(Logical Volume,LV)

    一个或多个物理卷组成一个逻辑卷。对于LVM而言,逻辑卷类似于非LVM系统中的磁盘分区。逻辑卷可以包含一个文件系统(比如/home或者/usr)

  • 卷组(Volume Group,VG)

    一个或者多个逻辑卷组成一个卷组。对于LVM而言,逻辑卷类似于非LVM系统中的物理磁盘。卷组把多个逻辑卷组合再一起,形成了一个可管理的单元。

  • 物理块(Physical Extent,PE)

    物理卷按大小相等的“块”为单位存储,块的大小与卷组中逻辑块的大小相同。

  • 逻辑块(Logical Extent,LE)

    逻辑卷按“块”为单位存储,再一卷组中的所有逻辑卷的块大小是相同的。

LVM实现过程:物理磁盘分区->物理卷->卷组->逻辑卷->格式化->挂载

准备磁盘分区

  • fdisk /dev/sdb
  • n 创建三个新分区,分别1G
  • t 改变分区类型为8e
[root@localhost ~]# fdisk -l	Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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	Disk label type: dos	Disk identifier: 0x000c37f3	   Device Boot      Start         End      Blocks   Id  System	/dev/sda1   *        2048      411647      204800   83  Linux	/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris	/dev/sda3         4605952    62914559    29154304   83  Linux	Disk /dev/sdb: 10.7 GB, 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[root@localhost ~]# fdisk /dev/sdb	Welcome to fdisk (util-linux 2.23.2).	Changes will remain in memory only, until you decide to write them.	Be careful before using the write command.	Device does not contain a recognized partition table	Building a new DOS disklabel with disk identifier 0xe4f99297.	Command (m for help): p	Disk /dev/sdb: 10.7 GB, 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	Disk label type: dos	Disk identifier: 0xe4f99297	   Device Boot      Start         End      Blocks   Id  System	Command (m for help): n	Partition type:	   p   primary (0 primary, 0 extended, 4 free)	   e   extended	Select (default p): p	Partition number (1-4, default 1): 1	First sector (2048-20971519, default 2048): 	Using default value 2048	Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G	Partition 1 of type Linux and of size 1 GiB is set	Command (m for help): n	Partition type:	   p   primary (1 primary, 0 extended, 3 free)	   e   extended	Select (default p): p	Partition number (2-4, default 2): 2	First sector (2099200-20971519, default 2099200): 	Using default value 2099200	Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G	Partition 2 of type Linux and of size 1 GiB is set	Command (m for help): n  	Partition type:	   p   primary (2 primary, 0 extended, 2 free)	   e   extended	Select (default p): p	Partition number (3,4, default 3): 3	First sector (4196352-20971519, default 4196352): 	Using default value 4196352	Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +1G	Partition 3 of type Linux and of size 1 GiB is set	Command (m for help): p	Disk /dev/sdb: 10.7 GB, 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	Disk label type: dos	Disk identifier: 0xe4f99297	   Device Boot      Start         End      Blocks   Id  System	/dev/sdb1            2048     2099199     1048576   83  Linux	/dev/sdb2         2099200     4196351     1048576   83  Linux	/dev/sdb3         4196352     6293503     1048576   83  Linux	Command (m for help):
Command (m for help): t	Partition number (1-3, default 3): 1	Hex code (type L to list all codes): 8e	Changed type of partition 'Linux' to 'Linux LVM'	Command (m for help): t	Partition number (1-3, default 3): 2	Hex code (type L to list all codes): 8e	Changed type of partition 'Linux' to 'Linux LVM'	Command (m for help): t	Partition number (1-3, default 3): 3	Hex code (type L to list all codes): 8e   	Changed type of partition 'Linux' to 'Linux LVM'	Command (m for help): p	Disk /dev/sdb: 10.7 GB, 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	Disk label type: dos	Disk identifier: 0x5ec6916a	   Device Boot      Start         End      Blocks   Id  System	/dev/sdb1            2048     2099199     1048576   8e  Linux LVM	/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM	/dev/sdb3         4196352     6293503     1048576   8e  Linux LVM	Command (m for help): w[root@localhost ~]# fdisk -l	Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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	Disk label type: dos	Disk identifier: 0x000c37f3	   Device Boot      Start         End      Blocks   Id  System	/dev/sda1   *        2048      411647      204800   83  Linux	/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris	/dev/sda3         4605952    62914559    29154304   83  Linux	Disk /dev/sdb: 10.7 GB, 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	Disk label type: dos	Disk identifier: 0x5ec6916a	   Device Boot      Start         End      Blocks   Id  System	/dev/sdb1            2048     2099199     1048576   8e  Linux LVM	/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM	/dev/sdb3         4196352     6293503     1048576   8e  Linux LVM

准备物理卷

  • pvcreate /dev/sdb1

  • pvcreate /dev/sdb2

  • pvcreate /dev/sdb3

  • pvdisplay 列出当前的物理卷

  • pvremove /dev/sdb3 删除物理卷

安装lvm包

[root@localhost ~]# yum install -y lvmLoaded plugins: fastestmirrorbase                                                                        | 3.6 kB  00:00:00     extras                                                                      | 3.4 kB  00:00:00     updates                                                                     | 3.4 kB  00:00:00     (1/2): extras/7/x86_64/primary_db                                           | 129 kB  00:00:00     (2/2): updates/7/x86_64/primary_db                                          | 3.6 MB  00:00:24     Loading mirror speeds from cached hostfile * base: mirrors.shuosc.org * extras: mirrors.nju.edu.cn * updates: mirrors.nju.edu.cnNo package lvm available.Error: Nothing to do

上面安装lvm时出现了问题,说明lvm软件包名不是为lvm,当我们知道某一个软件包里的某一个命令时,可以使用yum provides “路径”来查询到软件包

例如:[root ~]# yum provides "/*/pvcreate"

[root@localhost ~]#  yum install -y lvm2	Loaded plugins: fastestmirror	base                                                                        | 3.6 kB  00:00:00     	extras                                                                      | 3.4 kB  00:00:00     	updates                                                                     | 3.4 kB  00:00:00     	Determining fastest mirrors	 * base: mirrors.btte.net	 * extras: ftp.sjtu.edu.cn	 * updates: mirrors.btte.net	Resolving Dependencies	--> Running transaction check	---> Package lvm2.x86_64 7:2.02.171-8.el7 will be installed	--> Processing Dependency: lvm2-libs = 7:2.02.171-8.el7 for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: device-mapper-persistent-data >= 0.7.0-0.1.rc6 for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: liblvm2app.so.2.2(Base)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_97)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_138)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_135)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_133)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_128)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_113)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_110)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_107)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_104)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_103)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_101)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper.so.1.02(DM_1_02_100)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper-event.so.1.02(Base)(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: liblvm2app.so.2.2()(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Processing Dependency: libdevmapper-event.so.1.02()(64bit) for package: 7:lvm2-2.02.171-8.el7.x86_64	--> Running transaction check	---> Package device-mapper-event-libs.x86_64 7:1.02.140-8.el7 will be installed	---> Package device-mapper-libs.x86_64 7:1.02.84-14.el7 will be updated	--> Processing Dependency: device-mapper-libs = 7:1.02.84-14.el7 for package: 7:device-mapper-1.02.84-14.el7.x86_64	---> Package device-mapper-libs.x86_64 7:1.02.140-8.el7 will be an update	---> Package device-mapper-persistent-data.x86_64 0:0.7.0-0.1.rc6.el7 will be installed	--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64	--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64	--> Processing Dependency: libaio.so.1()(64bit) for package: device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64	---> Package lvm2-libs.x86_64 7:2.02.171-8.el7 will be installed	--> Processing Dependency: device-mapper-event = 7:1.02.140-8.el7 for package: 7:lvm2-libs-2.02.171-8.el7.x86_64	--> Running transaction check	---> Package device-mapper.x86_64 7:1.02.84-14.el7 will be updated	---> Package device-mapper.x86_64 7:1.02.140-8.el7 will be an update	---> Package device-mapper-event.x86_64 7:1.02.140-8.el7 will be installed	---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed	--> Finished Dependency Resolution		Dependencies Resolved		===================================================================================================	 Package                               Arch           Version                   Repository    Size	===================================================================================================	Installing:	 lvm2                                  x86_64         7:2.02.171-8.el7          base         1.3 M	Installing for dependencies:	 device-mapper-event                   x86_64         7:1.02.140-8.el7          base         180 k	 device-mapper-event-libs              x86_64         7:1.02.140-8.el7          base         179 k	 device-mapper-persistent-data         x86_64         0.7.0-0.1.rc6.el7         base         400 k	 libaio                                x86_64         0.3.109-13.el7            base          24 k	 lvm2-libs                             x86_64         7:2.02.171-8.el7          base         1.0 M	Updating for dependencies:	 device-mapper                         x86_64         7:1.02.140-8.el7          base         280 k	 device-mapper-libs                    x86_64         7:1.02.140-8.el7          base         312 k	Transaction Summary	===================================================================================================	Install  1 Package  (+5 Dependent packages)	Upgrade             ( 2 Dependent packages)	Total download size: 3.6 M	Downloading packages:	Delta RPMs disabled because /usr/bin/applydeltarpm not installed.	(1/8): device-mapper-event-1.02.140-8.el7.x86_64.rpm                        | 180 kB  00:00:00     	(2/8): libaio-0.3.109-13.el7.x86_64.rpm                                     |  24 kB  00:00:00     	(3/8): device-mapper-1.02.140-8.el7.x86_64.rpm                              | 280 kB  00:00:01     	(4/8): device-mapper-libs-1.02.140-8.el7.x86_64.rpm                         | 312 kB  00:00:01     	(5/8): device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64.rpm           | 400 kB  00:00:02     	(6/8): device-mapper-event-libs-1.02.140-8.el7.x86_64.rpm                   | 179 kB  00:00:02     	(7/8): lvm2-libs-2.02.171-8.el7.x86_64.rpm                                  | 1.0 MB  00:00:02     	(8/8): lvm2-2.02.171-8.el7.x86_64.rpm                                       | 1.3 MB  00:00:03     	---------------------------------------------------------------------------------------------------	Total                                                              912 kB/s | 3.6 MB  00:00:04     	Running transaction check	Running transaction test	Transaction test succeeded	Running transaction	  Updating   : 7:device-mapper-libs-1.02.140-8.el7.x86_64                                     1/10 	  Updating   : 7:device-mapper-1.02.140-8.el7.x86_64                                          2/10 	  Installing : 7:device-mapper-event-libs-1.02.140-8.el7.x86_64                               3/10 	  Installing : 7:device-mapper-event-1.02.140-8.el7.x86_64                                    4/10 	  Installing : 7:lvm2-libs-2.02.171-8.el7.x86_64                                              5/10 	  Installing : libaio-0.3.109-13.el7.x86_64                                                   6/10 	  Installing : device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64                         7/10 	  Installing : 7:lvm2-2.02.171-8.el7.x86_64                                                   8/10 	ln -s '/usr/lib/systemd/system/lvm2-lvmpolld.socket' '/etc/systemd/system/sysinit.target.wants/lvm2-lvmpolld.socket'	  Cleanup    : 7:device-mapper-libs-1.02.84-14.el7.x86_64                                     9/10 	  Cleanup    : 7:device-mapper-1.02.84-14.el7.x86_64                                         10/10 	  Verifying  : 7:device-mapper-event-libs-1.02.140-8.el7.x86_64                               1/10 	  Verifying  : 7:device-mapper-event-1.02.140-8.el7.x86_64                                    2/10 	  Verifying  : 7:lvm2-libs-2.02.171-8.el7.x86_64                                              3/10 	  Verifying  : 7:device-mapper-1.02.140-8.el7.x86_64                                          4/10 	  Verifying  : 7:device-mapper-libs-1.02.140-8.el7.x86_64                                     5/10 	  Verifying  : 7:lvm2-2.02.171-8.el7.x86_64                                                   6/10 	  Verifying  : device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64                         7/10 	  Verifying  : libaio-0.3.109-13.el7.x86_64                                                   8/10 	  Verifying  : 7:device-mapper-libs-1.02.84-14.el7.x86_64                                     9/10 	  Verifying  : 7:device-mapper-1.02.84-14.el7.x86_64                                         10/10 	Installed:	  lvm2.x86_64 7:2.02.171-8.el7                                                                     	Dependency Installed:	  device-mapper-event.x86_64 7:1.02.140-8.el7                                                      	  device-mapper-event-libs.x86_64 7:1.02.140-8.el7                                                 	  device-mapper-persistent-data.x86_64 0:0.7.0-0.1.rc6.el7                                         	  libaio.x86_64 0:0.3.109-13.el7                                                                   	  lvm2-libs.x86_64 7:2.02.171-8.el7                                                                	Dependency Updated:	  device-mapper.x86_64 7:1.02.140-8.el7         device-mapper-libs.x86_64 7:1.02.140-8.el7        	Complete!

partprobe重载分区表

[root@localhost ~]# ls /dev/sdb[root@localhost ~]# partprobe	Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.	Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.	Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.[root@localhost ~]# pvcreate /dev/sdb1	  Device /dev/sdb1 not found (or ignored by filtering).[root@localhost ~]# df -h	Filesystem      Size  Used Avail Use% Mounted on	/dev/sda3        28G  865M   27G   4% /	devtmpfs        909M     0  909M   0% /dev	tmpfs           914M     0  914M   0% /dev/shm	tmpfs           914M   17M  897M   2% /run	tmpfs           914M     0  914M   0% /sys/fs/cgroup	/dev/sdb         10G   33M   10G   1% /mnt	/dev/sda1       197M   75M  123M  38% /boot[root@localhost ~]# umount /mnt

pvcreate将物理磁盘分区为物理卷

[root@localhost ~]# pvcreate /dev/sdb1	WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y	  Wiping ext4 signature on /dev/sdb1.	  Physical volume "/dev/sdb1" successfully created.[root@localhost ~]# pvcreate /dev/sdb2	  Physical volume "/dev/sdb2" successfully created.[root@localhost ~]# pvcreate /dev/sdb3	  Physical volume "/dev/sdb3" successfully created.

pvdisplay显示物理卷属性

[root@localhost ~]# pvdisplay	  "/dev/sdb3" is a new physical volume of "1.00 GiB"	  --- NEW Physical volume ---	  PV Name               /dev/sdb3	  VG Name               	  PV Size               1.00 GiB	  Allocatable           NO	  PE Size               0   	  Total PE              0	  Free PE               0	  Allocated PE          0	  PV UUID               JeafFf-5aVO-xNf2-DUv6-17S2-N8Cg-f0E3vX   	  "/dev/sdb1" is a new physical volume of "1.00 GiB"	  --- NEW Physical volume ---	  PV Name               /dev/sdb1	  VG Name               	  PV Size               1.00 GiB	  Allocatable           NO	  PE Size               0   	  Total PE              0	  Free PE               0	  Allocated PE          0	  PV UUID               DEzGdZ-eZpX-qWYI-XndU-e5X9-SEcT-MsiLCc   	  "/dev/sdb2" is a new physical volume of "1.00 GiB"	  --- NEW Physical volume ---	  PV Name               /dev/sdb2	  VG Name               	  PV Size               1.00 GiB	  Allocatable           NO	  PE Size               0   	  Total PE              0	  Free PE               0	  Allocated PE          0	  PV UUID               QI4y20-GOdg-8CBJ-PfZF-GO8l-ambD-f7Jikz

创建卷组

pvs输出格式化物理卷信息报表

[root@localhost ~]# pvs	  PV         VG Fmt  Attr PSize PFree	  /dev/sdb1     lvm2 ---  1.00g 1.00g	  /dev/sdb2     lvm2 ---  1.00g 1.00g	  /dev/sdb3     lvm2 ---  1.00g 1.00g

vgcreate 创建lvm卷组

[root@localhost ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2	  Volume group "vg1" successfully created[root@localhost ~]# vgdisplay	  --- Volume group ---	  VG Name               vg1	  System ID             	  Format                lvm2	  Metadata Areas        2	  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                2	  Act PV                2	  VG Size               1.99 GiB	  PE Size               4.00 MiB	  Total PE              510	  Alloc PE / Size       0 / 0   	  Free  PE / Size       510 / 1.99 GiB	  VG UUID               ad3wQ3-M3m1-btaW-ae4b-RhQl-9iPM-xBDFaS

vgs查询lvm卷组

[root@localhost ~]# vgs	  VG  #PV #LV #SN Attr   VSize VFree	  vg1   2   0   0 wz--n- 1.99g 1.99g

vgremove 删除卷组

创建逻辑卷

lvcreate创建lvm逻辑卷

[root@localhost ~]# lvcreate -L 100M -n lv1 vg1	  Logical volume "lv1" created.[root@localhost ~]# mkfs.ext4 /dev/vg1/lv1	mke2fs 1.42.9 (28-Dec-2013)	Filesystem label=	OS type: Linux	Block size=1024 (log=0)	Fragment size=1024 (log=0)	Stride=0 blocks, Stripe width=0 blocks	25688 inodes, 102400 blocks	5120 blocks (5.00%) reserved for the super user	First data block=1	Maximum filesystem blocks=33685504	13 block groups	8192 blocks per group, 8192 fragments per group	1976 inodes per group	Superblock backups stored on blocks: 		8193, 24577, 40961, 57345, 73729	Allocating group tables: done                            	Writing inode tables: done                            	Creating journal (4096 blocks): done	Writing superblocks and filesystem accounting information: done [root@localhost ~]# mount /dev/vg1/lv1 /mnt/[root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  994M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1   93M  1.6M   85M   2% /mnt

这时候我们会发现/dev/mapper/vg1-lv1这个目录,对以下两个路径,其实这个两个目录都是指向同一个目录的

[root@localhost ~]# ls -l /dev/vg1/lv1	lrwxrwxrwx. 1 root root 7 Nov  6 09:09 /dev/vg1/lv1 -> ../dm-0[root@localhost ~]# ls -l /dev/mapper/vg1-lv1	lrwxrwxrwx. 1 root root 7 Nov  6 09:09 /dev/mapper/vg1-lv1 -> ../dm-0
[root@localhost ~]# mkdir /mnt/111[root@localhost ~]# touch /mnt/1.txt[root@localhost ~]# echo "22222" > /mnt/1.txt

扩容逻辑卷

  • lvresize -L 300M /dev/vg1/lv1 #重置设置卷大小
  • e2fsck -f /dev/vg1/lv1 #检查磁盘错误(ext4执行)
  • resize2fs /dev/vg1/lv1 #更新逻辑卷信息(ext4执行)
  • xfs_growfs /dev/vg1/lv1 #xfs文件系统需要执行
[root@localhost ~]# lvresize -L 200M /dev/vg1/lv1	  Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).	  Logical volume vg1/lv1 successfully resized.[root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  993M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1   93M  1.6M   85M   2% /mnt

不合规范,应当先

[root@localhost ~]# umount /mnt/[root@localhost ~]# lvresize -L 200M /dev/vg1/lv1	  New size (50 extents) matches existing size (50 extents).

检查磁盘是否存在错误

[root@localhost ~]# e2fsck -f /dev/vg1/lv1	e2fsck 1.42.9 (28-Dec-2013)	Pass 1: Checking inodes, blocks, and sizes	Pass 2: Checking directory structure	Pass 3: Checking directory connectivity	Pass 4: Checking reference counts	Pass 5: Checking group summary information	/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks

更新逻辑卷

[root@localhost ~]# resize2fs /dev/vg1/lv1	resize2fs 1.42.9 (28-Dec-2013)	Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.	The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
[root@localhost ~]# mount /dev/vg1/lv1 /mnt/[root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  993M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1  190M  1.6M  175M   1% /mnt[root@localhost ~]# ls /mnt/	111  1.txt  lost+found[root@localhost ~]# cat /mnt/1.txt 	22222

若扩容导致文件丢失,那么扩容就没有存在的意义

若格式为xfs那么方法有些不一样

缩减逻辑卷

  • 先umount
  • e2fsck -f /dev/vg1/lv1 #检查磁盘错误(ext)
  • resize2fs /dev/vg1/lv1 100M #更新逻辑卷信息(ext)
  • lvresize -L 100M /dev/vg1/lv1 #重新设置卷大小

xfs并不支持

[root@localhost ~]# umount /mnt/[root@localhost ~]# e2fsck -f /dev/vg1/lv1	e2fsck 1.42.9 (28-Dec-2013)	Pass 1: Checking inodes, blocks, and sizes	Pass 2: Checking directory structure	Pass 3: Checking directory connectivity	Pass 4: Checking reference counts	Pass 5: Checking group summary information	/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks[root@localhost ~]# resize2fs /dev/vg1/lv1 100M	resize2fs 1.42.9 (28-Dec-2013)	Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.	The filesystem on /dev/vg1/lv1 is now 102400 blocks long.[root@localhost ~]# lvresize -L 100M /dev/vg1/lv1	  WARNING: Reducing active logical volume to 100.00 MiB.	  THIS MAY DESTROY YOUR DATA (filesystem etc.)	Do you really want to reduce vg1/lv1? [y/n]: y	  Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).	  Logical volume vg1/lv1 successfully resized.
[root@localhost ~]# lvdisplay	  --- Logical volume ---	  LV Path                /dev/vg1/lv1	  LV Name                lv1	  VG Name                vg1	  LV UUID                BTZG2e-59Qy-29ls-X6Ko-Dvbm-0zUp-2MTdpk	  LV Write Access        read/write	  LV Creation host, time centos1133, 2017-11-06 09:05:29 +0800	  LV Status              available	  # open                 0	  LV Size                100.00 MiB	  Current LE             25	  Segments               1	  Allocation             inherit	  Read ahead sectors     auto	  - currently set to     8192	  Block device           253:0[root@localhost ~]# lvs	  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert	  lv1  vg1 -wi-a----- 100.00m [root@localhost ~]# mount /dev/vg1/lv1 /mnt/[root@localhost ~]# ls /mnt/	111  1.txt  lost+found[root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  994M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1   93M  1.6M   85M   2% /mnt[root@localhost ~]# umount /mnt/

lvm并不会因为缩容而导致文件丢失

xfs扩容

[root@localhost ~]# mkfs.xfs -f /dev/vg1/lv1	meta-data=/dev/vg1/lv1           isize=512    agcount=4, agsize=6400 blks	         =                       sectsz=512   attr=2, projid32bit=1	         =                       crc=1        finobt=0, sparse=0	data     =                       bsize=4096   blocks=25600, imaxpct=25	         =                       sunit=0      swidth=0 blks	naming   =version 2              bsize=4096   ascii-ci=0 ftype=1	log      =internal log           bsize=4096   blocks=855, version=2	         =                       sectsz=512   sunit=0 blks, lazy-count=1	realtime =none                   extsz=4096   blocks=0, rtextents=0[root@localhost ~]# mount /dev/vg1/lv1 /mnt/[root@localhost ~]# ls /mnt/[root@localhost ~]# touch /mnt/2.txt[root@localhost ~]# echo 123 > /mnt/2.txt[root@localhost ~]# cat !$	cat /mnt/2.txt	123[root@localhost ~]# lvs	  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert	  lv1  vg1 -wi-ao---- 100.00m

xfs扩容时不需要umount

[root@localhost ~]# lvresize -L 300M /dev/vg1/lv1	  Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).	  Logical volume vg1/lv1 successfully resized.[root@localhost ~]# lvs	  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert	  lv1  vg1 -wi-ao---- 300.00m   [root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  994M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1   97M  5.2M   92M   6% /mnt

[root@localhost ~]# xfs_growfs -L 300M /dev/vg1/lv1	meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=4, agsize=6400 blks	         =                       sectsz=512   attr=2, projid32bit=1	         =                       crc=1        finobt=0 spinodes=0	data     =                       bsize=4096   blocks=25600, imaxpct=25	         =                       sunit=0      swidth=0 blks	naming   =version 2              bsize=4096   ascii-ci=0 ftype=1	log      =internal               bsize=4096   blocks=855, version=2	         =                       sectsz=512   sunit=0 blks, lazy-count=1	realtime =none                   extsz=4096   blocks=0, rtextents=0	xfs_growfs: XFS_IOC_FSGROWFSLOG xfsctl failed: Invalid argument

无效的参数?

[root@localhost ~]# umount /dev/vg1/lv1[root@localhost ~]# lvresize -L 310M /dev/vg1/lv1	  Rounding size to boundary between physical extents: 312.00 MiB.	  Size of logical volume vg1/lv1 changed from 300.00 MiB (75 extents) to 312.00 MiB (78 extents).	  Logical volume vg1/lv1 successfully resized.[root@localhost ~]# xfs_growfs -L 310M /dev/vg1/lv1	xfs_growfs: /dev/vg1/lv1 is not a mounted XFS filesystem	#必须挂载[root@localhost ~]# mount /dev/vg1/lv1 /mnt/[root@localhost ~]# xfs_growfs -L 310M /dev/vg1/lv1	meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=4, agsize=6400 blks	         =                       sectsz=512   attr=2, projid32bit=1	         =                       crc=1        finobt=0 spinodes=0	data     =                       bsize=4096   blocks=25600, imaxpct=25	         =                       sunit=0      swidth=0 blks	naming   =version 2              bsize=4096   ascii-ci=0 ftype=1	log      =internal               bsize=4096   blocks=855, version=2	         =                       sectsz=512   sunit=0 blks, lazy-count=1	realtime =none                   extsz=4096   blocks=0, rtextents=0	xfs_growfs: XFS_IOC_FSGROWFSLOG xfsctl failed: Invalid argument

[root@localhost ~]# xfs_growfs /dev/vg1/lv1	meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=4, agsize=6400 blks	         =                       sectsz=512   attr=2, projid32bit=1	         =                       crc=1        finobt=0 spinodes=0	data     =                       bsize=4096   blocks=25600, imaxpct=25	         =                       sunit=0      swidth=0 blks	naming   =version 2              bsize=4096   ascii-ci=0 ftype=1	log      =internal               bsize=4096   blocks=855, version=2	         =                       sectsz=512   sunit=0 blks, lazy-count=1	realtime =none                   extsz=4096   blocks=0, rtextents=0	data blocks changed from 25600 to 79872[root@localhost ~]# df -h	Filesystem           Size  Used Avail Use% Mounted on	/dev/sda3             28G  994M   27G   4% /	devtmpfs             903M     0  903M   0% /dev	tmpfs                912M     0  912M   0% /dev/shm	tmpfs                912M  8.6M  904M   1% /run	tmpfs                912M     0  912M   0% /sys/fs/cgroup	/dev/sda1            197M  113M   85M  58% /boot	tmpfs                183M     0  183M   0% /run/user/0	/dev/mapper/vg1-lv1  309M  5.5M  304M   2% /mnt

扩展卷组

  • fdisk /dev/sdb #新增/dev/sdb5(逻辑分区8e) 2G
  • pvcreate /dev/sdb5 #创建物理卷
  • vgextend vg1 /dev/sdb5 #把物理卷加入卷组中
  • lvresize -L 100M /dev/vg1/lv1 #重新设置卷大小

扩容卷组最高能扩到卷组一样大

[root@localhost ~]# vgs	  VG  #PV #LV #SN Attr   VSize VFree 	  vg1   2   1   0 wz--n- 1.99g <1.69g

sdb1和sdb2组成卷组,而sdb3是空闲的

[root@localhost ~]# vgextend vg1 /dev/sdb3	  Volume group "vg1" successfully extended[root@localhost ~]# vgdisplay	  --- Volume group ---	  VG Name               vg1	  System ID             	  Format                lvm2	  Metadata Areas        3	  Metadata Sequence No  7	  VG Access             read/write	  VG Status             resizable	  MAX LV                0	  Cur LV                1	  Open LV               1	  Max PV                0	  Cur PV                3	  Act PV                3	  VG Size               <2.99 GiB	  PE Size               4.00 MiB	  Total PE              765	  Alloc PE / Size       78 / 312.00 MiB	  Free  PE / Size       687 / 2.68 GiB	  VG UUID               G7DZt6-wLGz-HqEr-erYp-lDYP-53eM-KBf5NB[root@localhost ~]# vgs	  VG  #PV #LV #SN Attr   VSize  VFree	  vg1   3   1   0 wz--n- <2.99g 2.68g

先扩容卷组,再扩容逻辑卷


转载于:https://my.oschina.net/u/3892756/blog/3053833

你可能感兴趣的文章
部署P2P升级的脚本
查看>>
ubuntu下安装libxml2
查看>>
nginx_lua_waf安装测试
查看>>
WinForm窗体缩放动画
查看>>
JQuery入门(2)
查看>>
POI导出JavaWeb中的table到excel下载
查看>>
linux文件描述符
查看>>
C++ const 详解
查看>>
传值引用和调用引用的区别
查看>>
Hive简介
查看>>
hyper-v 无线网连接
查看>>
Python3.7.1学习(六)RabbitMQ在Windows环境下的安装
查看>>
Windows下memcached的安装配置
查看>>
ubuntu: firefox+flashplay
查看>>
常见的海量数据处理方法
查看>>
C语言博客作业03--函数
查看>>
web.xml 中CharacterEncodingFilter类的学习
查看>>
贪吃蛇逻辑代码
查看>>
实现c协程
查看>>
ASP.NET视频教程 手把手教你做企业论坛网站 视频教程
查看>>