search
HomeSystem TutorialLINUXHow to automatically shut down and boot up a linux system

How to automatically shut down and boot up a linux system

Mar 01, 2024 am 08:00 AM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

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.

Valuable system running time

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.

System Hibernation

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
Automatic wake-up

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 wakeup

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.

linux 系统如何自动关机和开机

Figure 1: My system BIOS has an easy-to-use wake timer.

Host remote wake-up (Wake-On-LAN)

远程唤醒是仅次于 BIOS 唤醒的又一种可靠的唤醒方法。这需要你从第二台计算机发送信号到所要打开的计算机。可以使用 Arduino 或树莓派Raspberry Pi发送给基于 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 -- 特定数据包magic packet唤醒
  • s -- 设有密码的特定数据包magic packet唤醒

ethtool 命令的 man 手册并没说清楚 p 选项的作用;这表明任何信号都会导致唤醒。然而,在我的测试中它并没有这么做。想要实现远程唤醒主机,必须支持的功能是 g —— 特定数据包magic packet唤醒,而且下面的“Wake-on” 行显示这个功能已经在启用了。如果它没有被启用,你可以通过 ethtool 命令来启用它。

# ethtool -s eth0 wol g

这条命令可能会在重启后失效,所以为了确保万无一失,你可以创建个 root 用户的定时任务(cron)在每次重启的时候来执行这条命令。

@reboot /usr/bin/ethtool -s eth0 wol g

另一个选择是最近的网络管理器Network Manager版本有一个很好的小复选框来启用 Wake-On-LAN(图 2)。

linux 系统如何自动关机和开机

图 2:启用 Wake on LAN

这里有一个可以用于设置密码的地方,但是如果你的网络接口不支持安全开机Secure On密码,它就不起作用。

现在你需要配置第二台计算机来发送唤醒信号。你并不需要 root 权限,所以你可以为你的普通用户创建 cron 任务。你需要用到的是想要唤醒的机器的网络接口和MAC地址信息。

30 08 * * * /usr/bin/wakeonlan D0:50:99:82:E7:2B 
RTC 唤醒

通过使用实时闹钟来唤醒计算机是最不可靠的方法。对于这个方法,可以参看 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!

Statement
This article is reproduced at:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
What is the main purpose of Linux?What is the main purpose of Linux?Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Does the internet run on Linux?Does the internet run on Linux?Apr 14, 2025 am 12:03 AM

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

What are Linux operations?What are Linux operations?Apr 13, 2025 am 12:20 AM

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Boost Productivity with Custom Command Shortcuts Using Linux AliasesBoost Productivity with Custom Command Shortcuts Using Linux AliasesApr 12, 2025 am 11:43 AM

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

What is Linux actually good for?What is Linux actually good for?Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

Essential Tools and Frameworks for Mastering Ethical Hacking on LinuxEssential Tools and Frameworks for Mastering Ethical Hacking on LinuxApr 11, 2025 am 09:11 AM

Introduction: Securing the Digital Frontier with Linux-Based Ethical Hacking In our increasingly interconnected world, cybersecurity is paramount. Ethical hacking and penetration testing are vital for proactively identifying and mitigating vulnerabi

How to learn Linux basics?How to learn Linux basics?Apr 10, 2025 am 09:32 AM

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

What is the most use of Linux?What is the most use of Linux?Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool