Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtme-ng: redirect kernel log to stderr in interactive mode #66

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions virtme/architectures.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def earlyconsole_args():

@staticmethod
def serial_console_args():
return ["console=ttyS0"]
return ["virtme_console=ttyS0"]

@staticmethod
def config_base():
Expand Down Expand Up @@ -225,7 +225,7 @@ def earlyconsole_args():

@staticmethod
def serial_console_args():
return ["console=ttyAMA0"]
return ["virtme_console=ttyAMA0"]

def kimg_path(self):
return "arch/arm/boot/zImage"
Expand Down Expand Up @@ -274,7 +274,7 @@ def earlyconsole_args():

@staticmethod
def serial_console_args():
return ["console=ttyAMA0"]
return ["virtme_console=ttyAMA0"]

def kimg_path(self):
return "arch/arm64/boot/Image"
Expand Down Expand Up @@ -334,7 +334,7 @@ def qemuargs(is_native, use_kvm):

@staticmethod
def serial_console_args():
return ["console=ttyS0"]
return ["virtme_console=ttyS0"]

def kimg_path(self):
return "arch/riscv/boot/Image"
Expand Down
31 changes: 23 additions & 8 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,23 +986,38 @@ def do_it() -> int:
qemuargs.extend(["-net", "none"])

if args.graphics is None and not args.script_sh and not args.script_exec:
# It would be nice to use virtconsole, but it's terminally broken
# in current kernels. Nonetheless, I'm configuring the console
# manually to make it easier to tweak in the future.
qemuargs.extend(["-echr", "1"])
qemuargs.extend(["-serial", "none"])
qemuargs.extend(["-chardev", "stdio,id=console,signal=off,mux=on"])

qemuargs.extend(arch.qemu_serial_console_args())
if args.verbose:
# Check if we have permission to access the current stderr.
if not can_access_file("/proc/self/fd/2"):
print(
"ERROR: not a valid pts, try to run vng inside tmux or screen",
file=sys.stderr,
)
sys.exit(1)

qemuargs.extend(["-mon", "chardev=console"])
# Redirect kernel messages to stderr, creating a separate console
qemuargs.extend(["-chardev", "file,path=/proc/self/fd/2,id=dmesg"])
qemuargs.extend(["-device", arch.virtio_dev_type("serial")])
qemuargs.extend(["-device", "virtconsole,chardev=dmesg"])
kernelargs.extend(["console=hvc0"])

if args.verbose:
# Unfortunately we can't use hvc0 to redirect early console
# messages to stderr, so just send them to the main console, in
# this way we don't lose early printk's in verbose mode and we can
# catch potential boot issues.
kernelargs.extend(arch.earlyconsole_args())
qemuargs.extend(arch.qemu_nodisplay_args())

qemuargs.extend(["-chardev", "stdio,id=console,signal=off,mux=on"])
qemuargs.extend(["-serial", "chardev:console"])
qemuargs.extend(["-mon", "chardev=console"])

kernelargs.extend(arch.serial_console_args())

qemuargs.extend(arch.qemu_nodisplay_args())

# PS/2 probing is slow; give the kernel a hint to speed it up.
kernelargs.extend(["psmouse.proto=exps"])

Expand Down
10 changes: 9 additions & 1 deletion virtme/guest/virtme-init
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ if [[ -n "${user_cmd}" ]]; then
fi

# Figure out what the main console is
consdev="`grep ' ... (.C' /proc/consoles |cut -d' ' -f1`"
if [[ -n "${virtme_console}" ]]; then
consdev=${virtme_console}
else
consdev="`grep ' ... (.C' /proc/consoles |cut -d' ' -f1`"
fi
if [[ -z "$consdev" ]]; then
log "can't deduce console device"
exec bash --login # At least try to be helpful
Expand All @@ -335,6 +339,10 @@ if [[ ! -e "/dev/$consdev" ]]; then
exec bash --login
fi

# Redirect current stdout/stderr to consdev
exec 1>/dev/${consdev}
exec 2>&1

# Parameters that start with virtme_ shouldn't pollute the environment
for p in "${!virtme_@}"; do export -n "$p"; done

Expand Down
2 changes: 1 addition & 1 deletion virtme_ng_init
Submodule virtme_ng_init updated 1 files
+40 −1 src/main.rs
Loading