美文网首页
删除swap逻辑分区后无法开机及救援

删除swap逻辑分区后无法开机及救援

作者: 天天向上_ac78 | 来源:发表于2019-02-28 11:06 被阅读0次

关闭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 分区的位置即可

相关文章

  • 删除swap逻辑分区后无法开机及救援

    关闭swap fdisk -l 查看swap分区 free -h 查看swap内存 swapoff -a 临时...

  • /dev/centos/swap does not exist

    在centos/rhel上部署k8s时,安装系统时有swap分区,后期部署环境时候关闭了swap分区,手动删除/d...

  • Linux基础学习十一(下)

    三:swap分区 1.free:显示系统中空闲的,已用的物理内存及swap,buffer内存 -m 创建交换分区...

  • Linux59期day03

    什么是救援模式? 解决故障 root密码忘记\服务器无法开机 linux磁盘分区方案 1.通用-数据不重要的时候...

  • 硬盘分区

    开始分区 n p 删除分区 d 添加扩展分区 n e (逻辑分区) 有了扩展分区才能添加逻辑分区 l和...

  • LINUX新建和增加SWAP分区

    我们都知道在安装Linux系统时在分区时可以分配swap分区,而系统安装后(在运行中)如何建立或调整swap分区呢...

  • 添加swap分区

    我们都知道在安装Linux系统时在分区时可以分配swap分区,而系统安装后(在运行中)如何建立或调整swap分区呢...

  • swap分区,磁盘和文件两种方法。

    我们都知道在安装Linux系统时在分区时可以分配swap分区,而系统安装后(在运行中)如何建立或调整swap分区呢...

  • Deepin休眠

    系统休眠,可以让平时的工作环境保存到硬盘中,以便开机后便可立即进入工作状态. 提醒:分有swap分区的,先验证休眠...

  • Android 8.1下内置存储sdcard无法挂载

    平台: Rockchip 3399Android 8.1 问题: 开机后,内置/sdcard分区不可访问,无法挂载...

网友评论

      本文标题:删除swap逻辑分区后无法开机及救援

      本文链接:https://www.haomeiwen.com/subject/coocuqtx.html