linux如何強制關(guān)機

這篇文章將為大家詳細講解有關(guān)linux如何強制關(guān)機,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

站在用戶的角度思考問題,與客戶深入溝通,找到上蔡網(wǎng)站設(shè)計與上蔡網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋上蔡地區(qū)。

概念和術(shù)語

內(nèi)核模塊允許 Linux 內(nèi)核在運行時動態(tài)地向其中插入和刪除代碼。這些模塊是具有獨立功能的程序,可以被單獨編譯,但無法獨立運行。模塊在運行時作為內(nèi)核的一部分在內(nèi)核空間內(nèi)運行。

操作實戰(zhàn) 

場景一:使用 Kgotobed 強制關(guān)機
難度★★★
演示發(fā)行版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 命令會完成以下三件事情:

  1. 鴻蒙官方戰(zhàn)略合作共建——HarmonyOS技術(shù)社區(qū)

  2. 通過 DKMS 注冊 kgotobed.ko

  3. 安裝 gotobed 命令到 /usr/local/bin 下

  4. 在 systemd 中注冊、啟用并運行 kgotobed.service

使用

直接運行 gotobed 就能看到設(shè)置的強行關(guān)機的時間:

[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

不過你不能把時間調(diào)到更晚……

[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...

要想調(diào)整默認時間,你需要修改 /etc/systemd/system/kgotobed.service

原始的 kgotobed.service 內(nèi)容如下所示:

[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 后重啟系統(tǒng),再次執(zhí)行 gotobed 可以看到時間已經(jīng)修改了:

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

要逃脫強制關(guān)機的命運,幾乎唯一的辦法就是卸載 kgotobed 了。

我們可以在源代碼目錄中執(zhí)行 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]$

關(guān)于“l(fā)inux如何強制關(guān)機”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

當前題目:linux如何強制關(guān)機
地址分享:http://muchs.cn/article48/gphchp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、品牌網(wǎng)站制作外貿(mào)建站、自適應網(wǎng)站、品牌網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化