Tag Archives: debugging

Using GNU screen as virtmanager for KVM

After my last post about KVM, somebody emailed me, asking how I use KVM’s serial console in combination with screen. It’s a rather simple, but really usefull solution if you think tools like virtmanager are too much for you and you don’t like to use VNC. So this post will try to explain it to you.
For starters, you have to add the -nographic option to you KVM parameters. Next, make sure your virtual machine outputs it’s console to serial device 0. For example, start the Linux kernel with console=ttyS0 and make sure there is a getty process running on that same device. Now, whenever you start KVM in a GNU screen (with that -nographic parameter) you will see the dmesg scroll by and will end up with a login prompt. You can just keep this KVM running while detaching the GNU screen session (ctrl+a d) and you can re-attach by starting screen -x.
I use this on my server to start my two virtual machines. I made a screenrc like this:
# display a nice status bar on the bottom of the screen
hardstatus alwayslastline "%-Lw%50>%n%f* %t%{-}%+Lw%< %=[%c]"
vbell off
deflogin off
# use virtio for disks also!
screen -t production kvm -m 2048m -nographic -drive file=production.raw,if=virtio,boot=on -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no -smp 2
screen -t development kvm -m 1024m -nographic -drive file=development.raw,if=virtio,boot=on -net nic,model=virtio -net tap,ifname=tap1,script=no,downscript=no

Whenever the server boots it runs the following command in my rc.local:

# start KVM
cd /srv/
su frank - -c 'screen -c screenrc -dm'

So the server starts the GNU screen and the GNU screen start my virtual machines. If I can’t login via ssh in one of my virtual machines, I just connect to the host and attach to the screen to debug the problem.

Like this post? Tip me with bitcoin!

128na9ysGNmrJkEJcsLkARfUoRuJtBvBbJ

If you enjoyed reading this post, please consider tipping me using bitcoin. For an introduction to bitcoin please see weusecoins.com.

Magic c-style comments

A friend/collegea of mine had a really cool idea about c-style comments. C-style comments are multi-line comments that start with /* and end with */. They can be used in C, C++, C#, PHP, Java and a other languages. When this friend debugged some code, he found himself switching some blocks of code on and off all the time. He came up with a solution to switch between two blocks of code by just removing or adding one character!
See for yourself at: http://blog.mycroes.nl/2009/04/magic-comments.html

Like this post? Tip me with bitcoin!

1DrkG66j1YKUkUMAoZrnQnEBgXhxkgUTVX

If you enjoyed reading this post, please consider tipping me using bitcoin. For an introduction to bitcoin please see weusecoins.com.