linux如何强制关机

57次阅读
没有评论

共计 2405 个字符,预计需要花费 7 分钟才能阅读完成。

自动写代码机器人,免费开通

这篇文章将为大家详细讲解有关 linux 如何强制关机,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

概念和术语

内核模块允许 Linux 内核在运行时动态地向其中插入和删除代码。这些模块是具有独立功能的程序,可以被单独编译,但无法独立运行。模块在运行时作为内核的一部分在内核空间内运行。

操作实战   场景一:使用 Kgotobed 强制关机难度★★★演示发行版 archlinux 涉及命令 gotobed 安装

在 archlinux 上要安装  kgotobed,首先需要安装  dkms  和  linux-headers  这两个包:

sudo pacman -S dkms linux-headers --noconfirm

然后去 github 上克隆它的源代码:

git clone https://github.com/nikital/kgotobed.git

最后我们对源代码进行手工编译:

cd kgotobed/sudo make install

make install  命令会完成以下三件事情:

鸿蒙官方战略合作共建——HarmonyOS 技术社区

通过 DKMS 注册  kgotobed.ko

安装  gotobed  命令到  /usr/local/bin  下

在 systemd 中注册、启用并运行  kgotobed.service

使用

直接运行  gotobed  就能看到设置的强行关机的时间:

[vagrant@archlinux kgotobed]$ gotobed 22:00Current bedtime is 2018-04-13 01:00:00Setting bedtime to 2018-04-12 22:00:00Bedtime will be in 10 hours 32 minutes

不过你不能把时间调到更晚 hellip; hellip;

[vagrant@archlinux kgotobed]$ gotobed 2:00Current bedtime is 2018-04-13 01:00:00Error: Attempting to postpone bed time, it doesn t work like this...

要想调整默认时间,你需要修改  /etc/systemd/system/kgotobed.service。

原始的  kgotobed.service  内容如下所示:

[Unit]Description=kgotobed: Poweroff at bedtimeAfter=dkms.service [Service]Type=oneshotExecStartPre=/sbin/modprobe kgotobedEnvironment=TIME=01:00ExecStart=/usr/local/bin/gotobed -f ${TIME} [Install]WantedBy=multi-user.target

我们将其中的  TIME=01:00  改成  TIME=02:00  后重启系统,再次执行  gotobed  可以看到时间已经修改了:

[vagrant@archlinux ~]$ gotobed Current bedtime is 2018-04-13 02:00:00

删除 kgotobed

要逃脱强制关机的命运,几乎唯一的办法就是卸载 kgotobed 了。

我们可以在源代码目录中执行  make uninstall  进行卸载:

[vagrant@archlinux ~]$ cd kgotobed/[vagrant@archlinux kgotobed]$ sudo make uninstalldkms remove kgotobed/1.0 --all -------- Uninstall Beginning --------Module: kgotobedVersion: 1.0Kernel: 4.15.15-1-ARCH (x86_64)------------------------------------- Status: Before uninstall, this module version was ACTIVE on this kernel. kgotobed.ko: - Uninstallation - Deleting from: /usr/lib/modules/4.15.15-1-ARCH/extra// - Original module - No original module was found for this module on this kernel. - Use the dkms install command to reinstall any previous module version. depmod........... DKMS: uninstall completed. ------------------------------Deleting module version: 1.0completely from the DKMS tree.------------------------------Done.rm -f /usr/local/bin/gotobedrm -f /etc/systemd/system/kgotobed.servicesystemctl daemon-reload[vagrant@archlinux kgotobed]$

关于“linux 如何强制关机”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向 AI 问一下细节

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-07发表,共计2405字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)