Как активировать вторую консоль для гостевой системы FreeBSD, работающей в bhyve?

Здесь довольно много вопросов, объединенных в один.

Во-первых, при использовании find я всегда использовал --execвместо xargs. Как правило, лучше выполнять действия как можно меньшим числом команд. Но также первые два метода записывают все имена файлов в текстовый поток, готовый для повторной -интерпретации xargs в имена файлов. Это ненужный шаг, который только добавляет(весьма небольшую)возможность потерпеть неудачу.

dos2unixбудет принимать несколько имен файлов, поэтому я бы использовал:

find. -type f -exec dos2unix --keepdate {} +

При этом будут складываться длинные списки файлов, а затем запускаться dos2unixсразу для целой группы файлов.


Чтобы узнать, какие файлы будут затронуты, просто отбросьте пункты exec:

find. -type f

Изменения в кодировке гораздо более проблематичны. Имейте в виду, что невозможно надежно определить текущую кодировку любого текстового файла. Иногда об этом можно догадаться, но это никогда не бывает на 100% надежным. Таким образом, вы можете пакетно обрабатывать кодировку только в том случае, если уверены, что все файлы в настоящее время имеют одну и ту же кодировку.

Я бы рекомендовал использовать iconv. Это действительно значение по умолчанию для этой работы. Вы можете найти справочную страницу здесь:

https://linux.die.net/man/1/iconv

Здесь есть рабочий пример использования iconvс find:

https://stackoverflow.com/questions/4544669/batch-convert-latin-1-files-to-utf-8-using-iconv

5
27.06.2020, 16:25
1 ответ

Решение состоит в том, чтобы изменить /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 secure(часть secureздесь не имеет значения ). Это означает, что эти терминальные устройства включаются только в том случае, если они действуют как консоль. Чтобы сделать возможным доступ к этим устройствам с хоста, нам просто нужно заменить 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!
2
18.03.2021, 23:23

Теги

Похожие вопросы