免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1751 | 回复: 4
打印 上一主题 下一主题

[OpenBSD] OpenBSD如何把串口作为一个控制终端? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-15 11:03 |只看该作者 |倒序浏览
如题

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2005-11-15 11:07 |只看该作者
http://www.openbsd.org/faq/faq7.html#SerCon

7.7 - How do I use a serial console?
There are many reasons you may wish to use a serial console for your OpenBSD system:

    * Recording console output (for documentation).
    * Remote management.
    * Easier maintenance of a large quantity of machines
    * Providing a useful dmesg from machines which might otherwise be difficult to get one from.
    * Providing an accurate "trace" and "ps" output if your system crashes so developers can have a chance to fix the problem.

OpenBSD supports serial console on most platforms, however details vary greatly between platforms.

Note that serial interfacing is NOT a trivial task -- you will often need unusual cables, and ports are not standardized between machines, in some cases, not even consistent on one machine. It is assumed you know how to select the appropriate cable to go between your computer and the device acting as your serial terminal. A full tutorial on serial interfacing is beyond the scope of this article, however, we offer one hint: just because the ends plug in doesn't mean it will work.
/etc/ttys change
There are two parts to getting a functional serial console on an OpenBSD system. First, you must have OpenBSD use your serial port as a console for status and single user mode. This part is very platform dependent. Second, you must enable the serial port to be used as an interactive terminal, so a user can log into it when running multi-user. This part is fairly similar between platforms, and is detailed here.

Terminal sessions are controlled by the /etc/ttys file. Before OpenBSD will give you a "login:" prompt at a device, it has to be enabled in /etc/ttys, after all, there are other uses for a serial port other than for a terminal. In platforms which typically have an attached keyboard and screen as a console, the serial terminal is typically disabled by default. We'll use the i386 platform as an example. In this case, you must edit the line that reads:

     tty00   "/usr/libexec/getty std.9600"   unknown off

to read:

     tty00   "/usr/libexec/getty std.9600"   vt100   on secure

Here, tty00 is the serial port we are using as a console. The "on" activates the getty for that serial port so that a "login:" prompt will be presented, the "secure" permits a root (uid 0) login at this console (which may or may not be what you desire), and the "9600" is the terminal baud rate. Note that you can use a serial console for install without doing this step, as the system is running in single user mode, and not using getty for login.

On some platforms and some configurations, you must bring the system up in single user mode to make this change if a serial console is all you have available.
amd64 and i386
To direct the boot process to use the serial port as a console, create or edit your /etc/boot.conf file to include the line:

     set tty com0

to use the first serial port as your console. The default baud rate is 9600bps, this can be changed with a /etc/boot.conf line using the stty option. This file is put on your boot drive, which could also be your install floppy, or the command can be entered at the boot> prompt from the OpenBSD second-stage boot loader for a one-time (or first time) serial console usage.

amd64 and i386 notes:

    * OpenBSD numbers the serial ports starting at tty00, DOS/Windows labels them starting at COM1. So, keep in mind tty02 is COM3, not COM2
    * Some systems may be able to operate without a video card in the machine, but certainly not all -- many systems consider this an error condition. Some machines will even refuse to work easily without a keyboard attached.
    * Some systems are capable of redirecting all BIOS keyboard and screen activity to a serial port through a configuration option, so the machine can be completely maintained through the serial port. Your results may vary -- when using this feature, some BIOSs may prevent the bootloader from seeing the serial port, and thus, the kernel will not be told to use it. Some BIOSs have an option to "Continue Console Redirection after POST" (Power On Self Test), this should be set to "OFF", so the boot loader and the kernel can handle their own console. Unfortunately, this feature is not universal.
    * PC compatible computers are not designed to be run from a serial console, unlike some other platforms. Even those systems that support a serial console usually have it as a BIOS configuration option -- and should the configuration information get corrupted, you will find the system looking for a standard monitor and keyboard again. You generally must have some way to get a monitor and keyboard to your amd64 and i386 systems in an emergency.
    * You will need to edit /etc/ttys as above.
    * Only the first serial port (com0) is supported for console on amd64 and i386.

SPARC and UltraSPARC
These machines are designed to be completely maintainable with a serial console. Simply remove the keyboard from the machine, and the system will run serial.
SPARC and UltraSPARC notes

    * The serial ports on a SPARC are labeled ttya, ttyb, etc.
    * Unlike some other platforms, it is not necessary to make any changes to /etc/ttys to use a serial console.
    * The SPARC/UltraSPARC systems interpret a BREAK signal on the console port to be the same as a STOP-A command, and kicks the system back to the Forth prompt, stopping any application and operating system at that point. This is handy when desired, but unfortunately, some serial terminals at power-down and some RS-232 switching devices send something the computer interprets as a break signal, halting the machine. Test before you go into production.
    * If you have a keyboard and monitor attached, you can still force the serial console to be used instead by using the following commands at the ok prompt:

     ok setenv input-device ttya
     ok setenv output-device ttya
     ok reset


      If the keyboard and monitor (ttyC0) are active in /etc/ttys (above), you can use the keyboard and monitor in X.

MacPPC
The MacPPC machines are configured for a serial console through OpenFirmware. Use the commands:

     ok setenv output-device scca
     ok setenv input-device scca
     ok reset-all


Set your serial console to 57600bps, 8N1.
MacPPC notes

    * Unfortunately, serial console is not directly possible on most MacPPCs. While most of these machines do have serial hardware, it isn't accessible outside the machine. Fortunately, a few companies offer add-on devices for several Macintosh models which will make this port available for use as a serial console (or other uses). Use your favorite search engine and look for "Macintosh internal serial port".
    * You will have to change tty00 in /etc/ttys to on and set the speed to 57600 instead of the default of 9600 as detailed above in single user mode before booting multi-user and having the serial console functional.

Mac68k
Serial console is selected in the Booter program, under the "Options" pull-down menu, then "Serial Ports". Check the "Serial Console" button, then choose the Modem or Printer port. You will need a Macintosh modem or printer cable to attach to the Mac's serial ports. If you wish to have this as default, tell the Booter program to save your options.
Mac68k Notes

    * The modem port is tty00, the printer port is tty01.
    * The Mac68k doesn't turn on its serial port until called upon, so your breakout box may not show any signals on the Mac's serial port until the OpenBSD boot process has started.
    * You will have to enable the port (tty00 or tty01) as indicated above.

论坛徽章:
1
寅虎
日期:2013-09-29 23:15:15
3 [报告]
发表于 2005-11-15 11:12 |只看该作者
以前的贴有写过.
记得是黑夜编码人写的.

论坛徽章:
1
寅虎
日期:2013-09-29 23:15:15
4 [报告]
发表于 2005-11-15 11:13 |只看该作者
还有NetBSD的.

论坛徽章:
0
5 [报告]
发表于 2005-11-15 11:41 |只看该作者
thank you!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP