刪除swap邏輯分區(qū)后無法開機(jī)及救援

關(guān)閉swap

fdisk -l 查看swap分區(qū)

[root@k8s-master ~]# fdisk -l

磁盤 /dev/sda:21.5 GB, 21474836480 字節(jié),41943040 個(gè)扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤標(biāo)簽類型:dos
磁盤標(biāo)識(shí)符:0x000c6458

   設(shè)備 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 字節(jié),35643392 個(gè)扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)


磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節(jié),4194304 個(gè)扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)

free -h 查看swap內(nèi)存

[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 臨時(shí)關(guān)閉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 分區(qū)

[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空間分配給其他分區(qū)

[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
文件系統(tǒng)                 容量  已用  可用 已用% 掛載點(diǎn)
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
文件系統(tǒng)                 容量  已用  可用 已用% 掛載點(diǎn)
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繼續(xù)加載swap,從而導(dǎo)致系統(tǒng)無法自動(dòng)啟動(dòng)并進(jìn)入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

進(jìn)入 dracut 后如何正常引導(dǎo)系統(tǒng)

image.png

命令:

  • lvm vgscan
  • lvm vgchange -ay // 激活所有文件系統(tǒng)
  • exit


    image.png

    等待進(jìn)入系統(tǒng)后,刪除 grub 所對(duì)應(yīng) swap 分區(qū)的位置即可

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容