centos8 磁盘根分区扩容
0、查看使用情况 df -h
[root@host-work03 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 12G 105M 12G 1% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/mapper/cl-root 13G 13G 20K 100% /
/dev/sda2 976M 140M 770M 16% /boot
/dev/sdb1 196G 5.6G 181G 3% /data
/dev/sda1 599M 6.8M 593M 2% /boot/efi
tmpfs 2.4G 0 2.4G 0% /run/user/0
我们可以看到 上面的根目录已经满了
1、 查看磁盘 fdisk -l
发现我们磁盘是40G 但是分区才使用了16G(虚拟机系统安装后扩容了磁盘)
GPT PMBR size mismatch (33554431 != 83886079) will be corrected by write.
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DC841ABE-5DF6-4A14-9450-D23BD9064EE0
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 33552383 30224384 14.4G Linux LVM
Disk /dev/sdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xef33e1e1
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 419430399 419428352 200G 83 Linux
Disk /dev/mapper/cl-root: 12.8 GiB, 13753122816 bytes, 26861568 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-swap: 1.6 GiB, 1719664640 bytes, 3358720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
2、创建新的磁盘分区 fdisk /dev/sda
依次输入的指令如下参数
n(添加分区)
p(主分区)
数字 (分区号 可默认 一般在现有基础上+1)
默认(第一个扇区)
默认(上个扇区)
w(写入)
3、再次查看磁盘 fdisk -l
可以看到 sda4 为我们新分区出来的
[root@host-work03 pods]# fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DC841ABE-5DF6-4A14-9450-D23BD9064EE0
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 33552383 30224384 14.4G Linux LVM
/dev/sda4 33552384 83886046 50333663 24G Linux filesystem
Disk /dev/sdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xef33e1e1
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 419430399 419428352 200G 83 Linux
Disk /dev/mapper/cl-root: 12.8 GiB, 13753122816 bytes, 26861568 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-swap: 1.6 GiB, 1719664640 bytes, 3358720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
4、将分区初始化为物理卷 pvcreate /dev/sda4
[root@host-work03 pods]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
5、查看之前分区挂载的vg Name pvdisplay
[root@host-work03 pods]# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name cl
PV Size 14.41 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 3689
Free PE 0
Allocated PE 3689
PV UUID hsCwoG-zuyP-o5yz-2hWW-tQgC-3bAV-bN0stA
"/dev/sda4" is a new physical volume of "24.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda4
VG Name
PV Size 24.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID l3Nu3D-Z3ug-9hSx-Xfcu-DtRf-YVMz-J0owK4
6、将新的分区添加给vg vgextend cl /dev/sda4
7、给根分区添加磁空间
[root@host-work03 pods]# lvextend -L +20G /dev/cl/root Size of logical volume cl/root changed from <12.81 GiB (3279 extents) to <32.81 GiB (8399 extents). Logical volume cl/root successfully resized.
8、再次查看使用情况 df -h
[root@host-work03 pods]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 12G 2.7M 12G 1% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/mapper/cl-root 33G 19G 14G 58% /
/dev/sda2 976M 140M 770M 16% /boot
/dev/sdb1 196G 5.8G 181G 4% /data
/dev/sda1 599M 6.8M 593M 2% /boot/efi
tmpfs 2.4G 0 2.4G 0% /run/user/0
可以看到 根目录已经加上了我们添加的20G
写在后面
根分区写满的原因是kubelet目录的文件
最终解决方案是将kueblet迁移到其磁盘下面 参考文档 https://blog.csdn.net/zhangjunli/article/details/108606226 ps:docker的目录也要做迁移