How to automatically shut down and boot up a linux system
Don’t be an energy waster. If your computers don't need to be on, turn them off. For convenience and for computer geeks, you can configure your Linux computer to automatically wake up and shut down.
Sometimes some computers need to be turned on all the time. This situation is allowed as long as the computer running time is not exceeded. Some people pride themselves on keeping their computers up and running for long periods of time, and now we have kernel hotfixes that only require a machine shutdown if a hardware failure occurs. What I think is more practical is to save power by reducing wear and tear on moving parts and shutting down the machine when it is not needed. For example, you can wake up the backup server at a specified time, perform the backup, and then shut it down until it is ready for the next backup. Alternatively, you can set up your Internet gateway to only run at specific times. Anything that doesn't need to be running all the time can be configured to turn on when it needs to work and turn off when it's done its job.
For computers that do not need to be running all the time, use root's cron scheduled task (i.e. /etc/crontab) to shut down the computer reliably. This example creates a root scheduled task to implement scheduled shutdown at 11:15 every night.
# crontab -e -u root # m h dom mon dow command 15 23 * * * /sbin/shutdown -h now
The following example only runs Monday through Friday:
15 23 * * 1-5 /sbin/shutdown -h now
You can create multiple cron jobs for different dates and times. All time and date fields can be understood through the command man 5 crontab.
A quick and easy way is to use the /etc/crontab file. But this way you have to specify the user:
15 23 * * 1-5 root shutdown -h now
Having automatic wakeup is a cool thing; most of my SUSE (SUSE Linux) colleagues are in Nuremberg, so in order to have a few hours of work time with colleagues, I have to wake up at 5 am. Get up. My computer automatically starts working at 5:30am and I just drag myself and my coffee to my desk and get started. Pressing the power button may not seem like a big deal, but at that time of day every little thing becomes a big deal.
Waking up a Linux computer may not be as reliable as shutting it down, so you may want to try a different approach. You can use remote wake-up (Wake-On-LAN), RTC wake-up, or a scheduled wake-up method set by the PC's BIOS. The reason these methods work is that when you turn off your computer, you don't actually turn it off; it's in a very low-power state and can still receive and respond to signals. It only turns off completely when you unplug the power switch.
BIOS wake-up is the most reliable. My system's motherboard BIOS has an easy-to-use wake scheduler (Figure 1). It's just as easy for you.
Figure 1: My system BIOS has an easy-to-use wake timer.
远程唤醒是仅次于 BIOS 唤醒的又一种可靠的唤醒方法。这需要你从第二台计算机发送信号到所要打开的计算机。可以使用 Arduino 或树莓派发送给基于 Linux 的路由器或者任何 Linux 计算机的唤醒信号。首先,查看系统主板 BIOS 是否支持 Wake-On-LAN ,要是支持的话,必须先启动它,因为它被默认为禁用。
然后,需要一个支持 Wake-On-LAN 的网卡;无线网卡并不支持。你需要运行 ethtool 命令查看网卡是否支持 Wake-On-LAN :
# ethtool eth0 | grep -i wake-on Supports Wake-on: pumbg Wake-on: g
这条命令输出的 “Supports Wake-on” 字段会告诉你你的网卡现在开启了哪些功能:
- d -- 禁用
- p -- 物理活动唤醒
- u -- 单播消息唤醒
- m -- 多播(组播)消息唤醒
- b -- 广播消息唤醒
- a -- ARP 唤醒
- g -- 特定数据包唤醒
- s -- 设有密码的特定数据包唤醒
ethtool 命令的 man 手册并没说清楚 p 选项的作用;这表明任何信号都会导致唤醒。然而,在我的测试中它并没有这么做。想要实现远程唤醒主机,必须支持的功能是 g —— 特定数据包唤醒,而且下面的“Wake-on” 行显示这个功能已经在启用了。如果它没有被启用,你可以通过 ethtool 命令来启用它。
# ethtool -s eth0 wol g
这条命令可能会在重启后失效,所以为了确保万无一失,你可以创建个 root 用户的定时任务(cron)在每次重启的时候来执行这条命令。
@reboot /usr/bin/ethtool -s eth0 wol g
另一个选择是最近的网络管理器版本有一个很好的小复选框来启用 Wake-On-LAN(图 2)。
图 2:启用 Wake on LAN
这里有一个可以用于设置密码的地方,但是如果你的网络接口不支持安全开机密码,它就不起作用。
现在你需要配置第二台计算机来发送唤醒信号。你并不需要 root 权限,所以你可以为你的普通用户创建 cron 任务。你需要用到的是想要唤醒的机器的网络接口和MAC地址信息。
30 08 * * * /usr/bin/wakeonlan D0:50:99:82:E7:2B
通过使用实时闹钟来唤醒计算机是最不可靠的方法。对于这个方法,可以参看 Wake Up Linux With an RTC Alarm Clock[1] ;对于现在的大多数发行版来说这种方法已经有点过时了。
下周继续了解更多关于使用 RTC 唤醒的方法。
通过 Linux 基金会和 edX 可以学习更多关于 Linux 的免费 Linux 入门[2]教程。
(题图:The Observatory at Delhi[3])
The above is the detailed content of How to automatically shut down and boot up a linux system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

CentOS installation steps: Download the ISO image and burn bootable media; boot and select the installation source; select the language and keyboard layout; configure the network; partition the hard disk; set the system clock; create the root user; select the software package; start the installation; restart and boot from the hard disk after the installation is completed.

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

CentOS hard disk mount is divided into the following steps: determine the hard disk device name (/dev/sdX); create a mount point (it is recommended to use /mnt/newdisk); execute the mount command (mount /dev/sdX1 /mnt/newdisk); edit the /etc/fstab file to add a permanent mount configuration; use the umount command to uninstall the device to ensure that no process uses the device.

After CentOS is stopped, users can take the following measures to deal with it: Select a compatible distribution: such as AlmaLinux, Rocky Linux, and CentOS Stream. Migrate to commercial distributions: such as Red Hat Enterprise Linux, Oracle Linux. Upgrade to CentOS 9 Stream: Rolling distribution, providing the latest technology. Select other Linux distributions: such as Ubuntu, Debian. Evaluate other options such as containers, virtual machines, or cloud platforms.
