关闭swap
fdisk -l 查看swap分区
[root@k8s-master ~]# fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c6458
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
free -h 查看swap内存
[root@k8s-master ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 79M 1.7G 8.7M 119M 1.7G
Swap: 2.0G 0B 2.0G
swapoff -a 临时关闭swap
swapon /dev/mapper/centos-swap 开启swap
[root@k8s-master ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 78M 1.7G 8.7M 118M 1.7G
Swap: 0B 0B 0B
[root@k8s-master ~]# swapon /dev/mapper/centos-swap
[root@k8s-master ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 79M 1.7G 8.7M 119M 1.7G
Swap: 2.0G 0B 2.0G
vim /etc/fstab 注释掉swap
[root@k8s-master ~]# cat /etc/fstab
/dev/mapper/centos-root / xfs defaults 0 0
UUID=4c8100b5-3087-4845-98bf-f579c6a22b9d /boot xfs defaults 0 0
#/dev/mapper/centos-swap swap swap defaults 0 0
lvremove /dev/mapper/centos-swap 删除 swap 分区
[root@k8s-master ~]# swapoff -a
[root@k8s-master ~]# lvremove /dev/mapper/centos-swap
Do you really want to remove active logical volume centos/swap? [y/n]: y
Logical volume "swap" successfully removed
把swap的2G空间分配给其他分区
[root@k8s-master ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 1 0 wz--n- <19.00g 2.00g
[root@k8s-master ~]# lvextend -l +100%free /dev/mapper/centos-root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <19.00 GiB (4863 extents).
Logical volume centos/root successfully resized.
[root@k8s-master ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 1 0 wz--n- <19.00g 0
[root@k8s-master ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 972M 0 972M 0% /dev
tmpfs 985M 0 985M 0% /dev/shm
tmpfs 985M 8.7M 976M 1% /run
tmpfs 985M 0 985M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.4G 16G 8% /
/dev/sda1 1014M 134M 881M 14% /boot
tmpfs 197M 0 197M 0% /run/user/0
[root@k8s-master ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 4979712
[root@k8s-master ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 972M 0 972M 0% /dev
tmpfs 985M 0 985M 0% /dev/shm
tmpfs 985M 8.7M 976M 1% /run
tmpfs 985M 0 985M 0% /sys/fs/cgroup
/dev/mapper/centos-root 19G 1.4G 18G 8% /
/dev/sda1 1014M 134M 881M 14% /boot
tmpfs 197M 0 197M 0% /run/user/0
删除后,需要更新下/boot/grub2/grub.conf配置文件,防止重启后kernel继续加载swap,从而导致系统无法自动启动并进入dracut模式
- 删除/etc/default/grub中是swap信息rd.lvm.lv=centos/swap
[root@k8s-master ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
- 更新下/boot/grub2/grub.conf配置文件
[root@k8s-master ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.20.5-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.20.5-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-153f6a59c6f241029b2d108a010aee3a
Found initrd image: /boot/initramfs-0-rescue-153f6a59c6f241029b2d108a010aee3a.img
done
进入 dracut 后如何正常引导系统
image.png命令:
- lvm vgscan
- lvm vgchange -ay // 激活所有文件系统
-
exit
image.png
等待进入系统后,删除 grub 所对应 swap 分区的位置即可
网友评论