bike9876@エボ猫.コム

Connect a linux box to the raspberry pi 5 via a serial cable

It’s easy to connect a linux box to the raspberry pi 5 via a serial cable. This is useful eg to monitor the output during boot, or to make it easy to enter a passphrase to unlock the root partition (if it is encrypted).

You need a cable like the USB to TTL Serial Cable sold by thepihut (in the UK).

I think this is the Adafruit 954 USB-to-TTL Serial Cable.

Steps needed:

NB both my linux box and my pi run arch linux.

Edit /boot/config.txt on the pi

Add line at end of file (following the [all] line):

dtparam=uart0_console

See https://forums.raspberrypi.com/viewtopic.php?t=359132#p2154324 re this setting.

Edit /boot/cmdline.txt on the pi

There should only be one console= setting (but leave other settings alone):

console=serial0,115200

Power off the pi

Connect serial cable to pi

The individual coloured wires of the cable go to the pi.

The wires connect as:

See https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#gpio for pin locations on the GPIO header.

Connect usb end of cable to linux box

Suggest run

journalctl -e

on the linux box. (Press q to exit the pager.)

Should see a line similar to

XXX XX XX:XX:XX XXXX kernel: usb 1-2: cp210x converter now attached to ttyUSB0

So in this case, the device file is /dev/ttyUSB0.

Check the ownership of the device file (change device filename as needed):

Run on the linux box

ls -l /dev/ttyUSB0

which will give something like:

crw-rw---- 1 root uucp 188, 0 XXX XX XX:XX /dev/ttyUSB0

So the device file allows group uucp r/w access.

On linux box install the screen program, and add user to uucp group

(Change uucp to whatever group has access to the device as in the previous step.)

eg on arch linux:

sudo pacman -S screen

I recommend setting a decent size for the screen scrollback buffer, eg in ~/.screenrc on the linux box, have:

defscrollback 10000

Add user to uucp group

sudo usermod -aG uucp USERNAME # replace USERNAME with the username of the non-root a/c that will run screen

Log out and in again from linux box (so are now member of uucp)

Or run

sudo -s -u USERNAME

which will have USERNAME in the uucp group within (and only within) that terminal.

On linux box, run (change /dev device as needed)

screen /dev/ttyUSB0 115200

Power on rpi

Should be able to see whole boot process, until eventually a login prompt appears.

Can scroll by entering screen’s ‘copy mode’ with Ctrl-a <Escape>, then use mouse-wheel, or up/down keys, or Page-up/Page-down keys. (Press q to exit copy mode.)

Can search backwards by entering screen’s copy mode, then eg ?switch. Repeat ? to search further back. Enter / to search forwards again.

When finished

When finished (eg the pi is powered down), can exit the screen session with Ctrl-a k (then confirm).