Difference between revisions of "Working with the serial console"

From ArchWiki
Jump to: navigation, search
(Configuration)
(picocom: Without path, picocom 2.1-2-x86_64 gives me: "FATAL: cannot open ttyS0: No such file or directory")
 
(31 intermediate revisions by 11 users not shown)
Line 6: Line 6:
  
 
A basic environment for this scenario is two machines connected using a serial cable (9-pin connector cable).
 
A basic environment for this scenario is two machines connected using a serial cable (9-pin connector cable).
The administering machine can be any Linux or Windows machine with a terminal emulator program (PuTTY or Minicom, for example).
+
The administering machine can be any Unix/Linux or Windows machine with a terminal emulator program (PuTTY or Minicom, for example).
  
 
The configuration instructions below will enable GRUB menu selection, boot messages, and terminal forwarding to the serial console.
 
The configuration instructions below will enable GRUB menu selection, boot messages, and terminal forwarding to the serial console.
Line 16: Line 16:
 
====GRUB2 and systemd====
 
====GRUB2 and systemd====
  
If you configure the serial console in GRUB2 systemd will create a getty listener on the same serial device as GRUB2 by default. So, this is the only configuration needed for Arch running with systemd.
+
If you configure the serial console in GRUB2 systemd will create a getty listener on the same serial device as GRUB2 by default. So, this is the only configuration needed for Arch running with systemd. To make grub enable the serial console, open {{ic|/etc/default/grub}} in an editor.
<br><br>
+
Change the {{ic|GRUB_CMDLINE_DEFAULT}} line to start the console on {{ic|/dev/ttyS0}}. Note in the example below, we set two consoles up; one on tty0 and one on the serial port.
Edit /etc/default/grub
+
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,38400n8"
<br><br>
+
 
1. Edit the GRUB_CMDLINE_DEFAULT="" line to start the console on /dev/ttyS0<br>
+
Now we need to tell grub what command to start in order to enable the serial console:
{{ic|<nowiki>
+
 
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,38400n8"
+
## Serial console
</nowiki>}}
+
GRUB_TERMINAL=serial
<br><br>
+
GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"
2. Add a serial console section<br>
+
 
{{ic|<nowiki>
+
Rebuild the grub.cfg file with following command:
# Serial console</nowiki><br>
+
# grub-mkconfig -o /boot/grub/grub.cfg
<nowiki>GRUB_TERMINAL=serial</nowiki><br>
+
 
<nowiki>GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"
+
After a reboot, getty will be listening on {{ic|/dev/ttyS0}}, expecting 38400 baud, 8 data bits, no parity and one stop bit. When Arch boots, systemd will automatically start a getty session to listen on the same device with the same settings.
</nowiki>}}
+
<br><br>
+
3. Rebuild the grub.cfg file<br>
+
{{ic|<nowiki>
+
grub-mkconfig > /boot/grub/grub.cfg
+
</nowiki>}}
+
<br><br>
+
Now you are done. After reboot getty will be listening on device /dev/ttyS0 with settings 38400 8N1 and systemd will automatically start a getty session to listen on the same device with the same settings.
+
  
 
=====Without GRUB2, systemd only=====
 
=====Without GRUB2, systemd only=====
This step is not needed if you have configured GRUB2 to listen on the serial interface. If you do not want GRUB2 to listen on the serial device, but only want getty listening after boot then follow these steps.
+
Ignore this entire section if you have configured GRUB2 to listen on the serial interface. If you do not want GRUB2 to listen on the serial device, but only want getty listening after boot then follow these steps.
<br><br>
+
1. To start getty listening on /dev/ttyS0 use systemctl<br>
+
{{ic|<nowiki>
+
systemctl start getty@ttyS0.service
+
</nowiki>}}
+
<br><br>
+
You can check to see the speed getty is useing with systemctl, but should be 38400 8N1<br>
+
{{ic|<nowiki>
+
systemctl status serial-getty@ttyS0.service
+
</nowiki>}}
+
<br><br>
+
2. To have getty listening on /dev/ttyS0 every boot create this symlink
+
{{ic|<nowiki>
+
ln -s /usr/lib/systemd/system/serial-getty@.service  /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service
+
</nowiki>}}
+
<br><br>
+
Now after reboot getty will be listening on device /dev/ttyS0 with settings 38400 8N1
+
  
====GRUB v1 and No systemd====
+
To start getty listening on {{ic|/dev/ttyS0}} use systemctl:
  
1. Edit the GRUB config file:
+
# systemctl start getty@ttyS0.service
  
vi /boot/grub/menu.lst
+
You can check to see the speed(s) getty is using with systemctl, but should be 38400 8N1:
  
Add these lines to the general area of the configuration:
+
# systemctl status serial-getty@ttyS0.service
  
{{ic|<nowiki>
+
To have getty listening on {{ic|/dev/ttyS0}} every boot, enable the service for that specific port:
serial --unit=0 --speed=9600</nowiki><br>
+
<nowiki>terminal --timeout=5 serial console</nowiki>
+
}}
+
  
Add the console parameters at the end of your current kernel line:
+
# systemctl enable serial-getty@ttyS0.service
  
{{ic|<nowiki>
+
Now, after a reboot, getty will be listening on device {{ic|/dev/ttyS0}} expecting 38400 baud, 8 data bits, no parity and one stop bit-times.
console=tty0 console=ttyS0,9600
+
 
</nowiki>}}
+
====GRUB v1 and No systemd====
 +
Edit the GRUB config file {{ic|/boot/grub/menu.lst}} and add these lines to the general area of the configuration:
 +
 
 +
serial --unit=0 --speed=9600
 +
terminal --timeout=5 serial console
 +
 
 +
Add suitable console parameters (e.g. change the serial device name or baud rate if required) at the end of your current kernel line:
 +
 
 +
console=tty0 console=ttyS0,9600
  
 
For example, the kernel line should look something like this after modification:
 
For example, the kernel line should look something like this after modification:
  
{{ic|<nowiki>
+
kernel /vmlinuz-linux root=/dev/md0 ro md=0,/dev/sda3,/dev/sdb3 vga=773 console=tty0 console=ttyS0,9600
kernel /vmlinuz-linux root=/dev/md0 ro md=0,/dev/sda3,/dev/sdb3 vga=773 console=tty0 console=ttyS0,9600
+
</nowiki>}}
+
  
 
{{note|When the {{ic|<nowiki>terminal --timeout=5 serial console</nowiki>}} line is added to your menu.lst grub configuration, your boot sequence will now show a series of "Press any key to continue"  messages.  If no key is pressed, the boot menu will appear on whichever (serial or console) appears first in the 'terminal' configuration line.  The lines will look like this upon boot:}}
 
{{note|When the {{ic|<nowiki>terminal --timeout=5 serial console</nowiki>}} line is added to your menu.lst grub configuration, your boot sequence will now show a series of "Press any key to continue"  messages.  If no key is pressed, the boot menu will appear on whichever (serial or console) appears first in the 'terminal' configuration line.  The lines will look like this upon boot:}}
 
 
{{ic|
 
{{ic|
 
Press any key to continue.<br>
 
Press any key to continue.<br>
Line 96: Line 73:
 
}}
 
}}
  
2. Edit the inittab file:  
+
Next, we have to edit {{ic|/etc/inittab}} and add a new agetty line below the existing ones:
  
  vi /etc/inittab
+
  c0:2345:respawn:/sbin/agetty 9600 ttyS0 linux
  
Add a new agetty line below the existing ones:
+
Edit {{ic|/etc/securetty}} and add an entry for the the serial console, ''below the existing entries'':
  
{{ic|
+
ttyS0
c0:2345:respawn:/sbin/agetty 9600 ttyS0 linux
+
}}
+
  
3. Edit the securetty file:
+
Reboot.
 
+
vi /etc/securetty
+
 
+
Below the existing ttys, add an entry for the the serial console:
+
 
+
{{ic|
+
ttyS0
+
}}
+
 
+
4. Reboot the machine
+
  
 
{{note|In all of the steps above, ttyS1 can also be used in case your machine has more than one serial port.}}
 
{{note|In all of the steps above, ttyS1 can also be used in case your machine has more than one serial port.}}
Line 123: Line 88:
  
 
===Connect using a terminal emulator program===
 
===Connect using a terminal emulator program===
 +
{{note|Before making a connection, it is recommended to add your user to the {{ic|uucp}} group. Otherwise you will need root's permission to make a connection:
  
Perform these steps on the machine used to connect the remote console.
+
# gpasswd -a ''username'' uucp
  
====Minicom====
+
See [[Users and groups#User groups]] for details.}}
  
1. Install {{Pkg|Minicom}}:
+
Perform these steps on the machine used to connect the remote console.
  
pacman -S minicom
+
==== Command line ====
 +
===== dterm =====
  
2. Start Minicom in setup mode:
+
{{aur|dterm}} is a tiny serial communication program. If you invoke it without parameters, it will connect to {{ic|/dev/ttyS0}} at 9600 baud by default. The following example connect to {{ic|/dev/ttyS0}} at 115200 baud, with 8 data bits, no parity bit and 1 stop bit-times:
  
  minicom -s
+
  $ dterm 115200 8 n 1
  
3. Using the textual navigation menu, change the serial port settings to the following:
+
See its homepage[http://www.knossos.net.nz/resources/free-software/dterm/] for more examples.
  
{{ic|
+
===== Minicom =====
Serial Device: /dev/ttyS0<br>
+
Bps/Par/Bits: 9600 8N1
+
}}
+
  
Press Enter to exit the menus (pressing Esc will not save changes).
+
{{Pkg|minicom}} can be obtained from the official repositories. Start Minicom in setup mode:
  
4. Remove the modem Init and Reset strings:
+
$ minicom -s
  
Under the 'Modem and Dialing' menu, delete the Init and Reset strings.
+
Using the textual navigation menu, change the serial port settings to the following:
  
5. Save the setup:
+
Serial Device: /dev/ttyS0
 +
Bps/Par/Bits: 9600 8N1
  
From the main menu, choose 'save setup as dfl'.
+
Press Enter to exit the menus (pressing Esc will not save changes).
 +
Remove the modem Init and Reset strings, as we are not connecting to a modem. To do this, under the {{ic|Modem and Dialing}} menu, delete the Init and Reset strings. Optionally save the configuration by choosing {{ic|save setup as dfl}} from the main menu.
 +
Restart minicom with the serial cable connected to the target machine.
 +
To end the session, press {{ic|Ctrl+A}} followed by {{ic|Ctrl+X}}.
  
6. Exit Minicom:
+
===== picocom =====
  
From the main menu, choose 'Exit from Minicom'.
+
{{pkg|picocom}} is a tiny dumb-terminal emulation program that is very like minicom, but instead of ''mini'', it is ''pico''. The following example connect to {{ic|ttyS0}} at 9600 bps:
  
7. Connect to the target machine:
+
$ picocom -b 9600 /dev/ttyS0
  
While the serial cable is connected to the target machine, start the Minicom program:
+
See its manual for detailed usage.
  
minicom
+
===== Screen =====
  
8. Exiting Minicom
+
{{Pkg|screen}} is able to connect to a serial port. It will connect at 9600 baud by default:
  
To finish the session, press 'ctrl-A' and then 'X'.
+
$ screen /dev/ttyS0
  
====Screen====
+
A different baud rate (e.g. 115200) may be specified on the commmand line.
  
Screen is able to connect to a serial port. It will connect to a standard 9600 speed port without options.
+
screen /dev/ttyS0 115200
  
screen /dev/ttyS0
+
===== Serialclient =====
  
If needed, see the section "WINDOW TYPES" in the screen man page for details on setting the baud rate.
+
Serialclient[https://github.com/flagos/serialclient] is a CLI client for serial connection written in ruby. Install it with the following:
 
+
  # pacman -S ruby
====Serialclient====
+
  # gem install serialclient
 
+
Serialclient[https://github.com/flagos/serialclient] is a client for serial connection in command line in your shell. Install it doing:
+
  pacman -S ruby
+
  gem install serialclient
+
  
 
Then, you can use like this:
 
Then, you can use like this:
  serialclient -p /dev/ttyS0
+
  $ serialclient -p /dev/ttyS0
  
====Windows Options====
+
==== And, for Windows ====
  
On Windows machines, connect to the serial port using programs like PuTTY or Hyper Terminal.
+
On Windows machines, connect to the serial port using programs like PuTTY[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html] or Terminalbpp[https://sites.google.com/site/terminalbpp/].
  
==Installing Arch Linux using the serial console==
+
==== Graphical front-ends ====
  
1. Connect to the target machine using the method described above.
+
{{AUR|gtkterm}}{{Broken package link|{{aur-mirror|gtkterm}}}} provides a graphical interface to the task, with most abilities provided by {{Pkg|vte}}.
  
2. Boot the target machine using the Arch Linux installation CD.
+
{{AUR|cutecom}} is another gui enabled serial monitor.
  
3. When the bootloader appears, select "Boot Arch Linux (<arch>)" and press tab to edit
+
{{pkg|putty}} is also available for Linux.
  
4. Append {{ic|1=console=ttyS0}} and press enter
+
==Installing Arch Linux using the serial console==
 +
{{note|The Arch Linux monthly release(i.e. the installation CD)'s boot loader has been configured[https://projects.archlinux.org/archiso.git/tree/configs/releng/syslinux/archiso_head.cfg#n1] to listen on 0 port({{ic|ttyS0}}/COM1) at 38400 bps, with 8 data bits, no parity bit and 1 stop bit-times.}}
  
5. Systemd should now detect ttyS0 and spawn a serial getty on it, allowing you to proceed as usual
+
# Connect to the target machine using the method described above.
 +
# Boot the target machine using the Arch Linux installation CD.
 +
# When the bootloader appears, select ''Boot Arch Linux (<arch>)'' and press {{ic|Tab}} to edit
 +
# Append {{ic|1=console=ttyS0,38400}} and press {{ic|Enter}}.
 +
# Now systemd should detect ttyS0 and spawn a serial getty on it. Login as {{ic|root}} and start the installation as usual.
  
 
{{note|After setup is complete, the console settings will not be saved on the target machine; in order to avoid having to connect a keyboard and monitor, configure console access on the target machine before rebooting.}}
 
{{note|After setup is complete, the console settings will not be saved on the target machine; in order to avoid having to connect a keyboard and monitor, configure console access on the target machine before rebooting.}}
  
{{note|While a port speed of 9600 is used in all of the examples in this document, working with higher values is recommended (List of available speeds is displayed in Minicom by pressing 'Ctrl-A' and then 'P')}}
+
{{note|While a port speed of 9600 is used in most of the examples in this document, working with higher values is recommended (List of available speeds is displayed in Minicom by pressing 'Ctrl-A' and then 'P')}}
  
 
==Troubleshooting==
 
==Troubleshooting==
 
===Ctrl-C and Minicom===
 
===Ctrl-C and Minicom===
 
If you are having trouble sending a Control-C command through minicom you need to switch off hardware flow control in the device settings (minicom -s), which then enables the break.
 
If you are having trouble sending a Control-C command through minicom you need to switch off hardware flow control in the device settings (minicom -s), which then enables the break.
 +
 +
===Resizing a terminal===
 +
Unlike ssh, serial connection does not have a mechanism to transfer something like {{ic|SIGWINCH}} when a terminal is resized. This will cause weird problem with some full-screen programs (e.g. {{ic|less}}) when you resized your terminal emulator's window.
 +
 +
Resize the terminal via {{ic|stty}} is a workaround:
 +
$ stty rows ''lines'' cols ''columns''
 +
 +
However the above one requires you to manually input the proper geometry. The following examples should simplify the work.
 +
 +
1. There is a less-known utility called {{ic|resize}}, which is shipped with {{pkg|xterm}}, can solve this problem. Invoke it without parameter after you resize the terminal emulator's window:
 +
$ resize
 +
 +
2. In the case that you do not want to install xterm, it is possible to do the same work via a simple shell function. Put the following function into your zshrc, invoke it without parameter after you resize the terminal emulator's window:
 +
{{bc|<nowiki>rsz() {
 +
if [[ -t 0 && $# -eq 0 ]];then
 +
local IFS='[;' escape geometry x y
 +
print -n '\e7\e[r\e[999;999H\e[6n\e8'
 +
read -sd R escape geometry
 +
x=${geometry##*;} y=${geometry%%;*}
 +
if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]];then
 +
print "${TERM} ${x}x${y}"
 +
else
 +
print "${COLUMNS}x${LINES} -> ${x}x${y}"
 +
stty cols ${x} rows ${y}
 +
fi
 +
else
 +
[[ -n ${commands[repo-elephant]} ]] && repo-elephant || print 'Usage: rsz'  ## Easter egg here :)
 +
fi
 +
}</nowiki>}}

Latest revision as of 22:25, 31 January 2016

Configure your Arch Linux machine so you can connect to it via the serial console port (com port). This will enable you to administer the machine even if it has no keyboard, mouse, monitor, or network attached to it (a headless server).

As of Arch Linux 2007.x, installation of Arch Linux is possible via the serial console as well.

A basic environment for this scenario is two machines connected using a serial cable (9-pin connector cable). The administering machine can be any Unix/Linux or Windows machine with a terminal emulator program (PuTTY or Minicom, for example).

The configuration instructions below will enable GRUB menu selection, boot messages, and terminal forwarding to the serial console.

Configuration

Configure console access on the target machine

GRUB2 and systemd

If you configure the serial console in GRUB2 systemd will create a getty listener on the same serial device as GRUB2 by default. So, this is the only configuration needed for Arch running with systemd. To make grub enable the serial console, open /etc/default/grub in an editor. Change the GRUB_CMDLINE_DEFAULT line to start the console on /dev/ttyS0. Note in the example below, we set two consoles up; one on tty0 and one on the serial port.

GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,38400n8"

Now we need to tell grub what command to start in order to enable the serial console:

## Serial console
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"

Rebuild the grub.cfg file with following command:

# grub-mkconfig -o /boot/grub/grub.cfg

After a reboot, getty will be listening on /dev/ttyS0, expecting 38400 baud, 8 data bits, no parity and one stop bit. When Arch boots, systemd will automatically start a getty session to listen on the same device with the same settings.

Without GRUB2, systemd only

Ignore this entire section if you have configured GRUB2 to listen on the serial interface. If you do not want GRUB2 to listen on the serial device, but only want getty listening after boot then follow these steps.

To start getty listening on /dev/ttyS0 use systemctl:

# systemctl start getty@ttyS0.service

You can check to see the speed(s) getty is using with systemctl, but should be 38400 8N1:

# systemctl status serial-getty@ttyS0.service

To have getty listening on /dev/ttyS0 every boot, enable the service for that specific port:

# systemctl enable serial-getty@ttyS0.service

Now, after a reboot, getty will be listening on device /dev/ttyS0 expecting 38400 baud, 8 data bits, no parity and one stop bit-times.

GRUB v1 and No systemd

Edit the GRUB config file /boot/grub/menu.lst and add these lines to the general area of the configuration:

serial --unit=0 --speed=9600
terminal --timeout=5 serial console

Add suitable console parameters (e.g. change the serial device name or baud rate if required) at the end of your current kernel line:

console=tty0 console=ttyS0,9600

For example, the kernel line should look something like this after modification:

kernel /vmlinuz-linux root=/dev/md0 ro md=0,/dev/sda3,/dev/sdb3 vga=773 console=tty0 console=ttyS0,9600
Note: When the terminal --timeout=5 serial console line is added to your menu.lst grub configuration, your boot sequence will now show a series of "Press any key to continue" messages. If no key is pressed, the boot menu will appear on whichever (serial or console) appears first in the 'terminal' configuration line. The lines will look like this upon boot:

Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.
Press any key to continue.

Next, we have to edit /etc/inittab and add a new agetty line below the existing ones:

c0:2345:respawn:/sbin/agetty 9600 ttyS0 linux

Edit /etc/securetty and add an entry for the the serial console, below the existing entries:

ttyS0

Reboot.

Note: In all of the steps above, ttyS1 can also be used in case your machine has more than one serial port.

Making Connections

Connect using a terminal emulator program

Note: Before making a connection, it is recommended to add your user to the uucp group. Otherwise you will need root's permission to make a connection:
# gpasswd -a username uucp
See Users and groups#User groups for details.

Perform these steps on the machine used to connect the remote console.

Command line

dterm

dtermAUR is a tiny serial communication program. If you invoke it without parameters, it will connect to /dev/ttyS0 at 9600 baud by default. The following example connect to /dev/ttyS0 at 115200 baud, with 8 data bits, no parity bit and 1 stop bit-times:

$ dterm 115200 8 n 1

See its homepage[1] for more examples.

Minicom

minicom can be obtained from the official repositories. Start Minicom in setup mode:

$ minicom -s

Using the textual navigation menu, change the serial port settings to the following:

Serial Device: /dev/ttyS0
Bps/Par/Bits: 9600 8N1

Press Enter to exit the menus (pressing Esc will not save changes). Remove the modem Init and Reset strings, as we are not connecting to a modem. To do this, under the Modem and Dialing menu, delete the Init and Reset strings. Optionally save the configuration by choosing save setup as dfl from the main menu. Restart minicom with the serial cable connected to the target machine. To end the session, press Ctrl+A followed by Ctrl+X.

picocom

picocom is a tiny dumb-terminal emulation program that is very like minicom, but instead of mini, it is pico. The following example connect to ttyS0 at 9600 bps:

$ picocom -b 9600 /dev/ttyS0

See its manual for detailed usage.

Screen

screen is able to connect to a serial port. It will connect at 9600 baud by default:

$ screen /dev/ttyS0

A different baud rate (e.g. 115200) may be specified on the commmand line.

screen /dev/ttyS0 115200
Serialclient

Serialclient[2] is a CLI client for serial connection written in ruby. Install it with the following:

# pacman -S ruby
# gem install serialclient

Then, you can use like this:

$ serialclient -p /dev/ttyS0

And, for Windows

On Windows machines, connect to the serial port using programs like PuTTY[3] or Terminalbpp[4].

Graphical front-ends

gtktermAUR[broken link: archived in aur-mirror] provides a graphical interface to the task, with most abilities provided by vte.

cutecomAUR is another gui enabled serial monitor.

putty is also available for Linux.

Installing Arch Linux using the serial console

Note: The Arch Linux monthly release(i.e. the installation CD)'s boot loader has been configured[5] to listen on 0 port(ttyS0/COM1) at 38400 bps, with 8 data bits, no parity bit and 1 stop bit-times.
  1. Connect to the target machine using the method described above.
  2. Boot the target machine using the Arch Linux installation CD.
  3. When the bootloader appears, select Boot Arch Linux (<arch>) and press Tab to edit
  4. Append console=ttyS0,38400 and press Enter.
  5. Now systemd should detect ttyS0 and spawn a serial getty on it. Login as root and start the installation as usual.
Note: After setup is complete, the console settings will not be saved on the target machine; in order to avoid having to connect a keyboard and monitor, configure console access on the target machine before rebooting.
Note: While a port speed of 9600 is used in most of the examples in this document, working with higher values is recommended (List of available speeds is displayed in Minicom by pressing 'Ctrl-A' and then 'P')

Troubleshooting

Ctrl-C and Minicom

If you are having trouble sending a Control-C command through minicom you need to switch off hardware flow control in the device settings (minicom -s), which then enables the break.

Resizing a terminal

Unlike ssh, serial connection does not have a mechanism to transfer something like SIGWINCH when a terminal is resized. This will cause weird problem with some full-screen programs (e.g. less) when you resized your terminal emulator's window.

Resize the terminal via stty is a workaround:

$ stty rows lines cols columns

However the above one requires you to manually input the proper geometry. The following examples should simplify the work.

1. There is a less-known utility called resize, which is shipped with xterm, can solve this problem. Invoke it without parameter after you resize the terminal emulator's window:

$ resize

2. In the case that you do not want to install xterm, it is possible to do the same work via a simple shell function. Put the following function into your zshrc, invoke it without parameter after you resize the terminal emulator's window:

rsz() {
	if [[ -t 0 && $# -eq 0 ]];then
		local IFS='[;' escape geometry x y
		print -n '\e7\e[r\e[999;999H\e[6n\e8'
		read -sd R escape geometry
		x=${geometry##*;} y=${geometry%%;*}
		if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]];then
			print "${TERM} ${x}x${y}"
		else
			print "${COLUMNS}x${LINES} -> ${x}x${y}"
			stty cols ${x} rows ${y}
		fi
	else
		[[ -n ${commands[repo-elephant]} ]] && repo-elephant || print 'Usage: rsz'  ## Easter egg here :)
	fi
}