kvm-linux is sometimes hung up ssh is dead

sudo kvm -hda ubuntu.img -m 512 -localtime -net nic,model=pcnet,macaddr=00:00:00:00:00:0X -net tap,script=/etc/qemu-ifup -daemonize -nographic 

How to login to console besides ssh,vnc in kvm-linux.

I execute following commands in such a case

# kill -9 [kvm process]


A virtual machines console can be accessed through the use of a serial port. The -serial option of kvm redirects up to 4 virtual serial ports to the hosts physical serial port. You can then access the VM's console through the host's serial port. If a virtual machine somehow loses its network connection or you cannot connect to the ssh daemon you can connect to the VM through the serial port to correct the problem.

  • Thank you very much!. I tried it! but sudo kvm -hda ubuntu.img -m 512 -localtime -net nic,model=pcnet,macaddr=00:00:00:00:00:0X -net tap,script=/etc/qemu-ifup -serial -daemonize -nographic qemu: could not open serial device '-daemonize' ...!? – freddiefujiwra Jul 8 '09 at 1:49
  • you have to specify the console - -console pty for example will direct the VM's console to /dev/pty. from there you can just screen into it, or use minicom – dyasny Apr 2 '12 at 13:58
  • There's an even better solution - start using libvirt, and all you'll need to do is run virsh console $vm to get the VM's serial console – dyasny Apr 2 '12 at 13:59

My answer does not directly apply to KVM. My solution would simply to restart the SSH server so it becomes available again. By "ssh is dead" I'll assume you mean the sshd process is dead or at least port 22 is not responding. For these situation I often use Monit to restore service:

So for SSH I would go with something like this:

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

You have of course plenty of option with monit. See the monit documentation for details


I think the following post answers your question.

Debian Squeeze guest running under KVM, how to get serial?

Basically, you need to enable serial console on the guest kernel, then hook it up in the host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.