# pkg install tmux
Appendix D. Managing Serial Terminals with tmux and screen
Table of Contents
D.1. Using tmux(1) for Managing Serial Terminals
Install tmux with:
Run sh swim.sh in the SCRIPTS directory to start up the session manager running tmux.
The figure shows five named windows in one session (session [0]) with the tmux status line in green at the bottom:
Simplified tmux(1) Usage
tmux has a hierarchical organization.
Sessions - you start a session implicitly when you run tmux
Windows - you add a window with the command "tmux add-window" which can take a number of parameters. You can have multiple windows in a session at the same time. The current window is starred ("*") in the status bar at the bottom of the main window.
Panes - you can split a window into one or more panes either horizontally, or vertically.
The swim.sh script shows how to set up one session with several windows. Panes are not used.
tmux is controlled by the user typing in any open window or pane. tmux uses Ctl+b as its control key. You give tmux commands by typing the control key followed by one or more letters. To move from window to window use Ctl+b n to move to the next window or Ctl+b p to move to the previous window. Use Ctl+b ? for a list of all key bindings.
Type tmux kill-server in any session window to completely leave tmux.
Consult the tmux manual page tmux(1) for more usage details.
Accessing the QEMU Serial Consoles
To access the VM serial consoles, move to the indicated window and telnet to the port on the local host for that VM:
Move to the external1 window in tmux, then ~/ipfw/SCRIPTS $ telnet localhost 4410 Trying ::1... Connected to localhost. Escape character is '^]'. FreeBSD/amd64 (external1) (ttyu0) login:
The swim.sh script has the following un-commented lines. Un-comment additional lines as needed
0:bash - a terminal window of the user running swim.sh
1:firewall - a terminal window to access the firewall VM
2:external1 - a terminal window to access the external1 VM
3:external2 - a terminal window to access the external2 VM
4:external3 - a terminal window to access the external3 VM
The current window is marked with the '*' character in the status bar.
Note that the swim.sh script has entries for all windows used in this book. Uncomment the entries you need.
Run sh swim.sh in the SCRIPTS directory to start up the session manager running tmux.
D.2. Using screen(1) for Managing Serial Terminals
Install screen with:
# pkg install screen
screen, like tmux, is a terminal window manager. screen has its own control key - Ctl+a, and like tmux a list of key bindings is available at Ctl+a ?.
By default, it does not use a status line, and once activated, it looks like no manager is active at all. Type screen -ls to determine if there is an active screen session running.
To display a status line in a live session use:
Ctrl+a : hardstatus alwayslastline
Ctrl+a : hardstatus string "%{= bw}%-w%{= rW}[%n %t]%{-}%+w %=%{= kW} %H | %Y-%m-%d %c"
If you want it to always appear, edit the .screenrc file in your $HOME
directory and add:
hardstatus alwayslastline hardstatus string "%{= bw}%-w%{= rW}[%n %t]%{-}%+w %=%{= kW} %H | %Y-%m-%d %c"
To close all screen windows immediately and exit:
% screen -X quit
The scim.sh script has the following un-commented lines. Un-comment additional lines as needed
0:bash - a terminal window of the user running scim.sh
1:firewall - a terminal window to access the firewall VM
2:external1 - a terminal window to access the external1 VM
3:external2 - a terminal window to access the external2 VM
4:external3 - a terminal window to access the external3 VM
The current window is highlighted in the status bar.
Note that the scim.sh script has entries for all windows used in this book. Uncomment the entries you need.
Run sh scim.sh in the SCRIPTS directory to start up the session manager running screen.