Skip to content

Commit 58face4

Browse files
committed
readme: ttys are starting to make sense!
1 parent fafcf06 commit 58face4

File tree

1 file changed

+136
-16
lines changed

1 file changed

+136
-16
lines changed

README.adoc

Lines changed: 136 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,36 @@ Double quotes can be used to escape spaces as in `opt="a b"`, but double quotes
749749

750750
This even lead us to use base64 encoding with `-E`!
751751

752+
==== Kernel command line parameters definition points
753+
754+
There are two methods:
755+
756+
* `__setup` as in:
757+
+
758+
....
759+
__setup("console=", console_setup);
760+
....
761+
* `core_param` as in:
762+
+
763+
....
764+
core_param(panic, panic_timeout, int, 0644);
765+
....
766+
767+
`core_param` suggests how they are different:
768+
769+
....
770+
/**
771+
* core_param - define a historical core kernel parameter.
772+
773+
...
774+
775+
* core_param is just like module_param(), but cannot be modular and
776+
* doesn't add a prefix (such as "printk."). This is for compatibility
777+
* with __setup(), and it makes sense as truly core parameters aren't
778+
* tied to the particular file they're in.
779+
*/
780+
....
781+
752782
=== insmod alternatives
753783

754784
==== modprobe
@@ -3383,33 +3413,123 @@ The bitmask is documented at:
33833413
less linux/Documentation/admin-guide/sysrq.rst
33843414
....
33853415

3386-
===== Multiple TTYs
3416+
==== TTY
33873417

3388-
Switch between TTYs with:
3418+
In order to play with TTYs, do this:
33893419

33903420
....
3391-
sendkey alt-left
3392-
sendkey alt-right
3393-
sendkey alt-f1
3394-
sendkey alt-f2
3421+
printf '
3422+
tty2::respawn:/sbin/getty -n -L -l /loginroot.sh tty2 0 vt100
3423+
tty3::respawn:-/bin/sh
3424+
tty4::respawn:/sbin/getty 0 tty4
3425+
tty63::respawn:-/bin/sh
3426+
::respawn:/sbin/getty -L ttyS0 0 vt100
3427+
::respawn:/sbin/getty -L ttyS1 0 vt100
3428+
::respawn:/sbin/getty -L ttyS2 0 vt100
3429+
# Leave one serial empty.
3430+
#::respawn:/sbin/getty -L ttyS3 0 vt100
3431+
' >> rootfs_overlay/etc/inittab
3432+
./build
3433+
./run -x -- \
3434+
-serial telnet::1235,server,nowait \
3435+
-serial telnet::1236,server,nowait \
3436+
-serial telnet::1237,server,nowait \
3437+
;
33953438
....
33963439

3397-
TODO: only works after I do a `chvt 1`, but then how to put a terminal on `alt-f2`? I just get a blank screen. One day, one day:
3440+
and on a second shell:
33983441

3399-
* https://stackoverflow.com/questions/16706423/two-instances-of-busybox-on-separate-serial-lines-ttysn
3400-
* https://serverfault.com/questions/119736/how-to-enable-multiple-virtual-consoles-on-linux
3401-
* https://superuser.com/questions/33065/console-commands-to-change-virtual-ttys-in-linux-and-openbsd
3402-
* https://stackoverflow.com/questions/39373236/redirect-multiple-uarts-in-qemu
3442+
....
3443+
telnet localhost 1235
3444+
....
3445+
3446+
We don't add more TTYs by default because it would spawn more processes, even if we use `askfirst` instead of `respawn`.
34033447

3404-
Also tried to add some extra lines to `/etc/inittab` of type:
3448+
On the GUI, switch TTYs with:
34053449

