kgotobed 让你强制早睡

发布于 2023-02-17 12:46:07 字数 4099 浏览 68 评论 0

Kgotobed 是一个很变态的 Kernel Module。它会强制 linux 在特定时间关闭,而你却毫无办法(即使你是 root 用户)。

安装 Kgotobed

在 archlinux 上要安装 kgotobed,首先需要安装 dkmslinux 这两个包

sudo pacman -S dkms linux-headers --noconfirm

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

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

编译之

cd kgotobed/
sudo make install

安装命令会

  • 通过 DKMS 注册 kgotobed.ko
  • 安装 gotobed 命令到 /usr/local/bin
  • 在 systemd 中注册,启用,运行 kgotobed.service
[vagrant@archlinux ~]$ cd kgotobed/
[vagrant@archlinux kgotobed]$ sudo make install
dkms remove kgotobed/1.0 --all

------------------------------
Deleting module version: 1.0
completely from the DKMS tree.
------------------------------
Done.
dkms install module

Creating symlink /var/lib/dkms/kgotobed/1.0/source ->
                 /usr/src/kgotobed-1.0

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...........
make -j2 KERNELRELEASE=4.15.15-1-ARCH -C /usr/lib/modules/4.15.15-1-ARCH/build M=/var/lib/dkms/kgotobed/1.0/build..................
cleaning build area.......
Kernel cleanup unnecessary for this kernel.  Skipping...

DKMS: build completed.

kgotobed.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /usr/lib/modules/4.15.15-1-ARCH/extra//

depmod...........

DKMS: install completed.
cp gotobed /usr/local/bin
cp kgotobed.service /etc/systemd/system
systemctl daemon-reload
systemctl enable kgotobed.service
Created symlink /etc/systemd/system/multi-user.target.wants/kgotobed.service → /etc/systemd/system/kgotobed.service.
systemctl start kgotobed.service
[vagrant@archlinux kgotobed]$ 

使用 Kgotobed

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

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

可以看到默认的关机时间是凌晨一点,若你想临时调早一点关机时间可以 gotobed 新时间

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

不过你不能把时间调晚...

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

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

[vagrant@archlinux system]$ cat kgotobed.service 
[Unit]
Description=kgotobed: Poweroff at bedtime
After=dkms.service

[Service]
Type=oneshot
ExecStartPre=/sbin/modprobe kgotobed
Environment=TIME=01:00
ExecStart=/usr/local/bin/gotobed -f ${TIME}

[Install]
WantedBy=multi-user.target[vagrant@archlinux system]$ 

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 uninstall
dkms remove kgotobed/1.0 --all

-------- Uninstall Beginning --------
Module:  kgotobed
Version: 1.0
Kernel:  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.0
completely from the DKMS tree.
------------------------------
Done.
rm -f /usr/local/bin/gotobed
rm -f /etc/systemd/system/kgotobed.service
systemctl daemon-reload
[vagrant@archlinux kgotobed]$ 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

π浅易

暂无简介

文章
评论
27 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文