Freebsd

如何啟動在 bhyve 中執行的 FreeBSD 來賓的第二個控制台?

  • June 27, 2020

背景

我正在執行 FreeBSD 12.1-RELEASE 作為bhyve虛擬機的主機。

我有一個在 VM 內執行的 FreeBSD 12.1-RELEASE 來賓。我想為其配置兩個 TTY 類設備。

根據手冊頁,為了使用兩個 TTY 類設備啟動 VM,我必須使用類似於以下的命令行選項啟動 bhyve -l com1,/dev/nmdm0B -l com2,/dev/nmdm1B:然後我應該能夠通過這兩個nullmodem 終端使用cu -l /dev/nmdm0A和連接到來賓cu -l /dev/nmdm1A

問題

第一個命令按預期工作:cu -l /dev/nmdm0A向我顯示來賓的主控制台。

然而,第二個命令附加到客戶機,但什麼也不顯示。我希望向我顯示一個登錄提示,就像切換到另一個 TTY 一​​樣。

我錯過了什麼?


額外細節

  • 來賓是 FreeBSD 的全新安裝。
  • 來賓上的輸出dmesg | grep uart如下:
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: console (115200,n,8,1)
uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0
  • 我嘗試hint.uart.1.flags先設置為0x10,然後再設置為0x80(儘管這是我從uart(4)了解的內​​核調試器)並在每次更改後重新啟動。它沒有用。

參考

/etc/ttys解決方案是在來賓上進行修改。在 amd64 上,它具有以下預設值:

#
# $FreeBSD: head/sbin/init/ttys.amd64 338454 2018-09-04 15:48:13Z brd $
#   @(#)ttys    5.1 (Berkeley) 4/17/89
#
# This file specifies various information about terminals on the system.
# It is used by several different programs.  Common entries for the
# various columns include:
#
# name  The name of the terminal device.
#
# getty The program to start running on the terminal.  Typically a
#       getty program, as the name implies.  Other common entries
#       include none, when no getty is needed, and xdm, to start the
#       X Window System.
#
# type The initial terminal type for this port.  For hardwired
#      terminal lines, this will contain the type of terminal used.
#      For virtual consoles, the correct type is typically xterm.
#      Other common values include dialup for incoming modem ports, and
#      unknown when the terminal type cannot be predetermined.
#
# status Must be on or off.  If on, init will run the getty program on
#        the specified port.  If the word "secure" appears, this tty
#        allows root login.
#
# name  getty               type    status      comments
#
# If console is marked "insecure", then init will ask for the root password
# when going to single-user mode.
console none                unknown off secure
#
ttyv0   "/usr/libexec/getty Pc"     xterm   onifexists secure
# Virtual terminals
ttyv1   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv2   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv3   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv4   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv5   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv6   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv7   "/usr/libexec/getty Pc"     xterm   onifexists secure
ttyv8   "/usr/local/bin/xdm -nodaemon"  xterm   off secure
# Serial terminals
# The 'dialup' keyword identifies dialin lines to login, fingerd etc.
ttyu0   "/usr/libexec/getty 3wire"  vt100   onifconsole secure
ttyu1   "/usr/libexec/getty 3wire"  vt100   onifconsole secure
ttyu2   "/usr/libexec/getty 3wire"  vt100   onifconsole secure
ttyu3   "/usr/libexec/getty 3wire"  vt100   onifconsole secure
# Dumb console
dcons   "/usr/libexec/getty std.9600"   vt100   off secure

可以看到,每個ttyu終端設備的狀態都設置為onifconsole securesecure此處無關部分)。這意味著這些終端設備只有在充當控制台時才會打開。為了能夠從主機訪問這些設備,我們只需onifconsole要將onifexists.

在我的特殊情況下,我必須替換以下行:

ttyu1   "/usr/libexec/getty 3wire"  vt100   onifconsole secure

和:

ttyu1   "/usr/libexec/getty 3wire"  vt100   ifexists secure

因此,現在可以使用第二個控制台連接到訪客系統:

# cu -l /dev/nmdm1A
Password:
Connected


FreeBSD/amd64 (testvm) (ttyu1)

login: root
Password:
Last login: Fri Jun 26 19:59:40 on ttyu1
FreeBSD 12.1-RELEASE r354233 GENERIC

Welcome to FreeBSD!

引用自:https://unix.stackexchange.com/questions/595234