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

1、查看目录结构

javascript 复制代码
[root@localhost 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

2、备份/home数据

javascript 复制代码
[root@localhost opt]# mkdir /home-backup
[root@localhost opt]# 
[root@localhost opt]# mv /home/* /home-backup

3、删除/home逻辑卷

javascript 复制代码
[root@localhost /]# umount /home
[root@localhost /]# 
[root@localhost /]# lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed

4、查看可用空间大小

javascript 复制代码
[root@localhost /]# 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

5、新建/home卷

javascript 复制代码
[root@localhost /]# 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.

6、查看/home卷

javascript 复制代码
[root@localhost /]# 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空间成功

7、查看可用空间大小

javascript 复制代码
[root@localhost /]# 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

8、/home上建立xfs文件系统

javascript 复制代码
[root@localhost /]# 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

9、挂载/home

javascript 复制代码
[root@localhost /]# mount /dev/centos/home /home
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 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

10、迁移home目录的备份数据

javascript 复制代码
[root@localhost /]# mv /home-backup/* /home
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# rm -rf /home-backup

11、将剩余的空间129.53 GiB分配给根目录(/dev/centos/root)

javascript 复制代码
[root@localhost /]#  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@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 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

12、扩展根目录(/dev/centos/root)

javascript 复制代码
[root@localhost /]# 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@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 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
相关推荐
虾稿8 分钟前
[手机Linux] 七,NextCloud优化设置
linux·运维·服务器
首发运维10 分钟前
centos 释放系统预留内存并关闭Kdump服务
linux·运维·centos·linux操作系统问题
稳重的大王16 分钟前
威联通NAS部署openwrt软路由保姆级教程附镜像文件
运维·服务器
ascarl201018 分钟前
【Nginx系列】---Nginx配置tcp转发
运维·tcp/ip·nginx
新子-存在了19 分钟前
linux中 mysql备份
linux·运维·mysql
ZHOUPUYU21 分钟前
VMware虚拟机超详细安装Linux教程(最新版)
linux·运维·服务器·windows·微软·centos·虚拟机
成都渲染101云渲染666628 分钟前
云渲染,Enscape、D5、Lumion渲染提速教程
运维·服务器·unity·电脑·图形渲染·blender·houdini
初级代码游戏32 分钟前
关于linux的ld.so.conf.d
linux·运维·服务器
m0_7482323943 分钟前
在Linux centos7环境下部署wblogic使用weblogic部署war包项目
linux·运维·服务器
handsomestWei1 小时前
Nginx整合Lua脚本
运维·nginx·lua