当前位置: 首页 > article >正文

Linux业务系统将/home目录删除并将空间扩给根目录

原有目录空间分配如下:

[root@hisdb ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   21G   10G   11G  50% /
devtmpfs             905M     0  905M   0% /dev
tmpfs                920M  177M  744M  20% /dev/shm
tmpfs                920M  8.9M  912M   1% /run
tmpfs                920M     0  920M   0% /sys/fs/cgroup
/dev/sdb1           1014M  173M  842M  18% /boot
/dev/mapper/cl-home   15G  2.1G   13G  14% /home
/dev/mapper/cl-u01    20G   14G  6.1G  70% /u01
tmpfs                184M   12K  184M   1% /run/user/0
/dev/sr0             8.1G  8.1G     0 100% /run/media/root/CentOS 7 x86_64

现要将/home的15G空间全部扩给/目录
查看/home目录下是否有文件并备份。

[root@hisdb ~]# cd /home
[root@hisdb home]# ls
dm8_20210712_x86_rh6_64_ent  dmdba  oracle  soft  test.bak.sql  z
[root@hisdb home]# ls -al
total 16
drwxr-xr-x.  7 root   root      109 Feb 11  2022 .
dr-xr-xr-x. 20 root   root     4096 May 16  2022 ..
drwxr-xr-x   2 dmdba  oinstall  125 Aug 13  2021 dm8_20210712_x86_rh6_64_ent
drwx------   5 dmdba  dinstall  142 Feb 11  2022 dmdba
drwx------  19 oracle oinstall 4096 Sep  6  2023 oracle
drwxr-xr-x   3 oracle oinstall  131 Sep  7  2023 soft
-rw-r--r--   1 root   root     3070 Dec 30  2021 test.bak.sql
drwx------. 14 z      z        4096 Jul 13  2021 z
[root@hisdb home]# cd /
[root@hisdb /]# ls
1  backup  bin  boot  dev  etc  gauss  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  u01  usr  var
[root@hisdb /]# mkdir bak
[root@hisdb /]# cd home
[root@hisdb home]# cp * -rp /bak  --r表示目录下所有子目录也复制,p表进带权限复制。

卸载/home分区,把/home分区对应的lv删除。

[root@hisdb /]# umount -l /home    --加l是强制卸载,一般情况不需要加
[root@hisdb /]# 
[root@hisdb /]# lvremove /dev/cl/home   --移除lv,lv的名称可以通过lvdisplay查询
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM on /dev/sdb2 was already found on /dev/sda2.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM prefers device /dev/sda2 because device is used by LV.
Do you really want to remove active logical volume cl/home? [y/n]: y
  Logical volume "home" successfully removed
[root@hisdb /]# vgs    --可以查到空出空间。
  VG #PV #LV #SN Attr   VSize   VFree 
  cl   2   3   0 wz--n- <59.12g 15.00g


将空出来的空间扩给/

[root@hisdb /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   21G   12G  8.3G  60% /
devtmpfs             905M     0  905M   0% /dev
tmpfs                920M  458M  463M  50% /dev/shm
tmpfs                920M  8.8M  912M   1% /run
tmpfs                920M     0  920M   0% /sys/fs/cgroup
/dev/sdb1           1014M  173M  842M  18% /boot
/dev/mapper/cl-u01    20G   15G  5.4G  74% /u01
tmpfs                184M   16K  184M   1% /run/user/0
/dev/sr0             8.1G  8.1G     0 100% /run/media/root/CentOS 7 x86_64
[root@hisdb /]# lvresize -l +100%FREE /dev/mapper/cl-root
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM on /dev/sdb2 was already found on /dev/sda2.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM prefers device /dev/sda2 because device is used by LV.
  Size of logical volume cl/root changed from 20.12 GiB (5152 extents) to 35.12 GiB (8992 extents).
  Logical volume cl/root successfully resized.
[root@hisdb /]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root    isize=512    agcount=9, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5275648, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5275648 to 9207808
[root@hisdb /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   36G   12G   24G  34% /   --已经扩上去了
devtmpfs             905M     0  905M   0% /dev
tmpfs                920M  458M  463M  50% /dev/shm
tmpfs                920M  8.8M  912M   1% /run
tmpfs                920M     0  920M   0% /sys/fs/cgroup
/dev/sdb1           1014M  173M  842M  18% /boot
/dev/mapper/cl-u01    20G   15G  5.4G  74% /u01
tmpfs                184M   16K  184M   1% /run/user/0
/dev/sr0             8.1G  8.1G     0 100% /run/media/root/CentOS 7 x86_64


将备份文件拷贝回来

[root@hisdb /]# cd bak
[root@hisdb bak]# cp -rp * /home
[root@hisdb bak]# vi /etc/fsta
[root@hisdb bak]# lvs
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM on /dev/sdb2 was already found on /dev/sda2.
  WARNING: PV Ow5wuA-c6In-ykt6-iYBI-5LQd-mmSp-xzsboM prefers device /dev/sda2 because device is used by LV.
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root cl -wi-ao---- 35.12g                                                    
  swap cl -wi-ao----  4.00g                                                    
  u01  cl -wi-ao---- 19.99g                                                    
[root@hisdb bak]# vi /etc/fstab    --编辑fstab开机挂载文件,将/home目录挂载那行去掉


http://www.kler.cn/a/298823.html

相关文章:

  • 《Cocos Creator游戏实战》非固定摇杆实现原理
  • JAVAweb学习日记(三)Ajax
  • ffmpeg之播放一个yuv视频
  • Vue零基础必学教程(16) 计算属性
  • Dubbo简单总结
  • Spring AOP 中记录日志
  • 简要介绍联合索引
  • SprinBoot+Vue校园部门资料管理系统的设计与实现
  • Git操作和提交规范
  • 【算法专题--回文】最长回文子串 -- 高频面试题(图文详解,小白一看就懂!!)
  • 云曦2024秋季开学考
  • TeamTalk数据库代理服务器
  • SprinBoot+Vue智慧农业专家远程指导系统的设计与实现
  • 【自用21.】C++-this指针
  • pyflink的窗口
  • 5G网络建设
  • 【Kubernetes】常见面试题汇总(五)
  • Linux之ansible的playbook剧本(yaml文件)
  • 力扣题解2552
  • 开源的 Kafka 管理平台
  • C程序设计——再说说函数参数的值传递
  • 支持iPhone 16新品预售,饿了么同步上线专人配送等特色服务
  • 李诞-2021.8脱口秀工作手册-11-pitch your idea把一个想法扎进别人脑子里;专业,做足准备,给选择option!
  • 5.2 排列与代数余子式
  • 大模型实战一、Ollama+RagFlow 部署本地知识库
  • 三.海量数据实时分析-FlinkCDC实现Mysql数据同步到Doris