Disable Linux server through serial port

Source: Internet
Author: User
Article Title: Disable Linux server through serial port. Linux is a technology channel of the IT lab in China. Basic categories including desktop applications, Linux system management, kernel research, embedded systems, and open source
A Real Server generally does not need to be connected to peripherals such as a keyboard, display, or mouse. Instead, you only need a stable operating system such as Linux and a nic. External devices, such as the mouse and keyboard, do not need to be connected. Remote Management over the network is the best and most convenient solution for Linux machines.
When buying a server, make sure that the BIOS has settings that do not require keyboard detection. Most motherboard manufacturers currently have this option for their BIOS versions. However, some boards still think that their servers will only run windows, so a keyboard is required at startup. Therefore, we do not recommend using such machines as servers.
Computers without keyboards and monitors are very suitable for the concept of firewalls, web servers, NFS servers, email servers, ADSL gateways, and DNS servers. In addition, this machine is not necessarily a very powerful machine. Even if an old Pentimu100 machine has enough memory, it can serve hundreds of customer service requests at the same time.
The advantage of not connecting the keyboard, mouse, and display on the server is very convenient, because the server will be a simple portable box that can be placed in any suitable place. However, sometimes you may want to have a key to safely shut down the server, instead of remotely logging on to the server and running the shutdown command to shut down the server. You may also be in the server room now, and the nearest workstation is more than 100 metres away from you; or you want a common user without a root password to shut down the server. Of course, directly power off is not a good idea, because this may lead to data loss and requires a long time for file system detection at the next startup.
The solution is to install a small and inexpensive serial port device according to the method described in this article to achieve safe shutdown.
Device
We will create a small device consisting of two LEDs and a key switch. The green LED light indicates that the current key-based switch is active, and the Slow blinking yellow LED light indicates that the server is starting or still off. To safely shut down the server, you need to press the switch for three seconds.
If you press the button, the highlighted green LED will go off, indicating that it is shutting down. The command "/sbin/shutdown-t2-h now" is executed. When the server is turned off, the yellow LED will flash continuously for indication. When the yellow LED does not flash, you still need to wait 10 seconds to turn off the server power. When all processes are killed, the yellow LED will not flash after the disk is detached. If your server supports automatic shutdown, you do not need to consider the waiting time of 10 seconds, because the server will automatically turn off the power.
Serial Port
What is interesting about the serial port is that we can control several pins by calling the ioctl system. This means that you do not need to modify any kernel code to control the LEDs connected to the serial port or read the status of the key-based switch. The serial port has enough voltage to drive two low-voltage LEDs. We will connect the LED Using the RTS and DTR pins, and "Carrier Detect line" is used to read the status of the button switch.
Pin definition of the serial port connector:
9 PIN-connector 25 PIN-connector Name Dir Description
1 8 CD input Carrier Detect
2 3 RXD input Receive Data
3 2 TXD output Transmit Data
4 20 DTR output Data Terminal Ready
5 7 GND -- System Ground
6 6. DSR input Data Set Ready
7 4 RTS output Request to Send
8 5 CTS input Clear to Send
9 22 RI input Ring Indicator
Circuit
You need the following components to create a serial shutdown device:
1 green low-voltage LED (a common LED can also work, but the light is too low)
1 yellow low-voltage LED
2 K ohm resistance
1 6.8K ohm resistance
1 small button switch
1. Serial Port Connector
These components are connected according to the following circuit diagram. The serial port voltage range is +/-10 volts. K resistor is suitable for low-voltage LEDs, but ordinary LEDs are also suitable. It is not recommended to modify the resistor voltage and use external power, because the serial port control chip is part of the motherboard. Once you burn the chip, you only need to modify the entire motherboard.
Is the actual PCB sample diagram. The final device is shown in the picture at the beginning of the article.
Software
The software part is a small daemon process. It can be started through the/etc/rc. d/rc3.d/script. It uses ioctl (fd, TIOCMSET ,...) And ioctl (fd, TIOCMGET ,...) Function to read and write the serial port. You can download the program from here. The software contains a Makefile and installation instructions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.