3450+
* `Alt-Left` or `Alt-Right:` go to previous / next populated TTY. Skips over empty TTYs.
3451+
* `Alt-Fn`: go to the nth TTY. If it is not populated, don't go there.
3452+
* `chvt <n>`: go to the n-th virtual TTY, even if it is empty: https://superuser.com/questions/33065/console-commands-to-change-virtual-ttys-in-linux-and-openbsd
3453+
3454+
You can also test this on most hosts such as Ubuntu 18.04, except that when in the GUI, you must use `Ctrl-Alt-Fx` to switch to another terminal.
3455+
3456+
Then, go to the text shells we opened previously, and press enter, and you will see that we have:
3457+
3458+
* one shell on the shell that was used to run QEMU
3459+
* one shell on the second shell running `telnet`
3460+
3461+
although we cannot change between terminals from there.
3462+
3463+
Each populated TTY contains a "shell":
3464+
3465+
* `-/bin/sh`: goes directly into an `sh` without a login prompt. Don't forget the dash `-`: https://askubuntu.com/questions/902998/how-to-check-which-tty-am-i-using
3466+
+
3467+
TODO: does not work for the `ttyS*` terminals. Why?
3468+
* `/sbin/getty` asks for password, and then gives you an `sh`
3469+
+
3470+
We can overcome the password prompt with the `-l /loginroot.sh` technique explained at: https://askubuntu.com/questions/902998/how-to-check-which-tty-am-i-using but I don't see any advantage over `-/bin/sh` currently.
3471+
3472+
Identify the current TTY with the command:
3473+
3474+
....
3475+
tty
3476+
....
3477+
3478+
* https://unix.stackexchange.com/questions/270272/how-to-get-the-tty-in-which-bash-is-running/270372
3479+
* https://unix.stackexchange.com/questions/187319/how-to-get-the-real-name-of-the-controlling-terminal
3480+
* https://unix.stackexchange.com/questions/77796/how-to-get-the-current-terminal-name
3481+
* https://askubuntu.com/questions/902998/how-to-check-which-tty-am-i-using
3482+
3483+
This outputs:
3484+
3485+
* `/dev/console` for the initial GUI terminal. But I think it is the same as `/dev/tty1`, because if I try to do
3486+
+
3487+
....
3488+
tty1::respawn:-/bin/sh
3489+
....
3490+
+
3491+
it makes the terminal go crazy, as if multiple processes are randomly eating up the characters.
3492+
* `/dev/ttyN` for the other graphic TTYs. Note that there are only 63 available ones, from `/dev/tty1` to `/dev/tty63` (`/dev/tty0` is the current one): link:https://superuser.com/questions/449781/why-is-there-so-many-linux-dev-tty[]. I think this is determined by:
3493+
+
3494+
....
3495+
#define MAX_NR_CONSOLES 63
34063496
....
3407-
console::respawn:/sbin/getty -n -L -l /loginroot.sh ttyS1 0 vt100
3497+
+
3498+
in `linux/include/uapi/linux/vt.h`.
3499+
* `/dev/ttySN` for the text shells.
3500+
+
3501+
These are Serial ports, see this to understand what those represent physically: https://unix.stackexchange.com/questions/307390/what-is-the-difference-between-ttys0-ttyusb0-and-ttyama0-in-linux/367882#367882
3502+
+
3503+
There are only 4 serial ports, I think this is determined by QEMU. TODO check.
3504+
+
3505+
See also: https://stackoverflow.com/questions/16706423/two-instances-of-busybox-on-separate-serial-lines-ttysn
3506+
3507+
Next try:
3508+
3509+
....
3510+
insmod /kthread.ko
34083511
....
34093512

3410-
but nothing changed.
3513+
and switch between virtual terminals, to understand that the dmesg goes to whatever current virtual terminal you are on, but not the others, and not to the serial terminals.
34113514

3412-
Note that on Ubuntu 17.10, to get to the text terminal from the GUI we first need `Ctrl-Alt-Fx`, and once in the text terminals, `Alt-Fn` works without `Ctrl`.
3515+
See also:
3516+
3517+
* https://serverfault.com/questions/119736/how-to-enable-multiple-virtual-consoles-on-linux
3518+
* https://github.com/mirror/busybox/blob/1_28_3/examples/inittab#L60
3519+
* http://web.archive.org/web/20180117124612/http://nairobi-embedded.org/qemu_serial_port_system_console.html
3520+
3521+
===== console kernel boot parameter
3522+
3523+
Take the command described at <<tty>> and try adding the following:
3524+
3525+
* `-e 'console=tty7'`: boot messages still show on `/dev/tty1` (TODO how to change that?), but we don't get a shell at the end of boot there.
3526+
+
3527+
Instead, the shell appears on `/dev/tty7`.
3528+
* `-e 'console=tty2'` like `/dev/tty7`, but `/dev/tty2` is broken, because we have two shells there:
3529+
** one due to the `::respawn:-/bin/sh` entry which uses whatever `console` points to
3530+
** another one due to the `tty2::respawn:/sbin/getty` entry we added
3531+
* `-e 'console=ttyS0'` much like `tty2`, but messages show only on serial, and the terminal is broken due to having multiple shells on it
3532+
* `-e 'console=tty1 console=ttyS0'`: boot messages show on both `tty1` and `ttyS0`, but only `S0` gets a shell because it came last
34133533

34143534
==== CONFIG_LOGO
34153535

@@ -5262,7 +5382,7 @@ Then copy and paste the diff additions to link:br2[] to make them permanent.
52625382

52635383
=== Change user
52645384

5265-
At startup, we login automatically as the `root` user as explained at: https://unix.stackexchange.com/questions/299408/how-to-login-automatically-without-typing-root-in-buildroot-x86-64-qemu/300152#300152
5385+
At startup, we login automatically as the `root` user.
52665386

52675387
If you want to switch to another user to test some permissions, we have already created an `user0` user through the link:user_table[] file, and you can just login as that user with:
52685388

0 commit comments

Comments
 (0)