lost and found ( for me ? )

Showing posts with label virsh console. Show all posts
Showing posts with label virsh console. Show all posts

Ubuntu 13.10 KVM: build VMs without VNC by using virt-install

Here are logs when building VMs via virt-install without VNC.

# virt-install --version
0.600.4

error..
# virt-install --name ubuntu1204-varm -r 1024 --vcpus=2 --os-type=linux --os-variant=ubuntuprecise --disk path=/var/lib/KVM_images/ubuntu1204-varm.qcow2,size=10,format=qcow2 --cdrom  /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso --accelerate  --nographics --network network=default,model=virtio --hvm --extra-args='console=tty0 console=ttyS0,115200n8 serial'
ERROR    --extra-args は --location とともに指定する場合のみ機能します。

when using --extra-args option, I need to use --location instead of --cdrom option.

I need to specify nfs or http or ftp path when using --location.
nfs:host:/path or nfs://host/path
            An NFS server location containing an installable distribution image

        http://host/path
            An HTTP server location containing an installable distribution image

        ftp://host/path
            An FTP server location containing an installable distribution image

To specify http path, create a directory to mount ISO
# mkdir /var/www/mnt

mount the ISO
# mount -t iso9660 -o loop /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso /var/www/mnt
mount: block device /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso is write-protected, mounting read-only

# ls /var/www/mnt/
boot          dists  efi      isolinux    pics  preseed             ubuntu
cdromupgrade  doc    install  md5sum.txt  pool  README.diskdefines

start apache2
# apache2ctl start

Now, you can specify installable image over http.

try again.
Okay, I can install ubuntu via console without VNC.
virt-install --name ubuntu1204-varm -r 1024 --vcpus=2 --os-type=linux --os-variant=ubuntuprecise --disk path=/var/lib/KVM_images/ubuntu1204-varm.qcow2,size=10,format=qcow2 --location http://127.0.0.1/mnt --accelerate  --nographics --network network=default,model=virtio --hvm --extra-args='console=tty0 console=ttyS0,115200n8 serial'

Starting install...
Retrieving file version.info...                          |  116 B     00:00 ...
Retrieving file linux...                                 | 9.5 MB     00:00 ...
Retrieving file initrd.gz...                             |  33 MB     00:00 ...
Creating domain...                                       |    0 B     00:00     
Connected to domain ubuntu1204-varm
Escape character is ^]
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.0-29-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 (Ubuntu 3.2.0-29.46-generic 3.2.24)
[    0.000000] Command line: method=http://127.0.0.1/mnt console=tty0 console=ttyS0,115200n8
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
[    0.000000]  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
[    0.000000]  BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 000000003fffe000 (usable)
[    0.000000]  BIOS-e820: 000000003fffe000 - 0000000040000000 (reserved)
[    0.000000]  BIOS-e820: 00000000feffc000 - 00000000ff000000 (reserved)
[    0.000000]  BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved)
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI 2.4 present.
[    0.000000] No AGP bridge found





KVM virsh console error: operation failed: Active console session exists for this domain

When you can not connect to VMs over “virsh conlose” as below, restart libvirt-bin.
# virsh console 8
Connected to domain centos6-vm1-appportal
Escape character is ^]
error: operation failed: Active console session exists for this domain

After restarting libvirt-bin, you will be able to access to the VM.
# /etc/init.d/libvirt-bin restart
* Restarting libvirt management daemon /usr/sbin/libvirtd               [ OK ]

# virsh console 8
Connected to domain centos6-vm1
Escape character is ^]

Ubuntu13.04: install FreeBSD 9.2 64bit within KVM

Here are logs when building FreeBSD9.2 VM within KVM.
I am not familiar with FreeBSD, because I mainly use Linux.

I have built the VM by using virt-manager.
BSD 9.x are not in the OS list, so I specified BSD8.x as OS type.

KVM host
root@ubuntu-2:~# tail -1 /etc/lsb-release ;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 13.04"
3.8.0-34-generic x86_64
root@ubuntu-2:~# qemu-system-x86_64 --version
QEMU emulator version 1.4.0 (Debian 1.4.0+dfsg-1expubuntu4), Copyright (c) 2003-2008 Fabrice Bellard
root@ubuntu-2:~# libvirtd --version
libvirtd (libvirt) 1.0.2



vCPU*1
Memoery*1024
disk format: qcow2
OS type: BSD8.x
I used FreeBSD-9.2-RELEASE-amd64-dvd1.iso file to install FreeBSD.

installing BSD

booting.


get things done!


# uname -a
FreeBSD bsd01.localdomain 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

execute security update
# freebsd-update fetch
# freebsd-update install

how can I enable serial console to access to the VM via “virsh console”?

add the following line in /boot/defaults/loader.conf
# tail -1 /boot/defaults/loader.conf
console="comconsole"

