lvm+xfs的扩缩容
ext4文件系统可以经行扩缩容操作,但xfs的文件系统只能扩容,无法缩容
所以如果需要进行xfs的缩容,可以先使用xfsdump备份文件系统,然后对逻辑卷(/分区)进行缩容操作(此时原xfs文件系统会损坏),然后再重新格式化该逻辑卷(/分区),最后xfsrestore将备份还原到该逻辑卷(/分区)
当然,这需要先下载xfsdump工具
[root@localhost ~]# df -Th #查看文件系统磁盘使用情况
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run
tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 3.0G 47G 6% /
/dev/sda2 xfs 1014M 131M 884M 13% /boot
/dev/sda1 vfat 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home xfs 64G 33M 64G 1% /home
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@localhost ~]# xfsdump -f ~/home.xfs_dump /home #备份文件系统
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control ============================= dump label dialog ============================== please enter label for this dump session (timeout in 300 sec)
-> #自定义备份会话标签,可直接回车
session label entered: "" --------------------------------- end dialog --------------------------------- xfsdump: WARNING: no session label specified
xfsdump: level 0 dump of localhost.localdomain:/home
xfsdump: dump date: Wed Oct 26 22:48:12 2022
xfsdump: session id: e3f11041-db93-41db-954f-b1101edb7b42
xfsdump: session label: ""
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes ============================= media label dialog ============================= please enter label for media in drive 0 (timeout in 300 sec)
-> #自定义备份媒体标签,可直接回车
media label entered: "" --------------------------------- end dialog --------------------------------- xfsdump: WARNING: no media label specified
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21352 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 1 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /root/home.xfs_dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost ~]# umount /home #卸载home分区,(业内习惯性叫home分区,其实就是home逻辑卷)
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-a----- 64.00g
root centos -wi-ao---- 50.00g
swap centos -wi-ao---- 12.80g
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 126.80g 0
[root@localhost ~]# lvreduce -L 24G /dev/mapper/centos-home #home分区缩容
WARNING: Reducing active logical volume to 24.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
Size of logical volume centos/home changed from 64.00 GiB (16384 extents) to 24.00 GiB (6144 extents).
Logical volume centos/home successfully resized.
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root #将空余空间全部给root分区
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 90.00 GiB (23040 extents).
Logical volume centos/root successfully resized.
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root #逻辑卷扩容后,需要刷新文件系统
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 23592960
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run
tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 90G 3.0G 87G 4% /
/dev/sda2 xfs 1014M 131M 884M 13% /boot
/dev/sda1 vfat 200M 12M 189M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@localhost ~]# mkfs.xfs /dev/mapper/centos-home -f #格式化home分区
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=1572864 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=6291456, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=3072, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/mapper/centos-home /home/ #重新挂载home分区
[root@localhost ~]# xfsrestore -f ~/home.xfs_dump /home #home文件系统还原
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: localhost.localdomain
xfsrestore: mount point: /home
xfsrestore: volume: /dev/mapper/centos-home
xfsrestore: session time: Wed Oct 26 22:48:12 2022
xfsrestore: level: 0
xfsrestore: session label: ""
xfsrestore: media label: ""
xfsrestore: file system id: e59981eb-07f9-44e4-9c6f-9ecd8afc8b81
xfsrestore: session id: e3f11041-db93-41db-954f-b1101edb7b42
xfsrestore: media id: fd63d3e5-9bee-49f8-9872-9d17e82f80fc
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 0 entries processed
xfsrestore: directory post-processing
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /root/home.xfs_dump OK (success)
xfsrestore: Restore Status: SUCCESS [root@localhost ~]# df -Th #核对现在逻辑卷文件系统的情况
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 7.9G 8.9M 7.9G 1% /run
tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 90G 3.0G 87G 4% /
/dev/sda2 xfs 1014M 131M 884M 13% /boot
/dev/sda1 vfat 200M 12M 189M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home xfs 24G 33M 24G 1% /home
[root@localhost ~]#
#若有必要,使用uuid挂载
[root@localhost ~]# grep home /etc/fstab
/dev/mapper/centos-home /home xfs defaults 0 0
[root@localhost ~]# blkid|grep home
/dev/mapper/centos-home: UUID="39916644-f3eb-42c1-a940-8749395b88f9" TYPE="xfs"
xfsdump也可以面交互执行
-L :xfsdump 记录每次备份的 session 标头,这里可以填写针对此文件系统的简易说明
-M :xfsdump 可以记录存储媒体的标头,这里可以填写此媒体的简易说明
[root@localhost ~]# xfsdump -f ~/home.xfs_dump01 /home -L home_dump -M root_dir
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsdump: level 0 dump of localhost.localdomain:/home
xfsdump: dump date: Wed Oct 26 23:39:40 2022
xfsdump: session id: fa67f2be-0efe-4d23-b096-0fb0e3d12558
xfsdump: session label: "home_dump"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21352 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 0 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /root/home.xfs_dump01 OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost ~]#
lvresize
-L :指定逻辑卷的大小, 单位为“kKmMgGtT”字节
-l : 指定逻辑卷的大小单位为PE
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 4 0 wz--n- <129.80g 1020.00m
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 24.00g
root centos -wi-ao---- 90.00g
sdbtest centos -wi-a----- 2.00g
swap centos -wi-ao---- 12.80g
[root@localhost ~]# lvresize -L 1g sdbtest
Please specify a logical volume path.
Run `lvresize --help' for more information.
[root@localhost ~]# lvresize -L 1g /dev/centos/sdbtest -f
WARNING: Reducing active logical volume to 1.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Size of logical volume centos/sdbtest changed from 2.00 GiB (512 extents) to 1.00 GiB (256 extents).
Logical volume centos/sdbtest successfully resized.
[root@localhost ~]# lvresize -L 1.5g /dev/mapper/centos-sdbtest
Size of logical volume centos/sdbtest changed from 1.00 GiB (256 extents) to 1.50 GiB (384 extents).
Logical volume centos/sdbtest successfully resized.
[root@localhost ~]# lvresize -L -0.5g /dev/mapper/centos-sdbtest -f
WARNING: Reducing active logical volume to 1.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Size of logical volume centos/sdbtest changed from 1.50 GiB (384 extents) to 1.00 GiB (256 extents).
Logical volume centos/sdbtest successfully resized.
[root@localhost ~]# lvresize -l +100%free /dev/mapper/centos-sdbtest -f
Size of logical volume centos/sdbtest changed from 1.00 GiB (256 extents) to <3.00 GiB (767 extents).
Logical volume centos/sdbtest successfully resized.
[root@localhost ~]#
[root@localhost ~]# ll -d /dev/mapper/centos-sdbtest
lrwxrwxrwx. 1 root root 7 Oct 27 14:26 /dev/mapper/centos-sdbtest -> ../dm-3
[root@localhost ~]# ll -d /dev/centos/sdbtest
lrwxrwxrwx. 1 root root 7 Oct 27 14:26 /dev/centos/sdbtest -> ../dm-3
[root@localhost ~]# ll -d /dev/dm-3
brw-rw----. 1 root disk 253, 3 Oct 27 14:26 /dev/dm-3
[root@localhost ~]#
指定只备份分区中某个目录
参数:-s 文件路径 只对指定的文件进行备份,-s指定时,路径写的是相对路径(-s 可以是文件或目录)
[root@localhost sdb1]# xfsdump -f /opt/dump_grub2 -s grub2/grub.cfg /boot -L dump_grub2 -M boot-sda1
备份成功后,我们可以在/var/lib/xfsdump/inventory 目录下看到生成的档案信息
[root@localhost sdb1]# ls /
var
/lib/xfsdump/inventory/
0180aae6-80c6-472f-a031-c79f271f8177.InvIndex
a5398b8f-e1ae-49a4-9d70-5f1fc5a68194.StObj
a5c5b8d4-6656-4023-b576-96593b9440b8.StObj
ba6ae155-c50d-440d-802f-7111a5cd3d03.InvIndex
fstab
当然如果遇到挂载点繁忙,可以使用fuser或lsof去查看,或者直接umount -lf 挂载点
fuser 可以显示出当前哪个程序在使用磁盘上的:
某个文件
挂载点
甚至网络端口
lvm+xfs的扩缩容的更多相关文章
- 构建Docker平台【第四篇】创建服务及扩缩容等操作
第一步:创建服务 1. 配置 nginx 的 yaml 文件 apiVersion: extensions/v1beta1 kind: Deployment metadata: name: my-ng ...
- Knative 基本功能深入剖析:Knative Serving 自动扩缩容 Autoscaler
Knative Serving 默认情况下,提供了开箱即用的快速.基于请求的自动扩缩容功能 - Knative Pod Autoscaler(KPA).下面带你体验如何在 Knative 中玩转 Au ...
- 如何根据不同业务场景调节 HPA 扩缩容灵敏度
背景 在 K8s 1.18 之前,HPA 扩容是无法调整灵敏度的: 对于缩容,由 kube-controller-manager 的 --horizontal-pod-autoscaler-downs ...
- 通过Dapr实现一个简单的基于.net的微服务电商系统(十一)——一步一步教你如何撸Dapr之自动扩/缩容
上一篇我们讲到了dapr提供的bindings,通过绑定可以让我们的程序轻装上阵,在极端情况下几乎不需要集成任何sdk,仅需要通过httpclient+text.json即可完成对外部组件的调用,这样 ...
- Docker Swarm(七)Scale 扩(缩)容服务
扩(缩)容服务 扩容服务 Service还提供了复制(类似kubernetes里的副本)功能.可以通过 docker service scale 命令来设置服务中容器的副本数: docker serv ...
- 从零入门 Serverless | Serverless Kubernetes 应用部署及扩缩容
作者 | 邓青琳(轻零) 阿里云技术专家 导读:本文分为三个部分,首先给大家演示 Serverless Kubernetes 集群的创建和业务应用的部署,其次介绍 Serverless Kuberne ...
- 【kubevirt】VirtualMachineInstanceReplicaSet(vmis)-扩缩容-弹性伸缩
@ 目录 概述/理解 使用场景 创建vmis 扩缩容 弹性伸缩 方法1 方法2 概述/理解 VirtualMachineInstanceReplicaSet(vmis)确保指定数量的 VirtualM ...
- Netty 如何高效接收网络数据?一文聊透 ByteBuffer 动态自适应扩缩容机制
本系列Netty源码解析文章基于 4.1.56.Final版本,公众号:bin的技术小屋 前文回顾 在前边的系列文章中,我们从内核如何收发网络数据开始以一个C10K的问题作为主线详细从内核角度阐述了网 ...
- Airbnb的动态kubernetes集群扩缩容
Airbnb的动态kubernetes集群扩缩容 本文介绍了Airbnb的集群扩缩容的演化历史,以及当前是如何通过Cluster Autoscaler 实现自定义扩展器的.最重要的经验就是Airbnb ...
- Kubernetes 监控:Prometheus Adpater =》自定义指标扩缩容
使用 Kubernetes 进行容器编排的主要优点之一是,它可以非常轻松地对我们的应用程序进行水平扩展.Pod 水平自动缩放(HPA)可以根据 CPU 和内存使用量来扩展应用,前面讲解的 HPA 章节 ...
随机推荐
- python3之35个关键字详解
一. python35个关键字列举: help("keywords")查看运行结果: 1. and.or.not 2. if.elif.else3. for.while4. Tru ...
- 【FAQ】接入华为应用内支付服务常见问题解答
HMS Core应用内支付服务(In-App Purchases,IAP)为应用提供便捷的应用内支付体验和简便的接入流程.开发者的应用集成IAP SDK后,调用IAP SDK接口,启动IAP收银台,即 ...
- spring native 初体验实现 小米控制美的空调
目前关于 spring native 分享的文章还比较少 写这篇文章的主要目前是分享一下自己写的一个 小米控制美的空调 的程序 集成 spring native 过程中碰到的一些问题和解决方法 先放地 ...
- 使用pktmon抓包
在Windows上遇到网络问题,需要抓包的时候之前我们会使用netmon和Microsoft Message Analyzer.随着时间的推移,微软已经停止了对Microsoft Message An ...
- Docker网络详解——原理篇
安装Docker时,它会自动创建三个网络,bridge(创建容器默认连接到此网络). none .host 网络模式 简介 Host 容器将不会虚拟出自己的网卡,配置自己的IP等,而是使用宿主机的IP ...
- 基于electron+vue+element构建项目模板之【打包篇】
1.概述 开发平台OS:windows 开发平台IDE:vs code 本项目使用了一款Vue-CLI插件(vue-cli-plugin-electron-builder) 来构建 electron ...
- Spring笔记四
Spring-04 1.Spring整合Junit ①导入依赖 <!-- junit --> <dependency> <groupId>junit</gro ...
- 基于Netty的TCP服务框架
19年写的一个基础的TCP服务框架,内置了一个简单IOC容器,当时的目标是一方面能作为组件供第三方集成实现TCP通讯相关功能,另一方面作为提供一种服务框架范式.所以框架核心点主要还是通过适度的封装,隐 ...
- 洛谷P1714 切蛋糕(单调队列)
先放代码...... 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=5e5+10,M=0x3f3f3f3f; ...
- 记一次 .NET 某电子病历 CPU 爆高分析
一:背景 1.讲故事 前段时间有位朋友微信找到我,说他的程序出现了 CPU 爆高,帮忙看下程序到底出了什么情况?图就不上了,我们直接进入主题. 二:WinDbg 分析 1. CPU 真的爆高吗? 要确 ...