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
相关推荐
Karoku06633 分钟前
【企业级分布式系统】Zabbix监控系统与部署安装
运维·服务器·数据库·redis·mysql·zabbix
为什么这亚子36 分钟前
九、Go语言快速入门之map
运维·开发语言·后端·算法·云原生·golang·云计算
布值倒区什么name1 小时前
bug日常记录responded with a status of 413 (Request Entity Too Large)
运维·服务器·bug
。puppy2 小时前
HCIP--3实验- 链路聚合,VLAN间通讯,Super VLAN,MSTP,VRRPip配置,OSPF(静态路由,环回,缺省,空接口),NAT
运维·服务器
颇有几分姿色2 小时前
深入理解 Linux 内存管理:free 命令详解
linux·运维·服务器
光芒再现dev2 小时前
已解决,部署GPTSoVITS报错‘AsyncRequest‘ object has no attribute ‘_json_response_data‘
运维·python·gpt·语言模型·自然语言处理
AndyFrank2 小时前
mac crontab 不能使用问题简记
linux·运维·macos
成都古河云3 小时前
智慧场馆:安全、节能与智能化管理的未来
大数据·运维·人工智能·安全·智慧城市
算法与编程之美3 小时前
文件的写入与读取
linux·运维·服务器
Amelio_Ming4 小时前
Permissions 0755 for ‘/etc/ssh/ssh_host_rsa_key‘ are too open.问题解决
linux·运维·ssh