我使用以下命令创build了KVM虚拟机:
sudo ubuntu-vm-builder kvm oneiric \ --domain xpstage \ --dest xpstage \ --arch i386 \ --hostname xpstage \ --mem 1024 \ --user myuser --pass mypassword \ --bridge virbr0 \ --ip 192.168.1.50 --dns 8.8.8.8 \ --components main,universe,restricted \ --addpkg acpid --addpkg vim --addpkg openssh-server --addpkg avahi-daemon \ --libvirt qemu:///system ;
我能够启动虚拟机,但无法使用networking(ssh)和控制台连接到它。
为了启用控制台访问,我在VM定义文件中添加了一个控制台部分:
<domain type='kvm' id='10'> <name>xpstage</name> <uuid>1fbe45ca-655f-9de2-b552-6ed44b2fe4c2</uuid> <memory>1048576</memory> <currentMemory>1048576</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='pc-0.14'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/home/darugar/VMs/xpstage/tmpB1Hu5k.qcow2'/> <target dev='hda' bus='ide'/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' unit='0'/> </disk> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='52:54:00:d1:6d:b8'/> <source bridge='virbr0'/> <target dev='vnet0'/> <model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> <source path='/dev/pts/3'/> <target port='0'/> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/3'> <source path='/dev/pts/3'/> <target type='serial' port='0'/> <alias name='serial0'/> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'/> <video> <model type='cirrus' vram='9216' heads='1'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </memballoon> </devices> <seclabel type='dynamic' model='apparmor'> <label>libvirt-1fbe45ca-655f-9de2-b552-6ed44b2fe4c2</label> <imagelabel>libvirt-1fbe45ca-655f-9de2-b552-6ed44b2fe4c2</imagelabel> </seclabel> </domain>
但是,当我尝试通过控制台连接时,什么也没有显示:
$ virsh console xpstage Connected to domain xpstage Escape character is ^] $ virsh ttyconsole xpstage /dev/pts/3
“virsh控制台”命令似乎连接,但除了“转义字符是^”之外没有任何显示。
请注意,我不是在寻找VNC或graphics访问; 我想要简单的控制台访问。
如何使这项工作的想法,将不胜感激。
您必须先启用客机中的串行控制台才能连接。 正确的方法在这里描述: https : //help.ubuntu.com/community/SerialConsoleHowto
最近的Ubuntu版本使用Upstart任务和服务,因此您应该将一个Upstart任务添加为/etc/init/ttyS0.conf ,其中包含以下内容:
# ttyS0 - getty # # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc or RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 115200 ttyS0 vt102
以这种方式开始:
$ sudo start ttyS0
之后,您应该能够从主机连接到串行控制台。 连接后不要忘记按Enter键。
我相信你仍然需要从你的主机发送一些东西到控制台。
所以要么有console=ttyS0,38400n8等内核参数
T0:2345:respawn:/sbin/getty -L ttyS0 38400 vt100
在/etc/inittab 。
或者,也许只是删除VGA将使Ubuntu默认使用ttyS0(但我疯狂猜测在这里)。
描述了两个问题,ssh访问和virsh控制台访问。 显然,控制台是一个起点,所以你可以debuggingSSH和networking。 以下是如何让virsh console工作。
closures客户端并将它的根驱动器安装在环路设备上
$ sudo kpartx -a guest.img $ sudo kpartx -av guest.img add map loop0p1 (253:1): 0 41940992 linear /dev/loop0 2048 $ sudo mount -t ext4 /dev/loop0p1 /mnt
创build这个文件 – 谷歌“ttyS0(你的客户操作系统版本)”的例子。
/etc/init/ttyS0.conf: (this is the path for ubuntu 14.04) # ttyS0 - getty # # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -L 115200 ttyS0 xterm
编辑/mnt/etc/securetty并将ttyS0添加到列表中。
卸载/mnt , kpartx -d guest.img ,然后启动您的guest虚拟机。
现在virsh console guest应该工作和login将成功(没有编辑securetty,login总是失败。)
注意 CentOS / RHEL有一个文件/etc/init/serial.conf描述了如何做到这一点。
附录我有一个没有控制台的客户系统:如果我运行virsh console guest我得到了“连接…”消息,但是没有其他东西打印到屏幕上。 这个有SSH运行。 在shelling和创buildttyS0.conf文件之后,我运行了sudo start ttyS0 ,并且控制台开始工作。