Skip to content

Instantly share code, notes, and snippets.

@przemoc
Last active February 6, 2018 13:54
Show Gist options
  • Save przemoc/1585152 to your computer and use it in GitHub Desktop.
Save przemoc/1585152 to your computer and use it in GitHub Desktop.
Set up log/debug Linux kernel session w/ QEMU in tmux
#!/bin/sh
# SPDX-License-Identifier: MIT
## Copyright (C) 2012 Przemyslaw Pawelczyk <[email protected]>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
LDIR="$HOME/qemu"
KDIR="$LDIR/$1"
if [ -z "$1" -o ! -d "$KDIR" ]; then
echo "Please specify existing kernel directory under $LDIR"
exit 1
fi
VD="$LDIR/squeeze64.img"
BI="$KDIR/arch/x86/boot/bzImage"
VL="$KDIR/vmlinux"
if ! [ -r "$VD" -a -r "$BI" -a -r "$VL" ]; then
echo -e "At least one of files:\n$VD\n$BI\n$VL\ncannot be read"
exit 1
fi
if tmux has-session -t vm 2>/dev/null; then
echo "vm session already running"
exit 1
fi
export PATH="$HOME/+/builds/gdb/gdb:$HOME/+/builds/qemu/x86_64-softmmu:$PATH"
LOGFILE="$LDIR/serial_$(date +%s).log"
(
echo $VL
uname -a
qemu --version
gdb --version | sed 1q
echo
) >> "$LOGFILE"
EMU_CMD="qemu-system-x86_64 -hda $VD -kernel $BI -append 'root=\"/dev/hda\" ro console=ttyS0 no-kvmclock' -net nic,model=e1000 -net user,hostfwd=tcp::10022-:22 -m 128 -nographic -no-hpet -rtc clock=vm -s -enable-kvm -serial file:$LOGFILE"
LOG_CMD="tail -f $LOGFILE"
GDB_CMD="cgdb $VL"
SSH_CMD="ssh qemu"
tmux start-server
tmux new-session -d -s vm
tmux set-option -g history-limit 10000
tmux new-window -n log -t vm:1 "$LOG_CMD"
tmux new-window -n gdb -t vm:2 "$GDB_CMD"
tmux new-window -n ssh -t vm:3
tmux new-window -n emu -t vm:4 "$EMU_CMD"
tmux select-window -t vm:log
tmux set-window-option -g monitor-activity on
tmux send-keys -t vm:ssh "$SSH_CMD"
exec tmux attach -t vm
@przemoc
Copy link
Author

przemoc commented Feb 6, 2018

commit c0da48b263b0767b496664f7fc2832e3bf4661af
Author: Przemyslaw Pawelczyk <[email protected]>
Date:   2018-02-06 14:53:28 +0100

    tmux-vm.sh: Add copyright notice and MIT license notice.

commit 312ddf6494f5c8edd8825c5dda2930476e3a9f25
Author: Przemyslaw Pawelczyk <[email protected]>
Date:   2018-02-06 14:53:44 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment