CentOS7从默认/home中转移空间到根分区/
2021/7/31 7:08:06
本文主要是介绍CentOS7从默认/home中转移空间到根分区/,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、操作步骤
1. 备份/home中的用户数据
[root@localhost /]# mkdir /backup && mv /home/* /backup
[root@localhost /]# ls /home/
2. 卸载这个/home并删除逻辑卷home
# umount /home
# df -h //查看磁盘情况
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 50G 17G 34G 33% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 84K 3.9G 1% /dev/shm
- tmpfs 3.9G 9.0M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 494M 133M 362M 27% /boot
# lvremove /dev/centos/home //删除逻辑卷home
- Do you really want to remove active logical volume home? [y/n]: y
- Logical volume "home" successfully removed
# vgdisplay //查看卷组可用空间
- --- Volume group ---
- VG Name centos
- System ID
- Format lvm2
- Metadata Areas 1
- Metadata Sequence No 7
- 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 931.02 GiB
- PE Size 4.00 MiB
- Total PE 238341
- Alloc PE / Size 14784 / 57.75 GiB
- Free PE / Size 223557 / 873.27 GiB
- VG UUID IFQnYm-fCLh-38mD-Duid-nYXQ-qktX-3F1atk
这里注意,Free PE / Size 中显示的空间为卷组的空闲空间873G,之前为64M,也就是刚才删除的逻辑卷home所占用的空间,我们就从这个当中拿出一部分比如50G作为home
3. 新建一个卷home,fdisk格式化为8e格式,文件系统还是搞为xfs(同样挂载到/home)
# lvcreate -L 50G -n home centos //L表示大小,默认单位为M;n表示卷名;这里的centos是CentOS7安装系统的时候就默认建立好的卷组名
- 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.
# lvdisplay //查看逻辑卷home
- --- Logical volume ---
- LV Path /dev/centos/home
- LV Name home
- VG Name centos
- LV UUID b5lLlv-FQPY-dT43-SmzV-sSLA-4QqP-gdQqAP
- LV Write Access read/write
- LV Creation host, time localhost, 2015-11-13 14:05:06 +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
# vgdisplay //再次查看卷组空间大小
- --- Volume group ---
- VG Name centos
- System ID
- Format lvm2
- Metadata Areas 1
- Metadata Sequence No 8
- 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 931.02 GiB
- PE Size 4.00 MiB
- Total PE 238341
- Alloc PE / Size 27584 / 107.75 GiB
- Free PE / Size 210757 / 823.27 GiB
- VG UUID IFQnYm-fCLh-38mD-Duid-nYXQ-qktX-3F1atk
[# vgchange -ay centos //可选步骤:激活卷组centos,使得这个新建的home逻辑卷生效(用vgchange而不用lvchange)]
- 3 logical volume(s) in volume group "centos" now active
# mkfs -t xfs /dev/centos/home //在新建的逻辑卷home上建立xfs文件系统
- meta-data=/dev/centos/home isize=256 agcount=4, agsize=3276800 blks
- = sectsz=4096 attr=2, projid32bit=1
- = crc=0 finobt=0
- data = bsize=4096 blocks=13107200, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0 ftype=0
- log =internal log bsize=4096 blocks=6400, version=2
- = sectsz=4096 sunit=1 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
# mount /dev/centos/home /home/ //把这个新逻辑卷home挂到之前的文件夹/home中去,直接重启用fstab来挂载也行
# df -h //现在来查看磁盘使用情况
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 50G 17G 34G 33% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 84K 3.9G 1% /dev/shm
- tmpfs 3.9G 9.0M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 494M 133M 362M 27% /boot
- /dev/mapper/centos-home 50G 33M 50G 1% /home
# mv /backup/* /home/ //再把之前拷出来的东西拷回新建的/home中,拷贝完成就可以直接用这个普通用户来桌面登录系统了,不用重启
4. 最后再把释放出来多余的空间分配给root卷并xfs_growfs扩展文件系统
# lvextend -L +823G /dev/centos/root //把剩下的823G现在分配给root卷,剩下那点渣渣空间让它闲着;+号表示在原来的基础上额外增加,不要加好则设定为具体额度
- Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 873.00 GiB (223488 extents).
- Logical volume root successfully resized
# lvdisplay //查看逻辑卷和卷组情况,这下root的空间就多达到873G,之前的是50G
- --- Logical volume ---
- LV Path /dev/centos/root
- LV Name root
- VG Name centos
- LV UUID PgscNL-rvyY-21Z1-tVe3-80vC-ONCw-VlvmYs
- LV Write Access read/write
- LV Creation host, time localhost, 2015-11-11 04:46:04 +0800
- LV Status available
- # open 1
- LV Size 873.00 GiB
- Current LE 223488
- Segments 2
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:0
[# vgchange -ay centos //可选步骤:再次激活下卷组centos]
# df -h //不使用xfs_growfs扩展文件系统,磁盘是不认得多的空间的
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 50G 4.8G 46G 10% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 140K 3.9G 1% /dev/shm
- tmpfs 3.9G 9.0M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 494M 133M 362M 27% /boot
- /dev/mapper/centos-home 50G 12G 39G 23% /home
# xfs_growfs /dev/centos/root //扩展root卷
- meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800 blks
- = sectsz=4096 attr=2, projid32bit=1
- = crc=0 finobt=0
- data = bsize=4096 blocks=13107200, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0 ftype=0
- log =internal bsize=4096 blocks=6400, version=2
- = sectsz=4096 sunit=1 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- data blocks changed from 13107200 to 228851712
# df -h //再看root大小已经生效,800多G了
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 873G 4.8G 869G 1% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 140K 3.9G 1% /dev/shm
- tmpfs 3.9G 9.0M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 494M 133M 362M 27% /boot
- /dev/mapper/centos-home 50G 12G 39G 23% /home
二、命令汇总
简单总结下,就是下面几条命令:
- # mkdir /backup
- # mv /home/* /backup/
- # umount /home
- # lvremove /dev/centos/home
- # lvcreate -L 50G -n home cents
- # mkfs -t xfs /dev/centos/home
- # mv /backup/* /home/
- # lvextend -L +xxxG /dev/centos/root
- # xfs_growfs root
- # rm -rf /backup
这篇关于CentOS7从默认/home中转移空间到根分区/的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-18uniapp 怎么定义对象属性?-icode9专业技术文章分享
- 2024-11-18克罗内克积是什么?-icode9专业技术文章分享
- 2024-11-18uniapp怎么实现点击防抖和节流功能?-icode9专业技术文章分享
- 2024-11-18uniapp实现全局的监听和接收有哪些方法?-icode9专业技术文章分享
- 2024-11-18TCPDF与mpdf的区别与优势是什么?-icode9专业技术文章分享
- 2024-11-17getExternalFilesDir这个方法哪些安卓版本可以使用?-icode9专业技术文章分享
- 2024-11-17app下载好后,安装包更新代码怎么写?-icode9专业技术文章分享
- 2024-11-17login-customer-id 如何获取?-icode9专业技术文章分享
- 2024-11-17使用 vite加载.env 文件环境变量无法加载是什么原因?-icode9专业技术文章分享
- 2024-11-17tp钱包是什么,有哪些功能?-icode9专业技术文章分享