Last active
February 6, 2018 13:54
-
-
Save przemoc/1585152 to your computer and use it in GitHub Desktop.
Set up log/debug Linux kernel session w/ QEMU in tmux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
przemoc
commented
Feb 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment