物理服務器后臺安裝系統前可以自定義分區,沒有數據的建議直接重裝時分區
舉例把/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