From ef5e2be2a4bb23b2f07bbd2a925f7fc7cea3979f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 31 Jul 2013 09:19:36 +0200 Subject: [PATCH] add ability to run without graphic card ('vga: serial[n]') --- PVE/API2/Qemu.pm | 28 +++++++++++++++++++++------- PVE/QemuServer.pm | 7 ++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 1111970..772b2cd 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1273,6 +1273,8 @@ __PACKAGE__->register_method({ my $vmid = $param->{vmid}; my $node = $param->{node}; + my $conf = PVE::QemuServer::load_config($vmid); # check if VM exists + my $authpath = "/vms/$vmid"; my $ticket = PVE::AccessControl::assemble_vnc_ticket($authuser, $authpath); @@ -1283,14 +1285,14 @@ __PACKAGE__->register_method({ my $port = PVE::Tools::next_vnc_port(); my $remip; + my $remcmd = []; if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) { $remip = PVE::Cluster::remote_node_ip($node); + # NOTE: kvm VNC traffic is already TLS encrypted + $remcmd = ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes', $remip]; } - # NOTE: kvm VNC traffic is already TLS encrypted - my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes', $remip] : []; - my $timeout = 10; my $realcmd = sub { @@ -1298,12 +1300,24 @@ __PACKAGE__->register_method({ syslog('info', "starting vnc proxy $upid\n"); - my $qmcmd = [@$remcmd, "/usr/sbin/qm", 'vncproxy', $vmid]; + my $cmd; - my $qmstr = join(' ', @$qmcmd); + if ($conf->{vga} =~ m/^serial\d+$/) { + + my $termcmd = [ '/usr/sbin/qm', 'terminal', $vmid, '-iface', $conf->{vga} ]; + #my $termcmd = "/usr/bin/qm terminal -iface $conf->{vga}"; + $cmd = ['/usr/bin/vncterm', '-rfbport', $port, + '-timeout', $timeout, '-authpath', $authpath, + '-perm', 'Sys.Console', '-c', @$remcmd, @$termcmd]; + } else { - # also redirect stderr (else we get RFB protocol errors) - my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null"]; + my $qmcmd = [@$remcmd, "/usr/sbin/qm", 'vncproxy', $vmid]; + + my $qmstr = join(' ', @$qmcmd); + + # also redirect stderr (else we get RFB protocol errors) + $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null"]; + } PVE::Tools::run_command($cmd); diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 2baa67e..6387b28 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -335,8 +335,8 @@ EODESC vga => { optional => 1, type => 'string', - description => "Select VGA type. If you want to use high resolution modes (>= 1280x1024x16) then you should use option 'std' or 'vmware'. Default is 'std' for win8/win7/w2k8, and 'cirrur' for other OS types. Option 'qxl' enables the SPICE display sever.", - enum => [qw(std cirrus vmware qxl)], + description => "Select VGA type. If you want to use high resolution modes (>= 1280x1024x16) then you should use option 'std' or 'vmware'. Default is 'std' for win8/win7/w2k8, and 'cirrur' for other OS types. Option 'qxl' enables the SPICE display sever. You can also run without any graphic card using a serial devive as terminal.", + enum => [qw(std cirrus vmware qxl serial0 serial1 serial2 serial3)], }, watchdog => { optional => 1, @@ -2306,6 +2306,7 @@ sub config_to_command { } else { $tablet = $defaults->{tablet}; $tablet = 0 if vga_conf_has_spice($vga); # disable for spice because it is not needed + $tablet = 0 if $vga =~ m/^serial\d+$/; # disable if we use serial terminal (no vga card) } push @$devices, '-device', 'usb-tablet,id=tablet,bus=uhci.0,port=1' if $tablet; @@ -2385,7 +2386,7 @@ sub config_to_command { push @$cmd, '-no-reboot' if defined($conf->{reboot}) && $conf->{reboot} == 0; - push @$cmd, '-vga', $vga if $vga; # for kvm 77 and later + push @$cmd, '-vga', $vga if $vga && $vga !~ m/^serial\d+$/; # for kvm 77 and later # time drift fix my $tdf = defined($conf->{tdf}) ? $conf->{tdf} : $defaults->{tdf}; -- 2.39.2