In qemu
/kvm
, you only get a GUI if you attach a video card to your VM and if you don't expose it as SPICE/VNC.
For instance, you can do (zsh
syntax, with grub2
):
grub-mkimage -O i386-pc -c =(print -l serial 'terminal_input serial' \
'terminal_output serial'
) -o grub.img configfile biosdisk part_msdos part_gpt ext2 \
linux test serial halt minicmd cat
And start your VM with:
kvm -kernel grub.img -hda yourdisk.img -nographic
From the grub
prompt, load the kernel from the disk passing console=ttyS0
... option or equivalent on the system you're booting to have the console on serial. Remember to add a getty on the serial line as well.
Assuming you're running Linux in the VM, you can then update its grub config to display on serial and boot a kernel with serial console, and then you can boot your image disk directly without that grub.img.
To access the qemu "monitor", type Ctrl-Ac (where you can add/remove devices...).
You can have the serial
port as a unix domain or TCP socket, instead of stdio
if you like as well. Same for the qemu "monitor" interface.
Now, provided you have the sgabios.bin
firmware, and that your VM doesn't use graphics (just VGA BIOS text output), you can also just use the -curses
option:
kvm -hda yourdisk -curses
The VGA console is then shown in your terminal. If you need to access the qemu monitor, press Alt-2.
Bash needs to put the terminal into character-at-a-time mode while it's waiting for you to type in a command line, so that you can edit the command line using emacs or vi-like editing characters. That's the mode you saw when you looked at the terminal's attributes from another terminal in your example.
Just before it runs a program (in your example, stty
), bash puts the terminal back into canonical mode, where you have just a few special editing characters available courtesy of the operating system, such as backspace and Control-W, and basically the program gets input only after you type Enter.
When bash regains control, say after the program finishes or is suspended, it will put the terminal into character-at-a-time mode again.
Best Answer
The user response is stored in the exit code, so can be printed as usual:
echo $?
(note that0
means "yes", and1
is "no" in the shell world).Concerning other questions from the comment section:
to put into the dialog box the output from some command just use command substitution mechanism
$()
, eg:to give user multiple choices you can use
--menu
option instead of--yesno
to store the output of the user choice into variable one needs to use
--stdout
option or change output descriptor either via--output-fd
or manually, e.g.:This trick is needed because
dialog
by default outputs to stderr, not stdout.And as always,
man dialog
is your friend.