Monthly Archives: June 2009

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.

Speeding up your website

A few days ago I stumbled upon the new Google “Let’s make the web faster”-page. I found some useful tips on there. Some of them are public knowledge, for example the fact that using echo in php is faster than print, single quotes are faster than double quotes and echo supports endless arguments, which is faster than string concatenating (so you write echo 'this', $is, 'faster than', $concatenating, 'the string' instead of echo 'this' . $is . 'slower').
However, there’s a nice article about ommitting html tags, which had some tips I did not know. For example, if you’re using HTML, instead of XHTML, you’re allowed to ommit more tags than most people know. For example, you don’t need to close a paragraph, you can just start a new one. For the complete list, have a look at the articles section of the site.

Boot Ubuntu livecds in KVM without VNC

This post is just for the sake of documenting this.

A while ago I came across a blog post written by an Ubuntu developer (I believe) which gave a nice tip on how to boot a livecd in KVM without VNC. Yesterday I needed this feature again, but was unable to find it.

I needed to boot a hardy-jeos livecd on my server, but didn’t want to go through the hassle of punching a hole in my firewall and installing a vnc client on my desktop computer. Luckily this is not needed, because you can get kvm to output it’s serial console to your console (in combination with GNU Screen this is very usefull) and the livecd support serial console also. To do all this you just need to append this to your kvm startup command:
-nographic -kernel /mnt/install/vmlinuz -append console=ttyS0,9600 -initrd /mnt/install/initrd.gz -cdrom /home/frank/hardy-jeos-i386.iso
Of course, the relevant files should be changed according to your system. Note that the kernel and initrd files are on the cd, so you should mount the cd on the host sytem also.

Any questions? Just leave them in the comments!