While echoing, e.g. echo "serial tx to ttyAMA0" > /dev/ttyAMA0 shows output towards serial console terminal on Linux initramfs loaded to /dev/ram0 on an arm64 platform, there's no connection to a shell when starting this sh or bash shell from /init script with e.g. /bin/busybox sh.

Kernel command line:
root=/dev/ram0 rw earlyprintk console=ttyAMA0,115200 console=tty0,115200 initcall_debug=1

(Only successful attempt for interacting with a serial port prompt for a user program was with /bin/busybox getty 115200 ttyAMA0, that shows login prompt, reacts to input from keyboard characters and prints 'login errors' to serial port ttyAMA0 terminal, since there is no getty configuration enabled, because this would be unnecessary for a maintenance/rescue shell on boot-up and therefore no login possible to specified user accounts. Only hint for difference to 'normal' shell terminal access is /sbin/tty command, what responds with 'not a tty'? Screen, minicom, several compatible sh shell versions, bash shell had been tried without being able to enable serial command line access to initramfs. There is no need, as far as i understand, and no possibility for changing code within the device tree. Maybe tty redirection for stdout/stdin is necessary, but there's no explanation for this on www search engines for providing a comprehensive solution to this difficulty. None of 'similar questions' suggestions provided a solution for this. Most answers here are with x86(_64) platforms.)

An adjusted minimal initramfs example was tested, by now, without access to serial terminal.



2 Answers 2


With your kernel boot options:

console=ttyAMA0,115200 console=tty0,115200

the kernel will output it's messages to both serial port ttyAMA0 and tty0 (i.e. the common Linux KVM console).

But when the first process is started, it cannot have two separate TTY devices as it's standard input (and likewise for standard output and standard error). Like all processes, it can have only (at most) one stdin, one stdout and one stderr. That device will be the primary console, and it is determined by the last console= option on the kernel command line.

If /init in your initramfs is a script, the commands executed by it will inherit the primary console - and only it - as their standard input/output/error, unless the script explicitly assigns another device for them.

So, the simplest solution to your problem would have been to just specify the console= options in the opposite order:

console=tty0 console=ttyAMA0,115200

(Specifying a baud rate for tty0 is not really necessary, as it involves no serial port connection. But there is no harm in specifying it either.)

  • i'm sorry, but with tested configuration and bootloader/Kernel versions, changing order of console definitions did not solve the access difficulty from serial console terminal towards stdin/stdout and standard tty. Thanks for Your explanations and contribution.
    – beyondtime
    Feb 25, 2023 at 20:00

Solved with xuancong84's answer on a similar question:
setsid sh -c 'exec sh </dev/ttyAMA0 >/dev/ttyAMA0 2>&1'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .