RHEL7: Access a virtual machine’s console.

Share this link

Note: This is an RHCSA 7 exam objective.

Standard procedure

With KVM, to access the virtual machine’s console under X Window, type:

# virt-manager

If you aren’t under X Window, there is another way to access a virtual machine’s console: you can go through a serial console.

On the virtual machine, add ‘console=ttyS0‘ at the end of the kernel lines in the /boot/grub2/grub.cfg file:

# grubby --update-kernel=ALL --args="console=ttyS0"

Note: Alternatively, you can edit the /etc/default/grub file, add ‘console=ttyS0‘ to the GRUB_CMDLINE_LINUX variable and execute ‘# grub2-mkconfig -o /boot/grub2/grub.cfg‘.

Now, reboot the virtual machine:

# reboot

With KVM, connect to the virtual machine’s console (here vm.example.com):

# virsh console vm.example.com
Connected to domain vm.example.com
Escape character is ^]

Red Hat Enterprise Linux Server 7.0 (Maipo)
Kernel 3.10.0-121.el7.x86_64 on an x86_64

vm login:

Emergency procedure

Sometimes you have lost all links to your virtual machine (error in the /etc/fstab file, ssh configuration, etc) and, as you didn’t set up any virtual console, you are in real trouble. There is still a solution!
Connect to the physical host and shut down your virtual machine (here called vm.example.com):

# virsh destroy vm.example.com

Define where the virtual machine image file is located (by default in the /var/lib/libvirt/images directory with a name like vm.example.com.img):

# virsh dumpxml | grep "source file="
      <source file='/var/lib/libvirt/images/vm.example.com.img'/>      

Map your virtual machine image file into the host environment (-a for add and -v for verbose):

# kpartx -av /var/lib/libvirt/images/vm.example.com.img
add map loop0p1 (253:2): 0 1024000 linear /dev/loop0 2048
add map loop0p2 (253:3): 0 10240000 linear /dev/loop0 1026048

From the previous display, you know that you’ve got two partitions (in fact /boot and /, distinguishable by their respective size).
You need to mount the /boot partition to be able to change the grub configuration:

# mount /dev/mapper/loop0p1 /mnt

Then, edit the /mnt/grub2/grub.cfg file and add ‘console=ttyS0‘ at the end of every line containing /vmlinuz (the linux kernel).
Unmount the partition:

# umount /mnt

Unmap the virtual machine image file (-d for delete and -v for verbose):

# kpartx -dv /var/lib/libvirt/images/vm.example.com.img
del devmap : loop0p2
del devmap : loop0p1
loop deleted : /dev/loop0

Restart your virtual machine:

# virsh start vm.example.com
Domain vm.example.com started

Connect to your virtual machine console:

# virsh console vm.example.com
Connected to domain vm.example.com
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-123.el7.x86_64 on an x86_64

vm login: 

This procedure works for RHEL 6/CentOS 6 and RHEL 7/CentOS 7.

Source: Deepal Jayasinghe’s blog.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

46 Comments on "RHEL7: Access a virtual machine’s console."

Notify of
Sort by:   newest | oldest
abcdef
Member
abcdef

Changing the values of /boot/grub2/grub.cfg doesn’t/ wouldn’t work. Any tips on getting (virsh console domain) command working?

[root@station52 ~]# cat /boot/grub2/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

fernandezcuesta
Member
fernandezcuesta

You may also need to set GRUB_TERMINAL=”console serial” in order to be able to see/control grub from the serial line too.

Oxygen
Member
Oxygen

Could you please advise if all of that needs to be done via console or GUI is allowed? Because if it is, all kickstarts and vms stuff is quite easy as you don’t need to do blind installations and wait just to see how it fails again and again.

ak340
Member
ak340

I CertDepot, I have currently a Centos VM via Virtualbox however I cannot use KVM as I don’t have any vmx/svm CPU flags. Do you know any alternatives where I can practice this objective?
What I mean is I have a Centos VM and cannot use KVM inside that VM.

tom
Member
tom

I am not sure about VirtualBox, but VMware Player supports nested KVM as hypervisor. At least it works for me very well. I have VMware Player running on Windows 8. CentOS7 as guest OS in Player and one more CentOS 7 as guest in host CentOS. You need to set CPU Virtualization Engine to Intel VT-x/EPT. I think VirtualBox also supports this mode.

ak340
Member
ak340

thank you cerdepot! appreciate your concern for us!!!!

ak340
Member
ak340

Hi CertDepot, is there a way to recover the lost root password if I were in serial console?

ak340
Member
ak340

Thank you CertDepot!

ak340
Member
ak340

Hi not getting anything from kpartx, do you have an advice?

# kpartx -av /var/lib/libvirt/images/centos7.0.qcow2
#

langtu1511
Member
langtu1511

Thank CertDepot,

This is a great blog.

