帮助中心
物理服务器后台安装系统前可以自定义分区,没有数据的建议直接重装时分区
举例把/home删除,剩余空间扩容到 /
生产中的服务器操作有风险,请谨慎操作,本教程不对任何数据丢失负责
[root@localhost ~]# df -h #查看分区情况,准备卸载/home和删除/home所在的lv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 3.8G 47G 8% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 18M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 178M 837M 18% /boot
/dev/mapper/centos-home 245G 33M 245G 1% /home
tmpfs 379M 0 379M 0% /run/user/0
[root@localhost ~]# fdisk -l #查看磁盘lv名称
Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000ed6dc
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 629145599 313523200 8e Linux LVM
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/centos-home: 263.2 GB, 263192576000 bytes, 514048000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
[root@localhost ~]# umount /home #卸载/home
[root@localhost ~]# lvremove /dev/mapper/centos-home # 删除/home所在lv
Do you really want to remove active logical volume centos/home? [y/n]: y #输入y回车
Logical volume "home" successfully removed
[root@localhost ~]# lvextend -r -l +100%FREE /dev/mapper/centos-root #剩余容量全部分到 / ,回车后操作完成
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 2 95.12 GiB (75551 extents).
Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=4096 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 77364224
[root@localhost ~]# df -h # 根目录现在已经扩容完成
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 296G 3.8G 292G 2% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 18M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 178M 837M 18% /boot
tmpfs 379M 0 379M 0% /run/user/0
[root@localhost ~]# vi /etc/fstab # 需要编辑此文件,删除/home分区挂载,不然重启后会无法开机
# /etc/fstab
# Created by anaconda on Sat Mar 7 06:19:07 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=c02c8818-6a16-49df-a6f2-89e377303b9c /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0 # 删除这一行保存退出
/dev/mapper/centos-swap swap swap defaults 0 0
- 317 用户发现这个很有用