前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7 将home空间分配给根目录(/dev/centos/root)

Centos7 将home空间分配给根目录(/dev/centos/root)

作者头像
IT小马哥
发布2024-09-29 21:05:34
1770
发布2024-09-29 21:05:34
举报
文章被收录于专栏:Java Tale
  • 在安装centos系统的时候,如果在安装时没有分配磁盘空间,选择的是默认分配的,在安装完成后,可以发现大容量磁盘往往分配在了home下面。
  • 在没有大量自定义用户使用的情况下,home的空间基本不用时,可以将空间转移至root下面。
查看目录结构
代码语言:javascript
复制
[root@mrf-server opt]# df -hl
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 7.7G     0  7.7G    0% /dev
tmpfs                    7.7G     0  7.7G    0% /dev/shm
tmpfs                    7.7G   18M  7.7G    1% /run
tmpfs                    7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G   39G   12G   78% /
/dev/sda2               1014M  176M  839M   18% /boot
/dev/sda1                200M   12M  189M    6% /boot/efi
/dev/mapper/centos-home  180G   33M  180G    1% /home
tmpfs                    1.6G     0  1.6G    0% /run/user/0
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
备份/home数据
代码语言:javascript
复制
[root@mrf-server opt]# mkdir /home-backup
[root@mrf-server opt]# 
[root@mrf-server opt]# mv /home/* /home-backup
删除/home逻辑卷
代码语言:javascript
复制
[root@mrf-server /]# umount /home
[root@mrf-server /]# 
[root@mrf-server /]# lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed 
查看可用大小
代码语言:javascript
复制
[root@mrf-server /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <237.28 GiB
  PE Size               4.00 MiB
  Total PE              60743
  Alloc PE / Size       14784 / 57.75 GiB
  Free  PE / Size       45959 / <179.53 GiB
  VG UUID               6zqmne-yIRi-DzR0-pOc7-pwHI-O1hM-Vh7T5c

根据:Free PE / Size 45959 / <179.53 GiB判断 可用空间为:179.53 GiB

新建/home卷
代码语言:javascript
复制
[root@mrf-server /]# lvcreate -L 50G -n home centos
WARNING: xfs signature detected on /dev/centos/home at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/centos/home.
  Logical volume "home" created.
查看/home卷
代码语言:javascript
复制
[root@mrf-server /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                PkUzOD-edvq-AYZH-RZte-nOOF-h27l-UDywl5
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-05-07 16:07:38 +0800
  LV Status              available
  # open                 2
  LV Size                7.75 GiB
  Current LE             1984
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                jpAxQq-GFzU-AfaT-Hotn-k6bG-FwII-a6EzIq
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-05-07 16:07:43 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                jMNrQ0-VpnG-FBry-wmrb-9oue-ALSZ-fuXYrd
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-05-08 09:38:46 +0800
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

分配50G空间成功

查看可用空间大小
代码语言:javascript
复制
[root@mrf-server /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <237.28 GiB
  PE Size               4.00 MiB
  Total PE              60743
  Alloc PE / Size       27584 / 107.75 GiB
  Free  PE / Size       33159 / <129.53 GiB
  VG UUID               6zqmne-yIRi-DzR0-pOc7-pwHI-O1hM-Vh7T5c

根据:Free PE / Size 33159 / <129.53 GiB判断 可用空间为129.53 GiB

/home上建立xfs文件系统
代码语言:javascript
复制
[root@mrf-server /]# mkfs -t xfs /dev/centos/home
Discarding blocks...Done.
meta-data=/dev/centos/home       isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=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 log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
挂载/home
代码语言:javascript
复制
[root@mrf-server /]# mount /dev/centos/home /home
[root@mrf-server /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 7.7G     0  7.7G    0% /dev
tmpfs                    7.7G     0  7.7G    0% /dev/shm
tmpfs                    7.7G   18M  7.7G    1% /run
tmpfs                    7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G   39G   12G   78% /
/dev/sda2               1014M  176M  839M   18% /boot
/dev/sda1                200M   12M  189M    6% /boot/efi
tmpfs                    1.6G     0  1.6G    0% /run/user/0
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay                   50G   39G   12G   78% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
/dev/mapper/centos-home   50G   33M   50G    1% /home
迁移home目录的备份数据
代码语言:javascript
复制
[root@mrf-server /]# mv /home-backup/* /home
[root@mrf-server /]# rm -rf /home-backup
将剩余的空间分配给根目录
代码语言:javascript
复制
[root@mrf-server /]#  lvextend -L +129G /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 179.00 GiB (45824 extents).
  Logical volume centos/root successfully resized.
[root@mrf-server /]# 
[root@mrf-server /]# 
[root@mrf-server /]# 
[root@mrf-server /]# 
[root@mrf-server /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                PkUzOD-edvq-AYZH-RZte-nOOF-h27l-UDywl5
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-05-07 16:07:38 +0800
  LV Status              available
  # open                 2
  LV Size                7.75 GiB
  Current LE             1984
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                jpAxQq-GFzU-AfaT-Hotn-k6bG-FwII-a6EzIq
  LV Write Access        read/write
  LV Creation host, time localhost, 2024-05-07 16:07:43 +0800
  LV Status              available
  # open                 1
  LV Size                179.00 GiB
  Current LE             45824
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                jMNrQ0-VpnG-FBry-wmrb-9oue-ALSZ-fuXYrd
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-05-08 09:38:46 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
扩展根目录
代码语言:javascript
复制
[root@mrf-server /]# xfs_growfs /dev/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 46923776
[root@mrf-server /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 7.7G     0  7.7G    0% /dev
tmpfs                    7.7G     0  7.7G    0% /dev/shm
tmpfs                    7.7G   18M  7.7G    1% /run
tmpfs                    7.7G     0  7.7G    0% /sys/fs/cgroup
/dev/mapper/centos-root  179G   39G  141G   22% /
/dev/sda2               1014M  176M  839M   18% /boot
/dev/sda1                200M   12M  189M    6% /boot/efi
tmpfs                    1.6G     0  1.6G    0% /run/user/0
overlay                  179G   39G  141G   22% /var/lib/docker/overlay2/b13ed87897fe1cabe547341e9a855c43bf04fcf7f3ef44e41138b08e62fb6191/merged
overlay                  179G   39G  141G   22% /var/lib/docker/overlay2/502140d31ceae249f65f90e2fc096af6d8cece5f086ab9ce7e01ff80ec82576d/merged
overlay                  179G   39G  141G   22% /var/lib/docker/overlay2/b8bfb2a4f4360f9b3915452fb4303d5ebf02299bee754de9d7245b5efc0d8149/merged
overlay                  179G   39G  141G   22% /var/lib/docker/overlay2/59d0f795fa7c6d89467ada62d8e9e1cd8b9ad5628ca251bb5c9011fbed513af1/merged
overlay                  179G   39G  141G   22% /var/lib/docker/overlay2/b7ed9b03a812579f993ac7dbe086afb15401ec5109af9467a5efbbc524f74b79/merged
/dev/mapper/centos-home   50G   33M   50G    1% /home

本文由 小马哥 创作,采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-09-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 查看目录结构
  • 备份/home数据
  • 删除/home逻辑卷
  • 查看可用大小
  • 新建/home卷
  • 查看/home卷
  • 查看可用空间大小
  • /home上建立xfs文件系统
  • 挂载/home
  • 迁移home目录的备份数据
  • 将剩余的空间分配给根目录
  • 扩展根目录
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档