edit /etc/ttys
edit ttyu0 line like this:
# egrep ttyu0 /etc/ttys
#ttyu0  "/usr/libexec/getty std.9600"   dialup  off secure
ttyu0   "/usr/libexec/getty std.9600"   vt100   on  secure

reboot the OS
# reboot

connect to the VM over virsh console
virsh # console freebsd92-vm1
FreeBSD/amd64 (bsd01.localdomain) (ttyu0)

login: root
Password:
Dec  5 05:33:11 bsd01 login: ROOT LOGIN (root) ON ttyu0

virtio drivers are loading.
# dmesg | grep virtio
virtio_pci0: <VirtIO PCI Balloon adapter> port 0xc060-0xc07f irq 11 at device 4.0 on pci0
vtballoon0: <VirtIO Balloon Adapter> on virtio_pci0
virtio_pci0: host features: 0x71000002 <EventIdx,RingIndirect,NotifyOnEmpty,StatsVq>
virtio_pci0: negotiated features: 0

create one more BSD VM with virt-clone.

at first, shutdown the VM
# shutdown –p now

clone the VM
# virt-clone -o freebsd92-vm1 -n freebsd02-vm2 --file /var/lib/KVM_images/freebsd92-vm2.qcow2
割り当て中 'freebsd92-vm2.qcow2'                    |  20 GB     01:13

'freebsd02-vm2'のクローニングに成功しました

boot the cloned VM
# virsh list --all | grep -i bsd
-     freebsd02-vm2                  shut off
-     freebsd92-vm1                  shut off

# virsh start freebsd02-vm2 –console

change hostname
# head -1 /etc/rc.conf
hostname="bsd02.localdomain"

# reboot

how to allow non root user to become root user with su command.
add users in the wheel group
# egrep wheel /etc/group
wheel:*:0:root,hattori

Fedora 19 VM: enable serial console for virsh console

small tips.

on the Fedora 19 VM ( not a KVM host )
add consle=ttyS0,115200 in /etc/sysconfig/grub file and then update grub.cfg
# cat /etc/sysconfig/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/swap rd.md=0 rd.dm=0 vconsole.keymap=us $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :) rd.luks=0 vconsole.font=latarcyrheb-sun16 rd.lvm.lv=fedora/root rhgb quiet console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"

# grub2-mkconfig > /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.11.1-200.fc19.x86_64
Found initrd image: /boot/initramfs-3.11.1-200.fc19.x86_64.img
Found linux image: /boot/vmlinuz-3.10.7-200.fc19.x86_64
Found initrd image: /boot/initramfs-3.10.7-200.fc19.x86_64.img
Found linux image: /boot/vmlinuz-3.9.5-301.fc19.x86_64
Found initrd image: /boot/initramfs-3.9.5-301.fc19.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-f3c8f32e33ea5b487a97554afaf10441
Found initrd image: /boot/initramfs-0-rescue-f3c8f32e33ea5b487a97554afaf10441.img
done

on the Feroa19 VM, add “ttyS0” in /etc/securetty file.
# echo ttyS0 >> /etc/securetty

reboot the VM. You will connect to the Fedora 19 VM over virsh console.
on the VM
# reboot

on the KVM host, connect to the VM over virsh console.
[root@localhost ~]# virsh console f19-vm1
ドメイン f19-vm1 に接続しました
エスケープ文字は ^] です
[    0.022000] Failed to access perfctr msr (MSR c0010001 is ffffffffffffffff)
[  OK  ] Started Show Plymouth Boot Screen.
[  OK  ] Reached target Paths.
[  OK  ] Reached target Basic System.
<snip>

Please confirm the VM has a serial port.
[root@localhost ~]# virsh dumpxml f19-vm1 | grep serial
   <controller type='virtio-serial' index='0'>
     <alias name='virtio-serial0'/>
   <serial type='pty'>
     <alias name='serial0'/>
   </serial>
     <target type='serial' port='0'/>
     <alias name='serial0'/>
     <address type='virtio-serial' controller='0' bus='0' port='1'/>

KVM : allow access to FreeBSD 9.0 VMs via “virsh console”

small tips

add console="comconsole" in /boot/loader.conf
# cat /boot/loader.conf
# for virtio drivers
virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"
virtio_balloon_load="YES"

# for virsh console
console="comconsole"

edit ttys

from
ttyu0  "/usr/libexec/getty std.9600"   dialup  off secure

to
ttyu0   "/usr/libexec/getty std.9600"   vt100   on secure

reboot the VM
# reboot

on the KVM host , access to the VM via “virsh console”
virsh # console bsd90-64-vm1
Connected to domain bsd90-64-vm1
Escape character is ^]


FreeBSD/amd64 (bsd90) (ttyu0)

login: