LoginSignup
3
5

More than 5 years have passed since last update.

VMWare Fusion の Guest Linux にシリアル接続する

Posted at

たまたま立ち上げた VM に仮想コンソールが無くて IP も分からないのでシリアルでコンソールにアクセスする方法。

シリアルコンソールを作る

  • なんでもいいので一つシリアルポートを作る。
  • Virtual Machine > Setings... > Add Device... > Serial Port > Add...
    • とりあえずデフォルトで良い
    • Create a file to save the output of the virtual serial port
    • Save as: Untitled
    • Where: Virtual Machines
  • シリアル出力を観察するだけなら、ここで出来たファイルを読むだけで十分。
  • コマンド入力をしたいなら VM の vmx ファイルを直接編集して、ファイルの代わりに名前付きパイプにする。
    • 変更前
      • serial1.fileType = "file"
      • serial1.fileName = "xxxx/Untitled"
    • 変更後
      • serial1.fileType = "pipe"
      • serial1.fileName = "/tmp/serial1"

Guest のシリアルを Mac の標準入出力に転送

VM を起動した後で、socat というプログラムで /tmp/serial1 と標準入出力を対応づける。

socat /tmp/serial1 stdout

これでひとまず用はたせる。ifconfig などして IP を調べたりする。IP が分かって ssh 出来るなら下の screen は不要。

Guest のシリアルに screen でアクセス

stdout だと、制御文字がそのまま表示されたり、何かと使いづらいので screen でコンソールにアクセスするには、まず socat で stdout ではなく pty に転送する。-d をつけるとその分デバッグメッセージが増える。

socat -d -d /tmp/serial1 pty
2018/01/11 18:05:05 socat[7475] N opening connection to LEN=14 AF=1 "/tmp/serial1"
2018/01/11 18:05:05 socat[7475] N successfully connected from local address LEN=16 AF=1 ""
2018/01/11 18:05:05 socat[7475] N successfully connected via 
2018/01/11 18:05:05 socat[7475] N PTY is /dev/ttys003
2018/01/11 18:05:05 socat[7475] N starting data transfer loop with FDs [5,5] and [6,6]

socat の出力を読むと /dev/ttys003 に割り当てられているようなので、そこに screen で接続する。

screen /dev/ttys003

参考

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5