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.
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
#
I think you should be able to modify the content of the /boot/grub2/grub.cfg file. But if you make a mistake, the vm may not be able to boot.
You may also need to set GRUB_TERMINAL=”console serial” in order to be able to see/control grub from the serial line too.
Thanks.
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.
I think you can work via console or GUI but you don’t have access to virt-manager.
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.
You can buy a small second-hand PC like a HP N54L that you will be able to reuse as a NAS later on for $250/250Euros. Alternatively, you can rent a host with virtualization capabilities from an hosting company the time you practice your exam objectives. Finally, there are perhaps companies providing this kind of services for little money but I’m simply not aware of it.
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.
thank you cerdepot! appreciate your concern for us!!!!
Hi CertDepot, is there a way to recover the lost root password if I were in serial console?
Yes, one of the standard procedures should work in this case.
Thank you CertDepot!
Hi not getting anything from kpartx, do you have an advice?
# kpartx -av /var/lib/libvirt/images/centos7.0.qcow2
#
There is definitively a problem with your VM image.
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
You have to be prepared to answer all the questions through the command line.
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.
I don’t think credentials or IP could explain a slow connection.
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.
If there is something true here is I personally test every procedure that I display on my website. And if this procedure comes from somebody else, I write the source of it. After, how can you say that a procedure doesn’t work in any situation? There are 3 different versions (RHEL 7.0, RHEL 7.1, RHEL 7.2), did you test all of them to say that? Are you a KVM expert?
If you’ve got useful information, offer your knowledge in a positive manner in a comment.
Gjorgi, if you don’t trust all of the information here then don’t visit this site. Simple as that. peace
is all stuff mentioned here needed for the RHCSA exam ?
It is difficult to say if all the tutorials around the RHCSA curriculum (http://www.certdepot.net/rhel7-rhcsa-exam-objectives/) are needed, but you are supposed to know them.
HI Certdepot,
Is this Emergency procedure related to exam objectives..???
Thanks
No, this procedure isn’t part of any exam objectives. It’s just something useful to know.
The main procedure that you have to know is the one concerning the change of password at boot time.
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!
Thanks.
I find that the setting needs to be: “console=ttyS0,115200 edd=off” without ‘edd’ the booting hang at “Probing EDD (edd=off to disable)… ok”; without “115200” the virtual console hangs when trying to open.
Please advise
I didn’t come across this problem but it could depend on the minor RHEL version and the level of patches.
Have you tried virt-rescue command? Might be easier than the kpartx command.
I haven’t used it until now but I will. Thanks.
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!
Don’t worry about the virtual console setup, during the exam you will have access to the console.
Concerning virt-manager (I’m not used to virt-viewer), I don’t remember having any problem to access the console even in multi-user target.
Exiting from virsh console is effectively a great pain! Have a look at this SuperUser question. It worked for me, I hope it works for you!
HI!
Here you should provide vm name
# virsh dumpxml “VM_name”| grep “source file=”
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
I have never used Mac OSX, so I’m definitively not an expert in this domain.
However, I think it is a hardware configuration problem.
I think so too, won’t spend too much time on this.
Thanks.
Try adding “noapic” to the kernel line and see if it boots up.
where should I add this?
Are you trying to run virtualisation inside VirtualBox? VirtualBox does not support VT in VT.
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.
So I’m running virtualbox on my Mac then virt-manager from the centOS (virtualbox). SO yes 2 virtualization.
Been there, done that. VirtualBox does not have the ability to passthrough the VT-x features to a guest.
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 your software BACKUP(s) and check the BACKUPS
If you can afford it look at getting 2 or 3 raspberry pie,(case, microSD(fast) pi3, and micro usb). Centos now support ARM as of ver 7.1. NOT 7.0. I would not recomend this method yet.
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.
Thanks all, I just wanted to discuss some bit about these VM skills. I’m also learning with Linux Academy Lab.
Thanks.
so what does the exam actually look like ? based on sander van vugt’s videos, and the comments around the website, i was under the impression it would be like:
a desktop, with a GNOME desktop installed, with a virtual machine pre-installed, and the virtual machine may or may not include GNOME.
is this correct, or wrong ?
Don’t assume that you will have a GNOME desktop installed. You should rather think you’ve got only the command line interface.
Will I have to use this crazy line to remember?
grubby --update-kernel=ALL --args="console=ttyS0"
No, I don’t think so.
Yes, not sure
rd.break
is possible throughvirsh console
I wonder how VPS providers allow root password resets ?
Also when testing just now, it seems the console can default to a weirdly tiny resolution when the VM is accessed through
virsh console
even when used through the host’s TTY. Someone mentioned resolution problems in a comment about doing the exam through a kiosk:http://www.pmsas.pr.gov.br/wp-content/?id=certdepot-EX200&exam=rhel7-rhcsa-exam-objectives/#comment-42550
And seems the way to change the console resolution is very involved:
https://askubuntu.com/questions/18444/how-do-i-increase-console-mode-resolution
I use a couple of different VPS providers, they tend to give you access to a web-based control panel, where you can reset a root password.
Oh yes I’ve seen that too. But I meant: how are they able to offer that, behind the scenes ?
Well, a hypervisor has access to all VMs/containers hosted on it.
I cannot speak for all of virtualisation products available out there, but OpenVZ makes it super easy to reset the root account password for a container:
# vzctl set [VMID] –userpasswd [USER]:[PASSWORD]
Yeah sorry read the note below the
grubby
line later – seems I’ll only have to remember theconsole=ttyS0
part as I know about GRUB2 alreadyDoes it mean that host machine at the exam has GUI installed and we can access VM’s console via KVM’s virt-manager? Thanks in advance.
There is a kind of GUI but not compatible with KVM tools.
.qcow2
mount equivalent:http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html
Ok, this answer confuses me a lot. I think console=ttyS0 configuration is beyond scope of exam.
1. As far as I know Server with GUI is provided on RHCSA right? So virt-manager should be available.
2. If you are given CLI only access to your test system, it has VM1 installed on it and you can’t ssh to it, how are you supposed to ” add ‘console=ttyS0‘ ” to its grub.cfg?
If you can SSH to VM1, then you are already on the console, so why bother configuring serial port?
You can’t expect to get a GUI during the exam.
For the rest, in order to access the console during the exam, the only way I see is to reboot the VM.