让两个 Linux(虚拟)盒子通过串行端口进行通信

发布于 2024-07-05 09:53:50 字数 240 浏览 2 评论 0原文

设置一台 Linux 机器以侦听其串行端口传入连接的最佳方法是什么? 我已经做了很多谷歌搜索,但我找不到正确的命令组合来真正让他们说话!

我的主要目标是为正在运行的 kvm/qemu 虚拟机实例提供串行接口。 他们目前只有一个 VNC 接口(他们位于无头服务器上,没有 X)。 我可以让虚拟机通过使用 -serial file: 标志启动它来创建串行设备,但如何与其交谈,则是另一个问题。 两个机器都运行 Ubuntu 8.04。

What is the best way to setup one Linux box to listen on its serial port for incoming connections? I've done a lot of googling but I can't find the right combination of commands to actually get them to talk!

My main objective is to provide a serial interface to running instances of kvm/qemu VMs. They currently only have a VNC interface (they are on headless servers, no X). I can get the VM to create a serial device by starting it with the -serial file: flag, but how to talk to it, is a whole other problem. Both boxes are running Ubuntu 8.04.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒尘 2024-07-12 09:53:50

我假设您使用“零调制解调器”电缆连接两个串行端口。

使用像 minicom 这样的程序与远程系统通信 - 您可能需要设置通信参数,并可能需要关闭硬件流控制(如果您的电缆没有连接流控制线)。

I assume you connect the two serial ports using a "null modem" cable.

Use a program like minicom to talk to remote system -- you probably need to set up the communication parameters and possibly turn off hardware flow control (if your cable doesn't have the flow-control lines connected).

萌吟 2024-07-12 09:53:50

假设您正在 /dev/tty1 上执行此操作。

在 shell 中

chown *youruser* /dev/tty1

然后在名为 example.pl 的 Perl 脚本中

open PORT, "</dev/tty1" || die "Can't open port: $!";
while (defined ($_ = <PORT>))
{
 do_something($_);
}
close PORT;

显然,如果您希望它自动启动、出现错误时重新生成等等,还有更多工作要做。 但基本思想是像文件一样从串口读取。

Say you're doing this on /dev/tty1.

in the shell

chown *youruser* /dev/tty1

then in a Perl script called example.pl

open PORT, "</dev/tty1" || die "Can't open port: $!";
while (defined ($_ = <PORT>))
{
 do_something($_);
}
close PORT;

Obviously there is more to do if you want this to start automatically, and respawn on error, and so on. But the basic idea is to read from the serial port like a file.

您的好友蓝忘机已上羡 2024-07-12 09:53:50

Linux Serial HOWTO 有很多有关串行通信的详细信息。 更具体的 Linux 远程串行控制台 HOWTO 就是您的内容您正在真正寻找是否希望能够使用串行端口登录虚拟化系统,就像您在控制台一样。 正如 Hein 所指出的,您需要一根零调制解调器电缆,并且需要在远程终端上运行 minicom。

Linux 控制台有两种使用方式,每种方式都必须单独配置才能串行使用。 您可以将内核配置为通过串行端口复制其消息,这有时对于观察系统启动很有趣,并且在进行内核调试时几乎是不可或缺的。 (这需要内核支持并更新启动参数,以便内核知道您想要串行输出;请参阅 第二个howto的第5章。)您可能对通过串行端口登录更感兴趣,这需要在启动后在串行端口上运行getty(就像您的系统已经在启动后的虚拟终端),详细描述见第6章。

The Linux Serial HOWTO has a lot of detailed information about serial communication in general. The more-specific Linux Remote Serial Console HOWTO is what you're really looking for if you want to be able to log into your virtualized systems using the serial port as if you were at the console. As Hein indicated, you'll need a null modem cable and need to run minicom on the remote terminal.

The Linux console is used in two ways, each of which must be configured separately for serial use. You can configure the kernel to copy its messages over the serial port, which is occasionally interesting for watching the system boot and nearly indispensable if you're doing kernel debugging. (This requires kernel support and updating the boot parameters so the kernel knows you want serial output; see chapter 5 of the second howto.) You're probably more interested in logging in via the serial port, which requires running getty on the serial port after boot (just like your system already runs getty on the virtual terminals after boot), which is described in detail in chapter 6 of the howto.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文