命令

缩小PV空间到120G,即PV上的vg00已将缩小到120Gpvresize --setphysicalvolumesize 120g /dev/sda2

背景

机器上有一块900G本地的本地磁盘,安装系统时将900G的空间全部扩到了一个VG卷组中,即vg00,并创建了多个LV逻辑卷,LV逻辑卷占用了vg00卷组120G的空间,即卷组vg00还剩770G左右的空闲空间;此种文件系统格式不符合应用的规范标准,标准的文件系统规范为创建一个120G的卷组Vg00,使用Vg00卷组创建系统必要的LV逻辑卷,而剩下的770G空间新建卷组Vg01。为了满足应用需求,现将900G盘上的vg00空间缩小为120G,然后新建vg01使用剩下的770G空间。在不影响系统正常的情况下实现PV/VG的缩小。由于LV占用了120G的VG,即将VG空间缩小到120G方可最大化利用vg00卷组,为了达到缩小Vg00的需求,通过缩小PV来强制缩小Vg空间。

操作流程

现有文件系统

[root@sishb00302 ~]# vgsVG   #PV #LV #SN Attr   VSize   VFree  vg00   1   6   0 wz--n- 837.84g 721.84g
[root@sishb00302 ~]# lvsLV       VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertcrashvol vg00 -wi-ao---- 32.00g                                                    homevol  vg00 -wi-ao----  2.00g                                                    rootvol  vg00 -wi-ao---- 20.00g                                                    swapvol  vg00 -wi-ao---- 32.00g                                                    tmpvol   vg00 -wi-ao---- 10.00g                                                    varvol   vg00 -wi-ao---- 20.00g [root@sishb00302 ~]# fdisk /dev/sda
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.Command (m for help): pDisk /dev/sda: 900.2 GB, 900151926784 bytes, 1758109232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: dos
Disk identifier: 0x000cd03dDevice Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  1758107647   878540800   8e  Linux LVM

减小PV

[root@sishb00302 ~]# pvresize --setphysicalvolumesize 120g /dev/sda2Physical volume "/dev/sda2" changed1 physical volume(s) resized / 0 physical volume(s) not resized
[root@sishb00302 ~]# vgsVG   #PV #LV #SN Attr   VSize   VFreevg00   1   6   0 wz--n- 120.00g 4.00g
[root@sishb00302 ~]# pvsPV         VG   Fmt  Attr PSize   PFree/dev/sda2  vg00 lvm2 a--  120.00g 4.00g

删除原有的900G的/dev/sda2分区,新建/dev/sda2分区为120G,剩余空间为/dev/sda3分区

[root@sishb00302 ~]# fdisk /dev/sda
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.Command (m for help): pDisk /dev/sda: 900.2 GB, 900151926784 bytes, 1758109232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: dos
Disk identifier: 0x000cd03dDevice Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  1758107647   878540800   8e  Linux LVMCommand (m for help): d
Partition number (1,2, default 2):
Partition 2 is deletedCommand (m for help): n
Partition type:p   primary (1 primary, 0 extended, 3 free)e   extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (1026048-1758109231, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-1758109231, default 1758109231): +120G
Partition 2 of type Linux and of size 120 GiB is setCommand (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): n
Partition type:p   primary (2 primary, 0 extended, 2 free)e   extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (252684288-1758109231, default 252684288):
Using default value 252684288
Last sector, +sectors or +size{K,M,G} (252684288-1758109231, default 1758109231):
Using default value 1758109231
Partition 3 of type Linux and of size 717.9 GiB is setCommand (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

移除/dev/vg00/crashvol文件系统

[root@sishb00302 ~]# umount /var/crash/
[root@sishb00302 ~]# lvremove /dev/vg00/crashvol
Do you really want to remove active logical volume vg00/crashvol? [y/n]: yLogical volume "crashvol" successfully removed
[root@sishb00302 ~]# lvsLV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Converthomevol vg00 -wi-ao----  2.00g                                                    rootvol vg00 -wi-ao---- 20.00g                                                    swapvol vg00 -wi-ao---- 32.00g                                                    tmpvol  vg00 -wi-ao---- 10.00g                                                    varvol  vg00 -wi-ao---- 20.00g
[root@sishb00302 ~]# vgsVG   #PV #LV #SN Attr   VSize   VFree vg00   1   5   0 wz--n- 120.00g 36.00g

/dev/vg00/varvol逻辑卷在线扩容

[root@sishb00302 ~]# lvextend -L +30g /dev/vg00/varvol -rSize of logical volume vg00/varvol changed from 20.00 GiB (5120 extents) to 50.00 GiB (12800 extents).Logical volume vg00/varvol successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg00-varvol is mounted on /var; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/mapper/vg00-varvol is now 13107200 blocks long.[root@sishb00302 ~]# lvsLV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Converthomevol vg00 -wi-ao----  2.00g                                                    rootvol vg00 -wi-ao---- 20.00g                                                    swapvol vg00 -wi-ao---- 32.00g                                                    tmpvol  vg00 -wi-ao---- 10.00g                                                    varvol  vg00 -wi-ao---- 50.00g

修改fatab文件

修改前
[root@sishb00302 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar  6 11:44:46 2018
#
# 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/vg00-rootvol /                       ext4    defaults        1 1
UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot                   ext4    defaults        1 2
/dev/mapper/vg00-homevol /home                   ext4    defaults        1 2
/dev/mapper/vg00-tmpvol /tmp                    ext4    defaults        1 2
/dev/mapper/vg00-varvol /var                    ext4    defaults        1 2
/dev/mapper/vg00-crashvol /var/crash              ext4    defaults        1 2
/dev/mapper/vg00-swapvol swap                    swap    defaults        0 0修改后
[root@sishb00302 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar  6 11:44:46 2018
#
# 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/vg00-rootvol /                       ext4    defaults        1 1
UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot                   ext4    defaults        1 2
/dev/mapper/vg00-homevol /home                   ext4    defaults        1 2
/dev/mapper/vg00-tmpvol /tmp                    ext4    defaults        1 2
/dev/mapper/vg00-varvol /var                    ext4    defaults        1 2
/dev/mapper/vg00-swapvol swap                    swap    defaults        0 0

关机重启系统,从而释放/Idev/sda3分区的空间

空间释放后,再次创建vg01卷组

[root@sishb00302 ~]# lvsLV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Converthomevol vg00 -wi-ao----  2.00g                                                    rootvol vg00 -wi-ao---- 20.00g                                                    swapvol vg00 -wi-ao---- 32.00g                                                    tmpvol  vg00 -wi-ao---- 10.00g                                                    varvol  vg00 -wi-ao---- 50.00g                                                    [root@sishb00302 ~]# vgcreate /dev/vg01 /dev/sda3Physical volume "/dev/sda3" successfully created.Volume group "vg01" successfully created
[root@sishb00302 ~]# vgsVG   #PV #LV #SN Attr   VSize   VFree  vg00   1   5   0 wz--n- 120.00g   6.00gvg01   1   0   0 wz--n- 717.84g 717.84g[root@sishb00302 ~]# lvsLV      VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Converthomevol vg00 -wi-ao----  2.00g                                                    rootvol vg00 -wi-ao---- 20.00g                                                    swapvol vg00 -wi-ao---- 32.00g                                                    tmpvol  vg00 -wi-ao---- 10.00g                                                    varvol  vg00 -wi-ao---- 50.00g

最终实现了vg00文件系统从900G减小到了120G,并新建了vg01卷组

转载于:https://www.cnblogs.com/JevonWei/p/8532859.html

重做LVM文件系统之减小PV相关推荐

  1. LVM之VG、PV误删除恢复方法

    VG恢复 一.lvremove误删除vg卷组 lvremove vgname 会删除vg下的所有pv,需要用archive记录的元数据日志去恢复lv [root@centos7 archive]# l ...

  2. shell命令之---LVM文件系统

    1.文件系统 现在文件系统主要分为:日志文件系统和写时复制文件系统. 文件系统日志方法 方法                             描述 数据模式                 索 ...

  3. 【AWSL】之LVM与磁盘配额(PV、VG、LV、mkfs)

    序言 这里我主要介绍一些Linux关于磁盘配额的一些问题 LVM与磁盘配额 序言 一.LVM概述 1.LVM的管理命令 2.LVM的操作实例 二.磁盘配额概述 三.磁盘配额管理 总结 一.LVM概述 ...

  4. linux增加阵列磁盘空间,Linux Ubuntu系统下通过LVM创建软raid来实现硬盘合并大小

    将两块空硬盘合并为"一块",挂载到指定目录下,达到在一个目录使用3块硬盘所有空间的效果. 条件: 硬盘1 /dev/sda 硬盘2 /dev/sdb 硬盘3 /dev/sdc 方法 ...

  5. 学习笔记之lvm基本应用及其扩展和缩减实现

    Lvm 基本应用,扩展及缩减实现 Lvm是什么:logical volume manager,逻辑卷管理 学习lvm我们能实现什么?Lvm作用就是屏蔽了底层磁盘布局,便于动态调整磁盘容量,进而高效管理 ...

  6. Linux下逻辑卷LVM的管理和RAID磁盘阵列

    Linux系统安全 | Linux下逻辑卷LVM的管理和RAID磁盘阵列 原创 谢公子 [谢公子学安全](javascript:void(0);) 昨天 转载自公众号:谢公子学安全 图片 图片 LVM ...

  7. LVM: Logical Volume Manager 逻辑卷管理

    一.LVM介绍 LVM: Logical Volume Manager, Version: 2 允许对卷进行方便操作的抽象层,包括重新设定文件系统的大小 允许在多个物理设备间重新组织文件系统 将设备指 ...

  8. 理解 LVM (Logical Volume Manager)

    理解 LVM (Logical Volume Manager) Posted on2008-10-26 by hilyjiang 最近在安装 Gentoo 的过程中遇到一个新名词 ── LVM.由于在 ...

  9. linux中lvm卷管理

    一.LVM逻辑盘卷管理 (1)简介 LVM是逻辑盘卷管理(LogicalVolumeManager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层, ...

最新文章

  1. Python说“万能钥匙”不可见密码,立马写了个脚本解决了
  2. 小米note3无线显示电脑连接服务器,小米note3如何连接电脑 小米note3连接电脑没反应怎么办...
  3. python正则表达式匹配模式屠夫之桥_Python 编程快速上手 第 7章 模式匹配与正则表达式...
  4. session.merge 缓存不更新_这几个缓存更新的设计你都知道吗?
  5. Unknown/unsupported param List(--dist-cache-conf
  6. UE4 集成讯飞听写插件
  7. 算法训练营 重编码_您在编码训练营期间可能面临的最大挑战
  8. java索引ref_java – 如何使用jgit库将git HEAD指向特定的ref?
  9. c语言圆周率计算_C语言入门这一篇就够了
  10. CentOS系统Tomcat 8.5/9部署SSL证书
  11. android clipRect 用法说明
  12. Python中的unittest模块(入门学习款)
  13. [机器学习] Ubuntu 软件源更新(校园网)以及问题总结
  14. 基于MATLAB的AM调制解调
  15. Excel VBA ListBox列表框学习
  16. 惠普电脑u盘重装系统步骤_惠普笔记本u盘重装系统|惠普笔记本怎么用u盘重装系统...
  17. 大量打印怎么省钱,数量多怎么打印便宜
  18. [康宁]浅论亚里士多德对柏拉图“理念论”的批判与继承
  19. isnan函数返回值c语言,C++ std::isnan等函数的使用
  20. 大连 青少年 python 培训

热门文章

  1. 商汤 CVPR 2021的优异成绩单!
  2. 村土地利用规划和村庄规划的区别和联系
  3. 复练-软考网规-虚拟化专题
  4. 人工智能诗歌写作平台_人工智能教作文,只写出二类文,人类语文老师稳赢
  5. python企业级框架_Python六大开源框架对比:Web2py略胜一筹(转)
  6. matlab中fminunc函数使用方法,关于Matlab:了解fminunc参数和匿名函数,函数处理程序...
  7. mysql 中序号要怎么写_如何在mysql的字段ID中插入自动编号?
  8. Linux shell脚本启动 停止 重启jar包
  9. Linux 删除权限 umask,linux中的umask控制文件或目录的默认权限
  10. ajax请求可以延时吗,延时校验AJAX请求