I am wondering in the exam, can we use GUI for all questions? do I have to use command lines for all questions in the exam?

With these kind of question (in this blog post), I think it doesn’t matter if we have GUI virt-manager.

Thank

Gjorgi
Member
Gjorgi

While trying a console connection to a VM, it was very slow, so I don’t know if the following helps:
* you know username and password of a user on the VM. I’d assume you already have those credentials since you are the one that created the VM.
* you need to know the IP of that VM so you can ssh into it to fix stuff: arp -n and you’ll see the IP of the VM.
ssh into it with credentials you have and iron out what needs to be fixed.

Gjorgi
Member
Gjorgi

Also, if the VM’s image is in qcow2 format (which it is on CentOS 7 systems) this emergency procedure won’t work. Which is a strong hint that the author of the blog from which this procedure was taken simply copy/pasted someone else’s instructions without ever bothering to test.

redhat0329
Member
redhat0329

Gjorgi, if you don’t trust all of the information here then don’t visit this site. Simple as that. peace

aaqrabaw
Member
aaqrabaw

is all stuff mentioned here needed for the RHCSA exam ?

mehboob
Member
mehboob

HI Certdepot,

Is this Emergency procedure related to exam objectives..???

Thanks

misterX
Member
misterX

Maybe a workaround for the kpartx / qcow2 problem… It seems that kpartx can not always handle the qcow2 format correctly. Try to convert qcow2 to raw: #qemu-img convert file.qcow2 file.raw -> then edit the VM xml file. Lines “source file=/path/file.raw” and “driver name=qemu type=raw”. Thank you for your http://www.certdepot.net site it’s a huge help!

bashtheshell
Member
bashtheshell

Have you tried virt-rescue command? Might be easier than the kpartx command.

smrbukhari
Member
smrbukhari

Hello CertDepot,

Would there be a VM provided with virtual console setup? I just realized that virt-viewer and virt-manager would not work in multi-user target. If this is not the case how do you recommend we login into VM to make the changes in grub2 config as you mentioned above.

Also how do you exit from virsh console, I’m in non-GUI mode and none of the escape characters are working. Using “logout” or “exit” takes me back to the login prompt again.

Appreciate your help on this!

dudniksergei
Member
dudniksergei

HI!
Here you should provide vm name

# virsh dumpxml “VM_name”| grep “source file=”

ylemouel
Member
ylemouel

Hello,

I’m having trouble to run a CentOS iso.
Here my setup:
VirtualBox (CentOS 7)running from Mac OSX.
Running Virtual Machine Manager from CentOS 7 (Virtualbox)
When I boot CentOS via virt-manager I’m getting MP-bios bug: 8254 timer not connected to IO-APIC

I disabled I/O APIC from Virtualbox settings.

What do you think looks like a hardware incompatibility, assuming running 2 VM could be an issue.

Thanks for your help

Lisenet
Member

Try adding “noapic” to the kernel line and see if it boots up.

ylemouel
Member
ylemouel

where should I add this?

Lisenet
Member

Are you trying to run virtualisation inside VirtualBox? VirtualBox does not support VT in VT.

Sam
Member
Sam

Er, no that is not a good idea, or can’t be done with any in a good manor.

What do I mean, running a virt-manager inside virtualbox, causes issues. I would be surprised if it ran at all with most os’s. This is a hardware limitation issue. That’s my guess.

ylemouel
Member
ylemouel

So I’m running virtualbox on my Mac then virt-manager from the centOS (virtualbox). SO yes 2 virtualization.

Lisenet
Member

Been there, done that. VirtualBox does not have the ability to passthrough the VT-x features to a guest.

Sam
Member
Sam
I am pretty sure this will not work, unless you do something very odd. The way I see it you have 2 options assuming using a mac, and ither way you will need to work on this from other sources. I have no experteese on this and it depends on hardware limits(ram and num CPUs) * use virtualbox, using the inbuilt vlan between the various VM * Create a Dual boot enviorment. you will have to research this. this is more efficent, a few years ago mac had a simple method of doing this. WARRNING using this method may damage… Read more »
Lisenet
Member

OK, just to clarify this one more time, you cannot use VirtualBox to deploy KVM on top of it. However, you can use VirtualBox to set up you home lab and practice at least 95% of the exam tasks.

ylemouel
Member
ylemouel

Thanks all, I just wanted to discuss some bit about these VM skills. I’m also learning with Linux Academy Lab.
Thanks.

wpDiscuz

RHCSA7: Task of the day

Allowed time: 10 minutes.
Create an EXT4 file system mounted by UUID in /etc/fstab under /vol based on a logical volume of 28 logical extents.

RHCE7: Task of the day

Allowed time: 8 minutes.
Set up an iScsi target based on a block backstore of 100MB called lv_iscsi with basic authentication, ext4 filesystem and standard firewall configuration.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...